Skip to content

Latest commit

 

History

History
3867 lines (2685 loc) · 91.5 KB

File metadata and controls

3867 lines (2685 loc) · 91.5 KB

ElectroBlocks Examples

This repo lists ElectroBlocks Component Examples in Python and C. Note that most demo videos are played at double speed to reduce video size.

General Demo

https://youtu.be/yCtfm9R8Y0o

Setup

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Digital Display

Project File

Project File

Example Video

digitial_display.mp4
#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_digital_display(11, 10)

while True:
  eb.set_digital_display(True, "Toot")
  time.sleep(1) # Wait for the given/defined seconds.
  eb.set_digital_display(False, "Loon")
  time.sleep(1) # Wait for the given/defined seconds.
#include <TM1637.h>  // Includes the library for the TM1637 7-segment display
const byte PIN_CLK = 10;   // Defines CLK pin for the display
const byte PIN_DIO = 11;   // Defines DIO pin for the display
// Initializes the 7-segment display with CLK and DIO pins
TM1637    tm(PIN_CLK, PIN_DIO);



// Initialise the program settings and configurations
void setup() {
  tm.begin();
  tm.setBrightness(100);
  tm.clearScreen();

}

// The void loop function runs over and over again forever.
void loop() {

  tm.clearScreen();
  tm.colonOn();
  tm.display(String("Toot"));
  delay(1000); // Wait for the given/defined milliseconds.

  tm.clearScreen();
  tm.colonOff();
  tm.display(String("Loon"));
  delay(1000); // Wait for the given/defined milliseconds.
}

NeoPixels / FastLED / LED Strip

Project File

Project File

fastled_c.mp4
struct RGB {
    double red;
    double green;
    double blue;
};

#include <FastLED.h>  // Includes the FastLED library for controlling LED strips
#define NUM_LEDS 30 // Defines the number of LEDs in the strip
#define DATA_PIN A0 // Creates an array to hold the LED colors
CRGB leds[NUM_LEDS]; // Creates an array to hold the LED colors



double i = 0;



// Initialise the program settings and configurations
void setup() {

   // Initializes the LED strip
   FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
   // Sets the brightness of the LEDs
   FastLED.setBrightness(10);

}

// The void loop function runs over and over again forever.
void loop() {
  // Set all Colors for led strip
  setFastLEDColor(1,{255, 8, 206});
  setFastLEDColor(2,{0, 0, 0});
  setFastLEDColor(3,{0, 0, 0});
  setFastLEDColor(4,{0, 0, 0});
  setFastLEDColor(5,{0, 0, 0});
  setFastLEDColor(6,{0, 0, 0});
  setFastLEDColor(7,{0, 0, 0});
  setFastLEDColor(8,{0, 0, 0});
  setFastLEDColor(9,{0, 0, 0});
  setFastLEDColor(10,{0, 0, 0});
  setFastLEDColor(11,{0, 0, 0});
  setFastLEDColor(12,{237, 0, 162});
  setFastLEDColor(13,{0, 0, 0});
  setFastLEDColor(14,{0, 0, 0});
  setFastLEDColor(15,{0, 0, 0});
  setFastLEDColor(16,{0, 0, 0});
  setFastLEDColor(17,{0, 0, 0});
  setFastLEDColor(18,{0, 0, 0});
  setFastLEDColor(19,{0, 0, 0});
  setFastLEDColor(20,{0, 0, 0});
  setFastLEDColor(21,{0, 0, 0});
  setFastLEDColor(22,{0, 0, 0});
  setFastLEDColor(23,{0, 0, 0});
  setFastLEDColor(24,{0, 0, 0});
  setFastLEDColor(25,{252, 42, 5});
  setFastLEDColor(26,{0, 0, 0});
  setFastLEDColor(27,{0, 0, 0});
  setFastLEDColor(28,{0, 0, 0});
  setFastLEDColor(29,{0, 0, 0});
  setFastLEDColor(30,{255, 51, 0});
  // End of setting all the colors for the led strip.

  FastLED.show(); // Sets the color the led strip.
  delay(2000); // Wait for the given/defined milliseconds.
  for (i = 1; i <= 30; i += 1) {
    setFastLEDColor(i,{ 255, 0, 255});

  }
  FastLED.show(); // Sets the color the led strip.
  delay(2000); // Wait for the given/defined milliseconds.
}


// Sets the color of a specific LED at the given position
void setFastLEDColor(int pos, struct RGB color) {
    pos = pos <= 0 ? 0 : pos; // Ensures the position is not negative
    pos = pos >= 1 ? pos - 1 : pos;  // Adjusts position to fit within the array bounds
    leds[pos].setRGB((int)color.red, (int)color.green, (int)color.blue); // Sets the LED color
}

Notice that it runs slower because of the loop where it has to send each command to set the individual colors from the laptop / computer running python.

python_neopixels.mp4
#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


from dataclasses import dataclass

@dataclass
class RGB:
  red: float
  green: float
  blue: float


# Variable Declaration
i = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_rgb_strip("A0", 30, "GRB", 10) # Configures the NEOPIXEL strip



while True:
  eb.rgb_strip_set_all_colors([
  	(255, 8, 206),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(237, 0, 162),
  	(0, 0, 0),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(0, 0, 0),
  	(252, 42, 5),(0, 0, 0),(0, 0, 0),
  	(0, 0, 0),(0, 0, 0),(255, 51, 0)
  ])
  eb.rgb_strip_show_all() # Sets the color the led strip.
  time.sleep(2) # Wait for the given/defined seconds.
  for i in range(1, 31, 1):
    developer_temp_color = RGB(255, 0, 255) # create a variable to store the color
    eb.rgb_strip_set_color(i, developer_temp_color.red, developer_temp_color.green, developer_temp_color.blue)
  eb.rgb_strip_show_all() # Sets the color the led strip.
  time.sleep(2) # Wait for the given/defined seconds.

LCD Screen

Project File

Project File

Example Video

lcd.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_lcd(4, 20, 63) # Configures the LCD Screen pins



while True:
  eb.lcd_clear() #clear screen
  eb.lcd_print(0, 0, "Hello") # Print the first row text on the LCD screen
  eb.lcd_print(1, 0, "  World") # Print the second row text on the LCD screen
  eb.lcd_print(2, 0, " Test") # Print the third row text on the LCD screen
  eb.lcd_print(3, 0, " .# moo #- ") # Print the fourth row text on the LCD screen
  time.sleep(3) # Wait for 3 seconds
  eb.lcd_clear() # clear screen
  time.sleep(0.2) # Wait for the given/defined seconds.
  eb.lcd_print(0, 0, "Hi") # Print a message on the LCD screen at specified row and column
  for i in range(1, 18 + 1):
    eb.lcd_scrollright()
    time.sleep(0.2) # Wait for the given/defined seconds.
  for i2 in range(1, 18 + 1):
    eb.lcd_scrollleft()
    time.sleep(0.2) # Wait for the given/defined seconds.
  eb.lcd_clear() # Clear the LCD screen
  eb.lcd_blink_curor(3, 9, True) # Turn on the blink.
  time.sleep(1) # Wait for the given/defined seconds.
  eb.lcd_blink_curor(3, 9, False) # Turn off the blink.
  time.sleep(1) # Wait for the given/defined seconds.
  eb.lcd_toggle_backlight(False) # Turn off the LCD backlight
  time.sleep(1) # Wait for the given/defined seconds.
  eb.lcd_toggle_backlight(True) # Turn on the LCD backlight
  time.sleep(1) # Wait for the given/defined seconds.

C Code

#include <Wire.h>;  // Include the Wire library for I2C communication.
#include <LiquidCrystal_I2C.h>;  // Include the LiquidCrystal_I2C library for controlling the LCD
LiquidCrystal_I2C lcd(0X3F,4,20); // Create an LCD object with I2C address 0X3F, 4 rows, and 20 columns
int simple_loop_variable = 0;



// Initialise the program settings and configurations
void setup() {
   lcd.init(); // Initialize the LCD
   lcd.backlight(); // Turn on the LCD backlight

}

// The void loop function runs over and over again forever.
void loop() {
  lcd.clear(); // Clear LCD Screen
  lcd.setCursor(0, 0); // Print a message on the LCD screen
  lcd.print(String("Hello")); // Prints a message on LCD Screen.
  lcd.setCursor(0, 1); // Print a message on the LCD screen
  lcd.print(String("  World")); // Prints a message on LCD Screen.
  lcd.setCursor(0, 2); // Print a message on the LCD screen
  lcd.print(String(" Test")); // Prints a message on LCD Screen.
  lcd.setCursor(0, 3); // Print a message on the LCD screen
  lcd.print(String(" .# moo #- ")); // Prints a message on LCD Screen.
  delay(3000); // Wait 3 seconds
  lcd.clear(); // Clear LCD Screen

  delay(200); // Wait for the given/defined milliseconds.
  lcd.setCursor(0, 0); // Set position to print on the LCD screen
  lcd.print(String("Hi")); // Print a message on the LCD screen
  for (simple_loop_variable = 1; simple_loop_variable <= 18; simple_loop_variable += 1) {
    lcd.scrollDisplayRight();
    delay(200); // Wait for the given/defined milliseconds.
  }
  for (simple_loop_variable = 1; simple_loop_variable <= 18; simple_loop_variable += 1) {
    lcd.scrollDisplayLeft();
    delay(200); // Wait for the given/defined milliseconds.
  }
  lcd.clear(); // Clear LCD Screen.
  lcd.setCursor(9, 3);
  lcd.blink();
  delay(1000); // Wait for the given/defined milliseconds.
  lcd.setCursor(9, 3);
  lcd.noBlink();
  delay(1000); // Wait for the given/defined milliseconds.
  lcd.noBacklight(); // Turn off backlight
  delay(1000); // Wait for the given/defined milliseconds.
  lcd.backlight(); // Turn on backlight
  delay(1000); // Wait for the given/defined milliseconds.
}

LED

Project File

Project File

Example Video

leds.mp4

Python

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.digital_write_config(8)
eb.analog_write_config(9)


while True:
  eb.digital_write(8, 1) # Turns the led on
  time.sleep(1) # Wait for the given/defined seconds.
  eb.digital_write(8, 0) # Turns the led off
  time.sleep(1) # Wait for the given/defined seconds.
  for i in range(0, 101, 5):
    eb.analog_write(9, i)
    time.sleep(0.1) # Wait for the given/defined seconds.
  for i in range(100, -1, -5):
    eb.analog_write(9, i)
    time.sleep(0.1) # Wait for the given/defined seconds.
  time.sleep(1) # Wait for the given/defined seconds.

C Code

double i = 0;



// Initialise the program settings and configurations
void setup() {
   pinMode(8, OUTPUT);  // Configures led pin as an output
   pinMode(9, OUTPUT); // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  digitalWrite(8, HIGH); // Set defined pin to HIGH (turn it on).
  delay(1000); // Wait for the given/defined milliseconds.
  digitalWrite(8, LOW); // Set defined pin to LOW (turn it off).
  delay(1000); // Wait for the given/defined milliseconds.
  for (i = 0; i <= 100; i += 5) {
    analogWrite(9, i);
    delay(100); // Wait for the given/defined milliseconds.

  }
  for (i = 100; i >= 0; i -= 5) {
    analogWrite(9, i);
    delay(100); // Wait for the given/defined milliseconds.

  }
  delay(1000); // Wait for the given/defined milliseconds.
}

LED Matrix

Project File

Project File

Example Video

led_matrix.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class


eb.config_led_matrix(10,11,12, True)

while True:
  for i in range(1, 3 + 1):

    eb.draw_led_matrix([
    	"b00000000",
    	"b01100110",
    	"b01100110",
    	"b00000000",
    	"b00011000",
    	"b00000000",
    	"b10001111",
    	"b00111100",
    ])

    time.sleep(0.2) # Wait for the given/defined seconds.

    eb.draw_led_matrix([
    	"b00000000",
    	"b01100000",
    	"b01100110",
    	"b00000000",
    	"b00011000",
    	"b00000000",
    	"b11110001",
    	"b00111100",
    ])

    time.sleep(0.2) # Wait for the given/defined seconds.

  eb.draw_led_matrix([
  	"b00000000",
  	"b00000000",
  	"b00000000",
  	"b00000000",
  	"b00000000",
  	"b00000000",
  	"b00000000",
  	"b00000000",
  ])

  for i in range(1, 9, 1):
    eb.set_led_matrix_led(i, i, True)
    time.sleep(0.1) # Wait for the given/defined seconds.
  for i in range(8, 0, -1):
    eb.set_led_matrix_led(i, i, False)
    time.sleep(0.1) # Wait for the given/defined seconds.
  time.sleep(1) # Wait for the given/defined seconds.

C Code

// This a wrapper library on LedControl that allows us to rotate for breadboards
#include "LedMatrix.h";

LedMatrix lm(10, 12, 11, LedMatrix::R0, true);
byte developer_ledmatrix_image[8] = {
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000
};
int simple_loop_variable = 0;

double i = 0;



// Initialise the program settings and configurations
void setup() {

}

// The void loop function runs over and over again forever.
void loop() {
  for (simple_loop_variable = 1; simple_loop_variable <= 3; simple_loop_variable += 1) {

    developer_ledmatrix_image[0] = B00000000;
    developer_ledmatrix_image[1] = B01100110;
    developer_ledmatrix_image[2] = B01100110;
    developer_ledmatrix_image[3] = B00000000;
    developer_ledmatrix_image[4] = B00011000;
    developer_ledmatrix_image[5] = B00000000;
    developer_ledmatrix_image[6] = B10001111;
    developer_ledmatrix_image[7] = B00111100;
    lm.setImage(developer_ledmatrix_image); // Turns on the leds

    delay(200); // Wait for the given/defined milliseconds.

    developer_ledmatrix_image[0] = B00000000;
    developer_ledmatrix_image[1] = B01100000;
    developer_ledmatrix_image[2] = B01100110;
    developer_ledmatrix_image[3] = B00000000;
    developer_ledmatrix_image[4] = B00011000;
    developer_ledmatrix_image[5] = B00000000;
    developer_ledmatrix_image[6] = B11110001;
    developer_ledmatrix_image[7] = B00111100;
    lm.setImage(developer_ledmatrix_image); // Turns on the leds

    delay(200); // Wait for the given/defined milliseconds.
  }

  developer_ledmatrix_image[0] = B00000000;
  developer_ledmatrix_image[1] = B00000000;
  developer_ledmatrix_image[2] = B00000000;
  developer_ledmatrix_image[3] = B00000000;
  developer_ledmatrix_image[4] = B00000000;
  developer_ledmatrix_image[5] = B00000000;
  developer_ledmatrix_image[6] = B00000000;
  developer_ledmatrix_image[7] = B00000000;
  lm.setImage(developer_ledmatrix_image); // Turns on the leds

  for (i = 1; i <= 8; i += 1) {

    lm.setPixel(i, i, true); // change one pixel in the buffer.
    lm.setImage(); // changes the pixels on the device

    delay(100); // Wait for the given/defined milliseconds.

  }
  for (i = 8; i >= 1; i -= 1) {

    lm.setPixel(i, i, false); // change one pixel in the buffer.
    lm.setImage(); // changes the pixels on the device

    delay(100); // Wait for the given/defined milliseconds.

  }
  delay(1000); // Wait for the given/defined milliseconds.
}

Motor

I had to use the 12 V pin on the L298 board to get the DC motors spinning when powered by a 9 V battery.

Project File

Project File

Example Video

motor.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_motor(9, 8, 7, 3, 5, 4)



while True:
  eb.move_motor(1, 150, "clockwise")
  time.sleep(3) # Wait for the given/defined seconds.
  eb.stop_motor(1)
  time.sleep(3) # Wait for the given/defined seconds.
  eb.move_motor(1, 150, "anti_clockwise")
  time.sleep(3) # Wait for the given/defined seconds.
  eb.stop_motor(1)
  time.sleep(3) # Wait for the given/defined seconds.
  eb.move_motor(2, 150, "clockwise")
  time.sleep(3) # Wait for the given/defined seconds.
  eb.stop_motor(2)
  time.sleep(3) # Wait for the given/defined seconds.
  eb.move_motor(2, 150, "anti_clockwise")
  time.sleep(3) # Wait for the given/defined seconds.
  eb.stop_motor(2)
  time.sleep(3) # Wait for the given/defined seconds.

C Code

// Define an enumeration for motor direction with three possible values
typedef enum {
  CLOCKWISE = 0, // Motor turns in the clockwise direction
  ANTI_CLOCKWISE = 1,  // Motor turns in the anti-clockwise direction
  STOP = -1 // Motor stops
} Direction;

// Pin assign for the motor control
const int motor1Pin1 = 8;  // Control pin for motor direction 1
const int motor1Pin2 = 7;  // Control pin for motor direction 2
const int enablePin1 = 9; // PWM pin to enable the motor1
const int motor2Pin1 = 5; // Control pin for motor2 direction 1
const int motor2Pin2 = 4; // Control pin for motor2 direction 2
const int enablePin2 = 3; // PWM pin to enable the motor2

// Function to move the motor based on specified speed and direction
void moveMotor(int motor, int speed, Direction direction) {
  int enablePin = motor == 1 ? enablePin1 : enablePin2; // Set the enable pin to enablePin1
  int pin1 = motor == 1 ? motor1Pin1 : motor2Pin1; // Set pin1 to control direction 1
  int pin2 = motor == 1 ? motor1Pin2 : motor2Pin2; // Set pin2 to control direction 2
  // Control the motor direction based on the specified direction
  if (speed > 255) {
    speed = 254;
  } else if (speed < 1) {
    speed = 1;
  }

  switch (direction) {
    case CLOCKWISE:
      digitalWrite(pin1, HIGH);  // Set pin1 high to turn clockwise
      digitalWrite(pin2, LOW); // Set pin2 low
      analogWrite(enablePin, speed);  // Set motor speed
      break;
    case ANTI_CLOCKWISE:
      digitalWrite(pin1, LOW); // Set pin1 low to turn anti-clockwise
      digitalWrite(pin2, HIGH); // Set pin2 high
      analogWrite(enablePin, speed); // Set motor speed
      break;
    case STOP:
      analogWrite(enablePin, 0);  // Stop the motor
      break;
  }
}




// Initialise the program settings and configurations
void setup() {

   // Configuring motor control pins
   pinMode(motor1Pin1, OUTPUT); // Set motor1Pin1 as output
   pinMode(motor1Pin2, OUTPUT); // Set motor1Pin2 as output
   pinMode(enablePin1, OUTPUT); // Set enablePin1 as output
   pinMode(motor2Pin1, OUTPUT); // Set motor2Pin1 as output
   pinMode(motor2Pin2, OUTPUT); // Set motor2Pin2 as output
   pinMode(enablePin2, OUTPUT); // Set enablePin2 as output
   // Motor pin setup complete

}

// The void loop function runs over and over again forever.
void loop() {
  moveMotor(1, 150, CLOCKWISE);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(1, 0, STOP);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(1, 150, ANTI_CLOCKWISE);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(1, 0, STOP);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(2, 150, CLOCKWISE);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(2, 0, STOP);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(2, 150, ANTI_CLOCKWISE);
  delay(3000); // Wait for the given/defined milliseconds.
  moveMotor(2, 0, STOP);
  delay(3000); // Wait for the given/defined milliseconds.
}

Passive Buzzer

Project File

Project File

Example Video

buzzer.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_passive_buzzer(9)


while True:
  eb.play_passive_buzzer(9, 131)
  time.sleep(0.2) # Wait for the given/defined seconds.
  for i in range(100, 401, 10):
    eb.play_passive_buzzer(9, i)
    time.sleep(0.2) # Wait for the given/defined seconds.
  eb.play_passive_buzzer(9, 0)
  time.sleep(2) # Wait for the given/defined seconds.
  eb.play_passive_buzzer(9, 10000)
  time.sleep(2) # Wait for the given/defined seconds.

C Code

double i = 0;



// Initialise the program settings and configurations
void setup() {
   pinMode(7, OUTPUT);  // Configures led pin as an output
   pinMode(11, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  digitalWrite(7, HIGH);
  delay(1000); // Wait for the given/defined milliseconds.
  digitalWrite(7, LOW);
  delay(1000); // Wait for the given/defined milliseconds.
  for (i = 0; i <= 200; i += 5) {
    analogWrite(11, i);
    delay(50); // Wait for the given/defined milliseconds.

  }
  for (i = 200; i >= 0; i -= 5) {
    analogWrite(11, i);
    delay(50); // Wait for the given/defined milliseconds.

  }
  delay(5000); // Wait for the given/defined milliseconds.
}

Pins

Project File

Project File

Example Video

pins.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.digital_write_config(7)
eb.analog_write_config(11)


while True:
  eb.digital_write(7, 1) # Turns the led on
  time.sleep(1) # Wait for the given/defined seconds.
  eb.digital_write(7, 0) # Turns the led off
  time.sleep(1) # Wait for the given/defined seconds.
  for i in range(0, 201, 5):
    eb.analog_write(11, i)
    time.sleep(0.05) # Wait for the given/defined seconds.
  for i in range(200, -1, -5):
    eb.analog_write(11, i)
    time.sleep(0.05) # Wait for the given/defined seconds.
  time.sleep(5) # Wait for the given/defined seconds.

C Code

double i = 0;



// Initialise the program settings and configurations
void setup() {
   pinMode(7, OUTPUT);  // Configures led pin as an output
   pinMode(11, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  digitalWrite(7, HIGH);
  delay(1000); // Wait for the given/defined milliseconds.
  digitalWrite(7, LOW);
  delay(1000); // Wait for the given/defined milliseconds.
  for (i = 0; i <= 200; i += 5) {
    analogWrite(11, i);
    delay(50); // Wait for the given/defined milliseconds.

  }
  for (i = 200; i >= 0; i -= 5) {
    analogWrite(11, i);
    delay(50); // Wait for the given/defined milliseconds.

  }
  delay(5000); // Wait for the given/defined milliseconds.
}

RGB LED

Project File

Project File

Example Video

rgb_leds.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

from dataclasses import dataclass
import time # imports the time library


@dataclass
class RGB:
  red: float
  green: float
  blue: float


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_rgbled(11, 10, 9) # Configures the RGB LED pins



while True:
  dev_color = RGB(255, 0, 0) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(2) # Wait for the given/defined seconds.
  dev_color = RGB(0, 255, 0) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(2) # Wait for the given/defined seconds.
  dev_color = RGB(0, 0, 255) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(2) # Wait for the given/defined seconds.
  dev_color = RGB(0, 0, 0) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(2) # Wait for the given/defined seconds.
  dev_color = RGB(255, 94, 0) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(2) # Wait for the given/defined seconds.

C Code

struct RGB {
    double red;
    double green;
    double blue;
};
int BLUE_PIN_1 = 9; // Define pin number for the blue LED
int RED_PIN_1 = 11; // Define pin number for the red LED
int GREEN_PIN_1 = 10; // Define pin number for the green LED



// Initialise the program settings and configurations
void setup() {
   pinMode(RED_PIN_1, OUTPUT); // Set the red LED pin as an output
   pinMode(GREEN_PIN_1, OUTPUT); // Set the green LED pin as an output
   pinMode(BLUE_PIN_1, OUTPUT); // Set the blue LED pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  setLedColor({255, 0, 0}); // Set the RGB LED colour.
  delay(2000); // Wait for the given/defined milliseconds.
  setLedColor({0, 255, 0}); // Set the RGB LED colour.
  delay(2000); // Wait for the given/defined milliseconds.
  setLedColor({0, 0, 255}); // Set the RGB LED colour.
  delay(2000); // Wait for the given/defined milliseconds.
  setLedColor({0, 0, 0}); // Set the RGB LED colour.
  delay(2000); // Wait for the given/defined milliseconds.
  setLedColor({ 255, 94, 0}); // Set the RGB LED colour.
  delay(2000); // Wait for the given/defined milliseconds.
}

// Set the brightness of each LED based on the RGB color values provided
void setLedColor(RGB color) {
    analogWrite(RED_PIN_1, color.red);  // Adjust the red LED brightness
    analogWrite(GREEN_PIN_1, color.green); // Adjust the green LED brightness
    analogWrite(BLUE_PIN_1, color.blue); // Adjust the blue LED brightness
}

Servos

Project File

Project File

Python Code

servo_python_code.mp4

Notice that the Python code is a bit slower than the C code because of the commands and processing.

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_servo(8) # Configures the servo motor on pin 8
eb.config_servo(7) # Configures the servo motor on pin 7



while True:
  for i in range(0, 91, 5):
    eb.move_servo(8, i) # Rotate servo position to i degrees
    eb.move_servo(7, (180 - i)) # Rotate servo position to (180 - i) degrees
    time.sleep(0.05) # Wait for the given/defined seconds.
  for i in range(90, -1, -5):
    eb.move_servo(8, i) # Rotate servo position to i degrees
    eb.move_servo(7, (180 - i)) # Rotate servo position to (180 - i) degrees
    time.sleep(0.05) # Wait for the given/defined seconds.

C Code

servo_c_code.mp4
#include <Servo.h> // Includes the Servo library for controlling servo motors
Servo servo_8; // Creates a servo object
Servo servo_7; // Creates a servo object

double i = 0;




// Initialise the program settings and configurations
void setup() {
   servo_8.attach(8); // Attaches the servo motor to defined pin
   servo_7.attach(7); // Attaches the servo motor to defined pin
  servo_8.write(0); // Rotate servo position to 0 degrees
  servo_7.write(180); // Rotate servo position to 180 degrees
}

// The void loop function runs over and over again forever.
void loop() {
  for (i = 0; i <= 90; i += 5) {
    servo_8.write(i); // Rotate servo position to i degrees
    servo_7.write((180 - i)); // Rotate servo position to (180 - i) degrees
    delay(50); // Wait for the given/defined milliseconds.

  }
  for (i = 90; i >= 0; i -= 5) {
    servo_8.write(i); // Rotate servo position to i degrees
    servo_7.write((180 - i)); // Rotate servo position to (180 - i) degrees
    delay(50); // Wait for the given/defined milliseconds.

  }
}

Stepper

Project File

Project File

Example Video

stepper.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_stepper_motor(11, 10, 9, 8, 2048, 10)



while True:
  eb.move_stepper_motor(2048)
  time.sleep(2) # Wait for the given/defined seconds.
  eb.move_stepper_motor(-2048)
  time.sleep(2) # Wait for the given/defined seconds.

C Code

// Include the Stepper library for controlling stepper motors
#include <Stepper.h>
// Define the number of steps per revolution for the stepper motor
const int stepsPerRevolution = 2048;
// Initialize the stepper motor with the number of steps per revolution
// and the defined/given control pins
// Pins listed in motor phase (spin) order
Stepper stepperMotor(stepsPerRevolution, 11, 9, 10, 8);


// Initialise the program settings and configurations
void setup() {
   // Set the speed of the stepper motor to defined/given speed in RPM.
   stepperMotor.setSpeed(10);

}

// The void loop function runs over and over again forever.
void loop() {
  stepperMotor.step(2048);
  delay(2000); // Wait for the given/defined milliseconds.
  stepperMotor.step(-2048);
  delay(2000); // Wait for the given/defined milliseconds.
}

Analog Read

Project File

Project File

Example Video

analog_sensor.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_analog_read(A0) # Set up analog read for pin A0.
eb.digital_write_config(13)



while True:
  if (eb.analog_read(A0) > 100):
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

C Code

// Initialise the program settings and configurations
void setup() {
   pinMode(A0, INPUT); // Configures defined pin as an input
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if (((double)analogRead(A0) > 100)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
}

Button

Project File

Project File

Example Video

button.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_button(7) # Set up button for pin 7.
eb.digital_write_config(13)


while True:
  if not eb.is_button_pressed(7):
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

C Code

// Initialise the program settings and configurations
void setup() {
   // button pin uses internal pull-up resistor.  LOW mean on and HIGH means off.
   pinMode(7, INPUT_PULLUP);
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if (!(digitalRead(7) == LOW)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
}

Digital Sensor

Project File

Project File

Example Video

digital_sensor.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_digital_read(7) # Set up digital read for pin 7.
eb.config_digital_read(8) # Set up digital read for pin 8.
eb.digital_write_config(3)
eb.digital_write_config(9)



while True:
  if eb.digital_read(8) or eb.digital_read(7):
    eb.digital_write(3, 1) # Turns the led on
  else:
    eb.digital_write(3, 0) # Turns the led off

  if eb.digital_read(8) and eb.digital_read(7):
    eb.digital_write(9, 1) # Turns the led on
  else:
    eb.digital_write(9, 0) # Turns the led off

  time.sleep(0.2) # Wait for the given/defined seconds.

C Code

// Initialise the program settings and configurations
void setup() {
   pinMode(7, INPUT); // Configures defined pin as an input
   pinMode(8, INPUT); // Configures defined pin as an input
   pinMode(3, OUTPUT);  // Configures led pin as an output
   pinMode(9, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if (digitalRead(8) || digitalRead(7)) {
    digitalWrite(3, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(3, LOW); // Set defined pin to LOW (turn it off).
  }
  if (digitalRead(8) && digitalRead(7)) {
    digitalWrite(9, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(9, LOW); // Set defined pin to LOW (turn it off).
  }
  delay(200); // Wait for the given/defined milliseconds.
}

IR Remote

Project File

Project File

Example Video

ir_remote.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_ir_remote(2) # IR Remote Config
eb.digital_write_config(8)
eb.digital_write_config(7)



while True:
  if eb.ir_remote_has_sensed_code():
    if (eb.ir_remote_get_code() == 70):
      eb.digital_write(8, 1) # Turns the led on

    if (eb.ir_remote_get_code() == 69):
      eb.digital_write(7, 1) # Turns the led on


  time.sleep(1) # Wait for the given/defined seconds.

C Code

#include <IRremote.hpp> // Include the IRremote library for infrared communication
bool developer_ir_remote_found = false; // whether ir remote was pressed
int developer_ir_remote_command = -1; // the button pressed by the ir remote




// Initialise the program settings and configurations
void setup() {
   IrReceiver.begin(2, true); //
   pinMode(8, OUTPUT);  // Configures led pin as an output
   pinMode(7, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if (developer_ir_remote_found) {
    if ((developer_ir_remote_command == 70)) {
      digitalWrite(8, HIGH); // Set defined pin to HIGH (turn it on).
    }
    if ((developer_ir_remote_command == 69)) {
      digitalWrite(7, HIGH); // Set defined pin to HIGH (turn it on).
    }
  }
  delay(1000); // Wait for the given/defined milliseconds.
  irRemoteLoopScan(); // Checks for then ir loop scan.
}

void irRemoteLoopScan() {
  if (!IrReceiver.decode()) {
    developer_ir_remote_found = false;
    developer_ir_remote_command = -1;
    IrReceiver.resume();
    return;
  }

  // Short-circuit noisy/overflow frames
  if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
    // Too long/garbled signal, skip
    IrReceiver.resume();
    developer_ir_remote_found = false;
    developer_ir_remote_command = -1;
    return;
  }

  // Ignore repeat frames (user holding the button)
  if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
    IrReceiver.resume();
    developer_ir_remote_found = false;
    developer_ir_remote_command = -1;
    return;
  }

  developer_ir_remote_found = true;
  developer_ir_remote_command = IrReceiver.decodedIRData.command;
  IrReceiver.resume();
}

Joystick

Project File

Project File

Example Video

joystick.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_joystick("A1", "A3", 9) # Configures the joystick
eb.digital_write_config(7)
eb.digital_write_config(8)
eb.digital_write_config(13)



while True:
  if eb.is_joystick_button_pressed():
    eb.digital_write(7, 1) # Turns the led on
  else:
    eb.digital_write(7, 0) # Turns the led off

  if (eb.joystick_angle() < 100):
    eb.digital_write(8, 0) # Turns the led off

  if (eb.joystick_angle() > 100):
    eb.digital_write(8, 1) # Turns the led on

  if eb.is_joystick_engaged():
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

C Code

#include <math.h>

#define Y_PIN A3
#define X_PIN A1
#define SW_PIN 9

boolean internal_variable_isJoystickButtonPressed = false;
boolean internal_variable_isJoyStickEngaged = false;
int internal_variable_degrees = 0;




// Initialise the program settings and configurations
void setup() {

    pinMode(SW_PIN, INPUT);
    pinMode(Y_PIN, INPUT);
    pinMode(X_PIN, INPUT);
    digitalWrite(SW_PIN, HIGH);
     pinMode(7, OUTPUT);  // Configures led pin as an output
   pinMode(8, OUTPUT);  // Configures led pin as an output
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if (internal_variable_isJoystickButtonPressed) {
    digitalWrite(7, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(7, LOW); // Set defined pin to LOW (turn it off).
  }
  if ((internal_variable_degrees < 100)) {
    digitalWrite(8, LOW); // Set defined pin to LOW (turn it off).
  }
  if ((internal_variable_degrees > 100)) {
    digitalWrite(8, HIGH); // Set defined pin to HIGH (turn it on).
  }
  if (internal_variable_isJoyStickEngaged) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
	setJoyStickValues();
}

void setJoyStickValues() {
  // https://medium.com/@melaniechow/using-a-joystick-sensor-on-an-arduino-3498d7399464
  // This function was inspired by this Article
  int y = (analogRead(Y_PIN) * 4.9);
  delay(50); // small pause needed between reading
  int x = (analogRead(X_PIN) * 4.9 );
  delay(50);

  x = (x - 2457);
  y = (y - 2541);

  double val = atan2(y, x) * 180/3.14159265358979;

  if (val < 0) {
    val += 360;
  }

  //convert to a double
  double new_x = x / 100.0;
  double new_y = y / 100.0;
  double distance = sqrt((new_x * new_x) + (new_y * new_y));

  internal_variable_degrees = distance > 15 ? val : 0;
  internal_variable_isJoyStickEngaged = distance > 15;
  internal_variable_isJoystickButtonPressed = digitalRead(SW_PIN) == LOW;

}

Motion Sensor

Project File

Project File

Example Video

motion_sensor.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_motion_sensor(10, 11) # Setup Motion Sensor. EchoPin = 10 TrigPin = 11
eb.digital_write_config(13)



while True:
  if (eb.motion_distance_cm() < (2 * 3)):
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

C Code

// Initialise the program settings and configurations
void setup() {
   pinMode(10, INPUT); // Set pin 10 as input for the echo signal
   pinMode(11, OUTPUT); // Set pin 11 as output for the trigger signal
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if ((ultraSonicDistance() < (2 * 3))) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
}

// This is function to Trigger the ultrasonic sensor and measure the distance
double ultraSonicDistance() {
  digitalWrite(11, LOW); // Set the trigger pin to low
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(11, HIGH); // set the trigger pin to high
  delayMicroseconds(10); // Wait for 10 microseconds
  digitalWrite(11, LOW); // Set the trigger pin to low
  long microseconds = pulseIn(10, HIGH); // Measure the time for the echo to retur
  return (double)(microseconds / 29 / 2);  // Convert the time to distance in cm
}

Temp Sensor

Project File

Project File

Example Pictures

IMG_4580 Screenshot 2026-01-03 at 8 21 35 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_dht_temp(2)
eb.digital_write_config(13)



while True:
  print(f"{eb.dht_temp_celcius():.2f}")
  print(f"{eb.dht_temp_humidity():.2f}")
  if (eb.dht_temp_celcius() > 15) or (eb.dht_temp_humidity() > 50):
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

C Code

String serialMessageDEV = "";
boolean stopDebugging = false;
#define DHTPIN 2 // Define pin  for the DHT sensor data
#define DHTTYPE DHT11 // Define the type of DHT sensor.
#include <DHT.h>; // Include the DHT library for temperature and humidity sensor
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor using the defined pin and type



// Initialise the program settings and configurations
void setup() {
   dht.begin(); // Initialize the DHT sensor
   Serial.begin(115200);
   Serial.setTimeout(100);
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  Serial.println((double2string((double)dht.readTemperature(), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string((double)dht.readHumidity(), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  if (((double)dht.readTemperature() > 20) && ((double)dht.readHumidity() > 50)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
  delay(200); // Wait for the given/defined milliseconds.
}

 String double2string(double n, int ndec) {
		 String r = "";
		 int v = n;
		 r += v;     // whole number part
		 r += '.';   // decimal point
		 int i;
		 for (i = 0; i < ndec; i++) {
		     // iterate through each decimal digit for 0..ndec
		     n -= v;
		     n *= 10;
		     v = n;
		     r += v;
		 }

		 return r;
}

Thermistor

Project File

Project File

Example Video

thermistor.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_thermistor('A0') # Set's up the thermistor.
eb.digital_write_config(13)



while True:
  if (eb.thermistor_celsius() > 50):
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

  if (eb.thermistor_fahrenheit() > 60):
    eb.digital_write(13, 1) # Turns the led on
  else:
    eb.digital_write(13, 0) # Turns the led off

C Code

String serialMessageDEV = "";

#define THERMISTOR_PIN  A0 // Define analog pin for the thermistor
#define BETA            3950 // The beta value of the thermistor
#define RESISTANCE      10000 // The value of the pull-down resistor (in ohms)



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);
   pinMode(A0, INPUT); // Configures the thermistor pin as an input
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  if ((readThermistor("C") > 50)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
  if ((readThermistor("F") > 60)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  } else {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
}

float readThermistor(String returnUnit) {
  // Read the thermistor value from the analog pin
  long a = analogRead(THERMISTOR_PIN);

  // Calculate the temperature using the thermistor's equation
  float tempC = BETA / (log((1025.0 * RESISTANCE / a - RESISTANCE) / RESISTANCE) + BETA / 298.0) - 273.0;

  // Convert Celsius to Fahrenheit (optional)
  float tempF = (tempC * 1.8) + 32.0;

  // Print the Celsius temperature
  Serial.print("TempC: ");
  Serial.print(tempC); // Print Celsius temperature
  Serial.println(" °C"); // Print the unit

  // Print the Fahrenheit temperature (optional)
  Serial.print("TempF: ");
  Serial.print(tempF); // Print Fahrenheit temperature
  Serial.println(" °F"); // Print the unit

  delay(200); // Wait for 200 milliseconds before the next reading

  return returnUnit == "C" ? tempC : tempF; // Return the temperature based on the unit.
}

Text Parser

Project File

Project File

Example

Screenshot 2026-01-08 at 8 58 46 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library

# Function Code

def get_parse_value(data: str, separator: str, index: int, default: str = "") -> str:
    parts = data.split(separator)
    return parts[index] if 0 <= index < len(parts) else default


# Variable Declaration
i = 0

test = ""


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  for i in range(1, 4, 1):
    test = (get_parse_value("blue,red,green", ",", max(0, (i) - 1)))
    print(test)
    time.sleep(2) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

double i = 0;

String test = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  for (i = 1; i <= 3; i += 1) {
    test = getParseValue(String("blue,red,green"), ',', i);
    Serial.println(test);
    Serial.flush(); // Waits until outgoing buffer is empty
    delay(2000); // Wait for the given/defined milliseconds.

  }
}


String getParseValue(String data, char separator, int index) {
	int found = 0;	int strIndex[] = {0, -1};
	int maxIndex = data.length()-1;
	for(int i=0; i<=maxIndex && found<=index; i++){
	    if(data.charAt(i) == separator || i == maxIndex){
	        found++;
	        strIndex[0] = strIndex[1]+1;
	        strIndex[1] = (i == maxIndex) ? i+1 : i;
	    }
	}
	return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

Add Text

Project File

Project File

Example

Screenshot 2026-01-08 at 9 03 21 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
test = ""

local = ""


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  local = "part_one"
  test = (str(local) + " " + "part_two")
  print(test)
  time.sleep(2) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

String test = "";

String local = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  local = String("part_one");
  test = local + String(" ") + String("part_two");
  Serial.println(test);
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(2000); // Wait for the given/defined milliseconds.
}

Text Length

Project File

Project File

Example

Screenshot 2026-01-11 at 12 04 43 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
sound = ""


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  sound = "moo"
  if (len("abc") == 3):
    print("Works")
    time.sleep(2) # Wait for the given/defined seconds.

  if (len(sound) == 3):
    print("Works")
    time.sleep(2) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

String sound = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  sound = String("moo");
  if ((textLength(String("abc")) == 3)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
    delay(2000); // Wait for the given/defined milliseconds.
  }
  if ((textLength(sound) == 3)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
    delay(2000); // Wait for the given/defined milliseconds.
  }
}

double textLength(String str) {
	 return (double)str.length();
}

Upper / Lower Case

Project File

Project File

Example

Screenshot 2026-01-08 at 9 17 12 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
text = ""

lol = ""


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  lol = "aSf"
  print(("Blah".upper()))
  print(("Blah".lower()))
  print((lol.upper()))
  print((lol.lower()))
  time.sleep(2) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

String text = "";

String lol = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  lol = String("aSf");
  Serial.println(upperCaseString(String("Blah")));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println(lowerCaseString(String("Blah")));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println(upperCaseString(lol));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println(lowerCaseString(lol));
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(2000); // Wait for the given/defined milliseconds.
}


String upperCaseString(String str) {
	str.toUpperCase();
	return str;
}


String lowerCaseString(String str) {
	str.toLowerCase();
	return str;
}

Is Empty Text

Project File

Project File

Examples

Screenshot 2026-01-08 at 9 23 31 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
full = ""


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  full = "abc"
  if (len("") == 0):
    print("works")
    time.sleep(2) # Wait for the given/defined seconds.

  if (len(full) == 0):
    print("not working")
    time.sleep(2) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

String full = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  full = String("abc");
  if ((textLength(String("")) == 0)) {
    Serial.println(String("works"));
    Serial.flush(); // Waits until outgoing buffer is empty
    delay(2000); // Wait for the given/defined milliseconds.
  }
  if ((textLength(full) == 0)) {
    Serial.println(String("not working"));
    Serial.flush(); // Waits until outgoing buffer is empty
    delay(2000); // Wait for the given/defined milliseconds.
  }
}

double textLength(String str) {
	 return (double)str.length();
}

Number to Text

Project File

Project File

Example

Screenshot 2026-01-08 at 9 27 14 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
large_num = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  large_num = 4032.3333
  print(f"{large_num:.2f}")
  print(f"{123.234234:.3f}")
  time.sleep(3) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
boolean stopDebugging = false;

double large_num = 0;



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  large_num = 4032.3333;
  Serial.println((double2string(large_num, 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string(123.234234, 3)));
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(3000); // Wait for the given/defined milliseconds.
}

 String double2string(double n, int ndec) {
		 String r = "";
		 int v = n;
		 r += v;     // whole number part
		 r += '.';   // decimal point
		 int i;
		 for (i = 0; i < ndec; i++) {
		     // iterate through each decimal digit for 0..ndec
		     n -= v;
		     n *= 10;
		     v = n;
		     r += v;
		 }

		 return r;
}

Math Number Property

Project File

Project File

Example

number_property

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
num = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  num = 33
  if (3 % 2 == 0):
    print("Should Skip")

  if (num % 2 == 1):
    print("Works")

  if (3 > 0):
    print("Works")

  if (num < 0):
    print("Should Skip")

  if (3 % 12 == 0):
    print("Works")

  time.sleep(2) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

double num = 0;



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  num = 33;
  if (((int)3 % 2 == 0)) {
    Serial.println(String("Should Skip"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  if (((int)num % 2 == 1)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  if ((3 > 0)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  if ((num < 0)) {
    Serial.println(String("Should Skip"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  if (((int)3 % (int)12 == 0)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  delay(2000); // Wait for the given/defined milliseconds.
}

Math Arithmetic

Project File

Project File

Example

math_arithmetic
 arduino 2.00 (12:11:49 PM)

arduino 2.00 (12:11:49 PM)

arduino 0.00 (12:11:49 PM)

arduino 1.00 (12:11:49 PM)

arduino 1.00 (12:11:49 PM)

arduino 1.00 (12:11:49 PM)

arduino --------------------------------------- (12:11:49 PM)
...

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0

j = 0

number = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  number = 33
  for i in range(1, 11, 1):
    for j in range(1, 11, 1):
      number = (1 + 1)
      print(f"{number:.2f}")
      number = (i + j)
      print(f"{number:.2f}")
      number = (i - j)
      print(f"{number:.2f}")
      number = (i * j)
      print(f"{number:.2f}")
      number = (i / j)
      print(f"{number:.2f}")
      number = (i ** j)
      print(f"{number:.2f}")
      time.sleep(0.2) # Wait for the given/defined seconds.
      print("---------------------------------------")
  print("DONE")
  time.sleep(20) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
boolean stopDebugging = false;

double i = 0;

double j = 0;

double number = 0;



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  number = 33;
  for (i = 1; i <= 10; i += 1) {
    for (j = 1; j <= 10; j += 1) {
      number = (1 + 1);
      Serial.println((double2string(number, 2)));
      Serial.flush(); // Waits until outgoing buffer is empty
      number = (i + j);
      Serial.println((double2string(number, 2)));
      Serial.flush(); // Waits until outgoing buffer is empty
      number = (i - j);
      Serial.println((double2string(number, 2)));
      Serial.flush(); // Waits until outgoing buffer is empty
      number = (i * j);
      Serial.println((double2string(number, 2)));
      Serial.flush(); // Waits until outgoing buffer is empty
      number = (i / j);
      Serial.println((double2string(number, 2)));
      Serial.flush(); // Waits until outgoing buffer is empty
      number = (pow(i, j));
      Serial.println((double2string(number, 2)));
      Serial.flush(); // Waits until outgoing buffer is empty
      delay(200); // Wait for the given/defined milliseconds.
      Serial.println(String("---------------------------------------"));
      Serial.flush(); // Waits until outgoing buffer is empty

    }

  }
  Serial.println(String("DONE"));
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(20000); // Wait for the given/defined milliseconds.
}

 String double2string(double n, int ndec) {
		 String r = "";
		 int v = n;
		 r += v;     // whole number part
		 r += '.';   // decimal point
		 int i;
		 for (i = 0; i < ndec; i++) {
		     // iterate through each decimal digit for 0..ndec
		     n -= v;
		     n *= 10;
		     v = n;
		     r += v;
		 }

		 return r;
}

Text to Number

Project File

Project File

Example

text_to_number

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library


# Variable Declaration
i = 0

j = 0

number = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  number = 33
  for i in range(1, 11, 1):
    for j in range(1, 11, 1):
      number = (1 + 1)
      print(f"{number:.2f}")
      number = (i + j)
      print(f"{number:.2f}")
      number = (i - j)
      print(f"{number:.2f}")
      number = (i * j)
      print(f"{number:.2f}")
      number = (i / j)
      print(f"{number:.2f}")
      number = (i ** j)
      print(f"{number:.2f}")
      time.sleep(0.2) # Wait for the given/defined seconds.
      print("---------------------------------------")
  print("DONE")
  time.sleep(20) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";

String example = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  example = String("3");
  if ((parseDouble(String("5.35")) == 5.35)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
  } else {
    Serial.println(String("No Working"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  if ((parseDouble(example) == 3)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
  } else {
    Serial.println(String("No Working"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  example = String("3.5");
  if ((parseDouble(example) == 3.5)) {
    Serial.println(String("Works"));
    Serial.flush(); // Waits until outgoing buffer is empty
  } else {
    Serial.println(String("No Working"));
    Serial.flush(); // Waits until outgoing buffer is empty
  }
  delay(2000); // Wait for the given/defined milliseconds.
}


double parseDouble(String num) {
	 // Use num.toDouble() instead of this.  Doing this because of arduino is compiling on a linux server.
	char str[40];
	num.toCharArray(str, num.length() + 1);
	return atof(str);
}

Math Round

Project File

Project File

Example

round

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import math
import time # imports the time library


# Variable Declaration
num = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  num = 12.5
  print(f"{round(3.1):.2f}")
  print(f"{math.ceil(3.1):.2f}")
  print(f"{math.floor(3.1):.2f}")
  print(f"{round(num):.2f}")
  print(f"{math.ceil(num):.2f}")
  print(f"{math.floor(num):.2f}")
  time.sleep(10) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
boolean stopDebugging = false;

double num = 0;



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  num = 12.5;
  Serial.println((double2string(((double)round(3.1)), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string(((double)ceil(3.1)), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string(((double)floor(3.1)), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string(((double)round(num)), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string(((double)ceil(num)), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  Serial.println((double2string(((double)floor(num)), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(10000); // Wait for the given/defined milliseconds.
}

 String double2string(double n, int ndec) {
		 String r = "";
		 int v = n;
		 r += v;     // whole number part
		 r += '.';   // decimal point
		 int i;
		 for (i = 0; i < ndec; i++) {
		     // iterate through each decimal digit for 0..ndec
		     n -= v;
		     n *= 10;
		     v = n;
		     r += v;
		 }

		 return r;
}

Math Remainder / Random

Project File

Project File

Example

Screenshot 2026-01-11 at 12 43 49 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import random
import time # imports the time library


# Variable Declaration
random2 = 0

remainer = 0


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  random2 = (random.randint(1, 10))
  print(f"{random2:.2f}")
  random2 = (random.randint(1, 100))
  print(f"{random2:.2f}")
  remainer = ((64 % 10))
  print(f"{remainer:.2f}")
  remainer = ((2 % 10))
  print(f"{remainer:.2f}")
  time.sleep(20) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
boolean stopDebugging = false;

double random2 = 0;

double remainer = 0;



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  random2 = ((double)random(1, 10));
  Serial.println((double2string(random2, 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  random2 = ((double)random(1, 100));
  Serial.println((double2string(random2, 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  remainer = ((double)((int)64 % (int)10));
  Serial.println((double2string(remainer, 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  remainer = ((double)((int)2 % (int)10));
  Serial.println((double2string(remainer, 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(20000); // Wait for the given/defined milliseconds.
}

 String double2string(double n, int ndec) {
		 String r = "";
		 int v = n;
		 r += v;     // whole number part
		 r += '.';   // decimal point
		 int i;
		 for (i = 0; i < ndec; i++) {
		     // iterate through each decimal digit for 0..ndec
		     n -= v;
		     n *= 10;
		     v = n;
		     r += v;
		 }

		 return r;
}

Time

Project File

Project File

Example

Screenshot 2026-01-11 at 12 59 53 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library

arduino_start_time = time.time() # Start time of the Arduino program


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class



while True:
  print(f"{(time.time() - arduino_start_time):.2f}")
  time.sleep(0.1) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
boolean stopDebugging = false;



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);

}

// The void loop function runs over and over again forever.
void loop() {
  Serial.println((double2string(secondsArduinoBeenOn(), 2)));
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(100); // Wait for the given/defined milliseconds.
}

 String double2string(double n, int ndec) {
		 String r = "";
		 int v = n;
		 r += v;     // whole number part
		 r += '.';   // decimal point
		 int i;
		 for (i = 0; i < ndec; i++) {
		     // iterate through each decimal digit for 0..ndec
		     n -= v;
		     n *= 10;
		     v = n;
		     r += v;
		 }

		 return r;
}
double secondsArduinoBeenOn() {
	return millis() / 1000.0;
}

My Blocks

Project File

Project File

Example Video

my_blocks.mp4
Screenshot 2026-01-11 at 1 46 53 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library

# Function Code

def blink():
  eb.digital_write(13, 1) # Turns the led on
  time.sleep(0.2) # Wait for the given/defined seconds.
  eb.digital_write(13, 0) # Turns the led off
  time.sleep(0.2) # Wait for the given/defined seconds.


def print_hi():
  print("Hi")



# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.digital_write_config(13)



while True:
  print_hi()
  blink()

C Code

String serialMessageDEV = "";



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  print_hi();
  blink();
}

void blink() {
  digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  delay(200); // Wait for the given/defined milliseconds.
  digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  delay(200); // Wait for the given/defined milliseconds.
}
void print_hi() {
  Serial.println(String("Hi"));
  Serial.flush(); // Waits until outgoing buffer is empty
}

Color Blocks

Project File

Project File

Example Video

colors.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

from dataclasses import dataclass
import random
import time # imports the time library


@dataclass
class RGB:
  red: float
  green: float
  blue: float


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_rgbled(11, 10, 9) # Configures the RGB LED pins



while True:
  dev_color = RGB(random.randint(0, 255), random.randint(0,255), radnom.randit(0,255)) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(1) # Wait for the given/defined seconds.
  dev_color = RGB(100, 0, 100) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(1) # Wait for the given/defined seconds.
  dev_color = RGB(255, 0, 51) # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(1) # Wait for the given/defined seconds.

C Code

struct RGB {
    double red;
    double green;
    double blue;
};
int BLUE_PIN_1 = 9; // Define pin number for the blue LED
int RED_PIN_1 = 11; // Define pin number for the red LED
int GREEN_PIN_1 = 10; // Define pin number for the green LED



// Initialise the program settings and configurations
void setup() {
   pinMode(RED_PIN_1, OUTPUT); // Set the red LED pin as an output
   pinMode(GREEN_PIN_1, OUTPUT); // Set the green LED pin as an output
   pinMode(BLUE_PIN_1, OUTPUT); // Set the blue LED pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  setLedColor({ random(0, 255), random(0, 255), random(0, 255)}); // Set the RGB LED colour.
  delay(1000); // Wait for the given/defined milliseconds.
  setLedColor({ 100, 0, 100}); // Set the RGB LED colour.
  delay(1000); // Wait for the given/defined milliseconds.
  setLedColor({ 255, 0, 51}); // Set the RGB LED colour.
  delay(1000); // Wait for the given/defined milliseconds.
}

// Set the brightness of each LED based on the RGB color values provided
void setLedColor(RGB color) {
    analogWrite(RED_PIN_1, color.red);  // Adjust the red LED brightness
    analogWrite(GREEN_PIN_1, color.green); // Adjust the green LED brightness
    analogWrite(BLUE_PIN_1, color.blue); // Adjust the blue LED brightness
}

Variables

Project File

Project File

Example

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

from dataclasses import dataclass
import time # imports the time library


@dataclass
class RGB:
  red: float
  green: float
  blue: float


# Variable Declaration
num = 0

name = ""

awesome = False

deep_blue = RGB(0, 0, 0)


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_rgbled(11, 10, 9) # Configures the RGB LED pins
eb.digital_write_config(13)



while True:
  deep_blue = RGB(0, 89, 255)
  awesome = True
  name = "Robo1000"
  num = 33
  if (num == 33):
    eb.digital_write(13, 1) # Turns the led on

  time.sleep(1) # Wait for the given/defined seconds.
  print(("Hi, " + str(name)))
  time.sleep(1) # Wait for the given/defined seconds.
  if awesome:
    eb.digital_write(13, 0) # Turns the led off

  dev_color = deep_blue # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.

C Code

String serialMessageDEV = "";
struct RGB {
    double red;
    double green;
    double blue;
};
int BLUE_PIN_1 = 9; // Define pin number for the blue LED
int RED_PIN_1 = 11; // Define pin number for the red LED
int GREEN_PIN_1 = 10; // Define pin number for the green LED

double num = 0;

String name = "";

boolean awesome = false;

struct RGB deep_blue = {0, 0, 0};



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);
   pinMode(RED_PIN_1, OUTPUT); // Set the red LED pin as an output
   pinMode(GREEN_PIN_1, OUTPUT); // Set the green LED pin as an output
   pinMode(BLUE_PIN_1, OUTPUT); // Set the blue LED pin as an output
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  deep_blue = { 0, 89, 255};
  awesome = true;
  name = String("Robo1000");
  num = 33;
  if ((num == 33)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  }
  delay(1000); // Wait for the given/defined milliseconds.
  Serial.println(String("Hi, ") + name);
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(1000); // Wait for the given/defined milliseconds.
  if (awesome) {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
  setLedColor(deep_blue); // Set the RGB LED colour.
}

// Set the brightness of each LED based on the RGB color values provided
void setLedColor(RGB color) {
    analogWrite(RED_PIN_1, color.red);  // Adjust the red LED brightness
    analogWrite(GREEN_PIN_1, color.green); // Adjust the green LED brightness
    analogWrite(BLUE_PIN_1, color.blue); // Adjust the blue LED brightness
}

Variables

Project File

Project File

Example Video

Screenshot 2026-01-11 at 2 53 23 PM
variables.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

from dataclasses import dataclass
import time # imports the time library


@dataclass
class RGB:
  red: float
  green: float
  blue: float


# Variable Declaration
num = 0

name = ""

awesome = False

deep_blue = RGB(0, 0, 0)


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_rgbled(11, 10, 9) # Configures the RGB LED pins
eb.digital_write_config(13)



while True:
  deep_blue = RGB(0, 89, 255)
  awesome = True
  name = "Robo1000"
  num = 33
  if (num == 33):
    eb.digital_write(13, 1) # Turns the led on

  time.sleep(1) # Wait for the given/defined seconds.
  print(("Hi, " + str(name)))
  time.sleep(1) # Wait for the given/defined seconds.
  if awesome:
    eb.digital_write(13, 0) # Turns the led off

  dev_color = deep_blue # Create the RGB color object.
  eb.set_color_rgbled(dev_color.red, dev_color.green, dev_color.blue) # Set the RGB LED color on the Arduino.
  time.sleep(1) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
struct RGB {
    double red;
    double green;
    double blue;
};
int BLUE_PIN_1 = 9; // Define pin number for the blue LED
int RED_PIN_1 = 11; // Define pin number for the red LED
int GREEN_PIN_1 = 10; // Define pin number for the green LED

double num = 0;

String name = "";

boolean awesome = false;

struct RGB deep_blue = {0, 0, 0};



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);
   pinMode(RED_PIN_1, OUTPUT); // Set the red LED pin as an output
   pinMode(GREEN_PIN_1, OUTPUT); // Set the green LED pin as an output
   pinMode(BLUE_PIN_1, OUTPUT); // Set the blue LED pin as an output
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  deep_blue = { 0, 89, 255};
  awesome = true;
  name = String("Robo1000");
  num = 33;
  if ((num == 33)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  }
  delay(1000); // Wait for the given/defined milliseconds.
  Serial.println(String("Hi, ") + name);
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(1000); // Wait for the given/defined milliseconds.
  if (awesome) {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
  setLedColor(deep_blue); // Set the RGB LED colour.
  delay(1000); // Wait for the given/defined milliseconds.
}

// Set the brightness of each LED based on the RGB color values provided
void setLedColor(RGB color) {
    analogWrite(RED_PIN_1, color.red);  // Adjust the red LED brightness
    analogWrite(GREEN_PIN_1, color.green); // Adjust the green LED brightness
    analogWrite(BLUE_PIN_1, color.blue); // Adjust the blue LED brightness
}

Simple List

Project File

Project File

Example

Screenshot 2026-01-11 at 8 23 22 PM

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library

# Function Code

def set_item_in_list(lst, pos, value, fill=None):
    """
    Sets a 1-based position in a list.
    Grows the list if needed using the fill value.
    """
    idx = max(0, int(pos) - 1)

    while idx >= len(lst):
        lst.append(fill)

    lst[idx] = value


def get_item_from_list(lst, pos, default=None):
    """
    Gets a 1-based position from a list.
    Returns default if the position is out of range or the list is empty.
    """
    idx = max(0, int(pos) - 1)
    if 0 <= idx < len(lst):
        return lst[idx]
    return default



# Variable Declaration
i = 0

j = 0

nums = []

animals = []


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class


def setup():
  for i in range(1, 6, 1):
    set_item_in_list(nums, i, (i * 2), -1)
  set_item_in_list(animals, 1, "Fish", "")
  set_item_in_list(animals, 2, "Cats", "")
  set_item_in_list(animals, 3, "Mice", "")


# Call Setup Function to do what the arduino does. Only gets called once.
setup()


while True:
  for j in range(1, 4, 1):
    print(get_item_from_list(animals, j, ""))
    time.sleep(0.2) # Wait for the given/defined seconds.
  for j in range(1, 6, 1):
    print(f"{get_item_from_list(nums, j, -1):.2f}")
    time.sleep(0.2) # Wait for the given/defined seconds.
  time.sleep(20) # Wait for the given/defined seconds.

C Code

String serialMessageDEV = "";
struct RGB {
    double red;
    double green;
    double blue;
};
int BLUE_PIN_1 = 9; // Define pin number for the blue LED
int RED_PIN_1 = 11; // Define pin number for the red LED
int GREEN_PIN_1 = 10; // Define pin number for the green LED

double num = 0;

String name = "";

boolean awesome = false;

struct RGB deep_blue = {0, 0, 0};



// Initialise the program settings and configurations
void setup() {
   Serial.begin(115200);
   Serial.setTimeout(100);
   pinMode(RED_PIN_1, OUTPUT); // Set the red LED pin as an output
   pinMode(GREEN_PIN_1, OUTPUT); // Set the green LED pin as an output
   pinMode(BLUE_PIN_1, OUTPUT); // Set the blue LED pin as an output
   pinMode(13, OUTPUT);  // Configures led pin as an output

}

// The void loop function runs over and over again forever.
void loop() {
  deep_blue = { 0, 89, 255};
  awesome = true;
  name = String("Robo1000");
  num = 33;
  if ((num == 33)) {
    digitalWrite(13, HIGH); // Set defined pin to HIGH (turn it on).
  }
  delay(1000); // Wait for the given/defined milliseconds.
  Serial.println(String("Hi, ") + name);
  Serial.flush(); // Waits until outgoing buffer is empty
  delay(1000); // Wait for the given/defined milliseconds.
  if (awesome) {
    digitalWrite(13, LOW); // Set defined pin to LOW (turn it off).
  }
  setLedColor(deep_blue); // Set the RGB LED colour.
}

// Set the brightness of each LED based on the RGB color values provided
void setLedColor(RGB color) {
    analogWrite(RED_PIN_1, color.red);  // Adjust the red LED brightness
    analogWrite(GREEN_PIN_1, color.green); // Adjust the green LED brightness
    analogWrite(BLUE_PIN_1, color.blue); // Adjust the blue LED brightness
}

Rainbow / Color List

Project File

Project File

Example Video Python

python_rainbow.mp4

Example Video C

c_rainbow.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks

from dataclasses import dataclass
import time # imports the time library


@dataclass
class RGB:
  red: float
  green: float
  blue: float

# Function Code

def set_item_in_list(lst, pos, value, fill=None):
    """
    Sets a 1-based position in a list.
    Grows the list if needed using the fill value.
    """
    idx = max(0, int(pos) - 1)

    while idx >= len(lst):
        lst.append(fill)

    lst[idx] = value


def get_item_from_list(lst, pos, default=None):
    """
    Gets a 1-based position from a list.
    Returns default if the position is out of range or the list is empty.
    """
    idx = max(0, int(pos) - 1)
    if 0 <= idx < len(lst):
        return lst[idx]
    return default



# Variable Declaration
j = 0

i = 0

k = 0

tempcolor = RGB(0, 0, 0)

colors = []


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
eb.config_rgb_strip("3", 30, "GRB", 10) # Configures the NEOPIXEL strip


def setup():
  tempcolor = RGB(255, 0, 255)
  for i in range(1, 7, 1):
    set_item_in_list(colors, i, RGB(255, 0, 72), RGB(0,0,0))
  for i in range(7, 13, 1):
    set_item_in_list(colors, i, RGB(255, 255, 0), RGB(0,0,0))
  for i in range(13, 19, 1):
    set_item_in_list(colors, i, RGB(0, 255, 30), RGB(0,0,0))
  for i in range(19, 25, 1):
    set_item_in_list(colors, i, RGB(0, 72, 255), RGB(0,0,0))
  for i in range(25, 31, 1):
    set_item_in_list(colors, i, RGB(255, 0, 191), RGB(0,0,0))


# Call Setup Function to do what the arduino does. Only gets called once.
setup()


while True:
  for j in range(1, 31, 1):
    developer_temp_color = get_item_from_list(colors, j, RGB(0,0,0)) # create a variable to store the color
    eb.rgb_strip_set_color(j, developer_temp_color.red, developer_temp_color.green, developer_temp_color.blue)
  eb.rgb_strip_show_all() # Sets the color the led strip.
  time.sleep(0.2) # Wait for the given/defined seconds.
  tempcolor = get_item_from_list(colors, 30, RGB(0,0,0))
  for k in range(30, 1, -1):
    set_item_in_list(colors, k, get_item_from_list(colors, (k - 1), RGB(0,0,0)), RGB(0,0,0))
  set_item_in_list(colors, 0, tempcolor, RGB(0,0,0))

C Code

struct RGB {
    double red;
    double green;
    double blue;
};

#include <FastLED.h>  // Includes the FastLED library for controlling LED strips
#define NUM_LEDS 30 // Defines the number of LEDs in the strip
#define DATA_PIN 3 // Creates an array to hold the LED colors
CRGB leds[NUM_LEDS]; // Creates an array to hold the LED colors



double j = 0;

double i = 0;

double k = 0;

struct RGB tempcolor = {0, 0, 0};

struct RGB colors[30];



// Initialise the program settings and configurations
void setup() {

   // Initializes the LED strip
   FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
   // Sets the brightness of the LEDs
   FastLED.setBrightness(10);
  tempcolor = { 255, 0, 255};
  for (i = 1; i <= 6; i += 1) {
    colors[zeroIndexAdjustNumber(i)] = { 255, 0, 72};

  }
  for (i = 7; i <= 12; i += 1) {
    colors[zeroIndexAdjustNumber(i)] = { 255, 255, 0};

  }
  for (i = 13; i <= 18; i += 1) {
    colors[zeroIndexAdjustNumber(i)] = { 0, 255, 30};

  }
  for (i = 19; i <= 24; i += 1) {
    colors[zeroIndexAdjustNumber(i)] = { 0, 72, 255};

  }
  for (i = 25; i <= 30; i += 1) {
    colors[zeroIndexAdjustNumber(i)] = { 255, 0, 191};

  }
}

// The void loop function runs over and over again forever.
void loop() {
  for (j = 1; j <= 30; j += 1) {
    setFastLEDColor(j,colors[zeroIndexAdjustNumber(j)]);

  }
  FastLED.show(); // Sets the color the led strip.
  delay(200); // Wait for the given/defined milliseconds.
  tempcolor = colors[zeroIndexAdjustNumber(30)];
  for (k = 30; k >= 2; k -= 1) {
    colors[zeroIndexAdjustNumber(k)] = colors[zeroIndexAdjustNumber((k - 1))];

  }
  colors[zeroIndexAdjustNumber(0)] = tempcolor;
}


// Sets the color of a specific LED at the given position
void setFastLEDColor(int pos, struct RGB color) {
    pos = pos <= 0 ? 0 : pos; // Ensures the position is not negative
    pos = pos >= 1 ? pos - 1 : pos;  // Adjusts position to fit within the array bounds
    leds[pos].setRGB((int)color.red, (int)color.green, (int)color.blue); // Sets the LED color
}


int zeroIndexAdjustNumber(double pos) {
	pos = pos <= 0 ? 0 : pos;
	return pos >= 1 ? pos - 1 : pos;
}

Led Matrix Bool List

Project File

Project File

Python Example Video

python_led_matix_bools.mp4

C Example Video

c_led_matix_bools.mp4

Python Code

#Import ElectroBlocks library
from electroblocks import ElectroBlocks
import time # imports the time library

# Function Code

def set_item_in_list(lst, pos, value, fill=None):
    """
    Sets a 1-based position in a list.
    Grows the list if needed using the fill value.
    """
    idx = max(0, int(pos) - 1)

    while idx >= len(lst):
        lst.append(fill)

    lst[idx] = value


def get_item_from_list(lst, pos, default=None):
    """
    Gets a 1-based position from a list.
    Returns default if the position is out of range or the list is empty.
    """
    idx = max(0, int(pos) - 1)
    if 0 <= idx < len(lst):
        return lst[idx]
    return default



# Variable Declaration
x = 0

y = 0

leds = []


# Initialise the program settings and configurations
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class


eb.config_led_matrix(10,11,12, True)
def setup():
  set_item_in_list(leds, 1, True, False)
  set_item_in_list(leds, 2, True, False)
  set_item_in_list(leds, 3, True, False)
  set_item_in_list(leds, 4, False, False)
  set_item_in_list(leds, 5, False, False)
  set_item_in_list(leds, 6, False, False)
  set_item_in_list(leds, 7, True, False)
  set_item_in_list(leds, 8, True, False)


# Call Setup Function to do what the arduino does. Only gets called once.
setup()


while True:
  for x in range(1, 9, 1):
    for y in range(1, 11, 1):
      if get_item_from_list(leds, x, False):
        eb.set_led_matrix_led(y, x, True)
      else:
        eb.set_led_matrix_led(y, x, False)

  time.sleep(3) # Wait for the given/defined seconds.
  for x in range(1, 9, 1):
    for y in range(1, 11, 1):
      if get_item_from_list(leds, y, False):
        eb.set_led_matrix_led(y, x, True)
      else:
        eb.set_led_matrix_led(y, x, False)

  time.sleep(3) # Wait for the given/defined seconds.

C Code

// This a wrapper library on LedControl that allows us to rotate for breadboards
#include "LedMatrix.h";

LedMatrix lm(10, 12, 11, LedMatrix::R0, true);
byte developer_ledmatrix_image[8] = {
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000
};

double x = 0;

double y = 0;

boolean leds[8];



// Initialise the program settings and configurations
void setup() {
  leds[zeroIndexAdjustNumber(1)] = true;
  leds[zeroIndexAdjustNumber(2)] = true;
  leds[zeroIndexAdjustNumber(3)] = true;
  leds[zeroIndexAdjustNumber(4)] = false;
  leds[zeroIndexAdjustNumber(5)] = false;
  leds[zeroIndexAdjustNumber(6)] = false;
  leds[zeroIndexAdjustNumber(7)] = true;
  leds[zeroIndexAdjustNumber(8)] = true;
}

// The void loop function runs over and over again forever.
void loop() {
  for (x = 1; x <= 8; x += 1) {
    for (y = 1; y <= 10; y += 1) {
      if (leds[zeroIndexAdjustNumber(x)]) {

        lm.setPixel(x, y, true); // change one pixel in the buffer.
        lm.setImage(); // changes the pixels on the device

      } else {

        lm.setPixel(x, y, false); // change one pixel in the buffer.
        lm.setImage(); // changes the pixels on the device

      }

    }

  }
  delay(3000); // Wait for the given/defined milliseconds.
  for (x = 1; x <= 8; x += 1) {
    for (y = 1; y <= 10; y += 1) {
      if (leds[zeroIndexAdjustNumber(y)]) {

        lm.setPixel(x, y, true); // change one pixel in the buffer.
        lm.setImage(); // changes the pixels on the device

      } else {

        lm.setPixel(x, y, false); // change one pixel in the buffer.
        lm.setImage(); // changes the pixels on the device

      }

    }

  }
  delay(3000); // Wait for the given/defined milliseconds.
}


int zeroIndexAdjustNumber(double pos) {
	pos = pos <= 0 ? 0 : pos;
	return pos >= 1 ? pos - 1 : pos;
}