--- /dev/null
+https://www.tinkercad.com/things/bJ9mxNp3wXG
--- /dev/null
+https://www.tinkercad.com/things/kQ6afgEqekR
--- /dev/null
+https://www.tinkercad.com/things/aHW3wNDugHU
--- /dev/null
+https://www.tinkercad.com/things/kaVhIKUgeAY
--- /dev/null
+#include <stdlib.h>
+
+#define DATA1_PIN 12
+#define DATA2_PIN 5
+#define DATA3_PIN 4
+#define DATA4_PIN 13
+#define LATCH0_PIN 11
+#define LATCH1_PIN 9
+#define LATCH2_PIN 8
+#define LATCH3_PIN 7
+#define LATCH4_PIN 6
+#define LATCH5_PIN A5
+#define BLANKING_PIN 10
+
+#define BUTTON_PIN 3
+#define POT_PIN A4
+#define NC_PIN A3
+
+#define DIGITS 6
+#define BRIGHTNESS 200 // Maximum 255
+
+const uint8_t data_pins[4] = {DATA1_PIN, DATA2_PIN, DATA3_PIN, DATA4_PIN};
+const uint8_t latch_pins[DIGITS] = {LATCH0_PIN, LATCH1_PIN, LATCH2_PIN, LATCH3_PIN, LATCH4_PIN, LATCH5_PIN};
+
+volatile uint32_t current_value = 0;
+
+void button_ISR(void);
+void print_7segm(uint32_t val);
+
+void setup()
+{
+ Serial.begin(9600);
+
+ pinMode(NC_PIN, INPUT);
+ srand(analogRead(NC_PIN));
+
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ pinMode(data_pins[i], OUTPUT);
+ digitalWrite(data_pins[i], LOW);
+ }
+ for (uint8_t i = 0; i < DIGITS; i++)
+ {
+ pinMode(latch_pins[i], OUTPUT);
+ digitalWrite(latch_pins[i], HIGH);
+ }
+ pinMode(BUTTON_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), button_ISR, FALLING);
+ pinMode(BLANKING_PIN, OUTPUT);
+ digitalWrite(BLANKING_PIN, HIGH);
+}
+
+void loop()
+{
+ print_7segm(current_value);
+ delay(100);
+}
+
+void button_ISR(void)
+{
+ current_value = rand();
+ current_value |= ((uint32_t) rand() << 16);
+ Serial.print(current_value);
+}
+
+void print_7segm(uint32_t val)
+{
+ uint8_t i, j;
+ uint8_t digit;
+
+ for (i = 0; i < DIGITS; i++)
+ {
+ digit = val % 10;
+ val /= 10;
+
+ for (j = 0; j < 4; j++)
+ {
+ digitalWrite(data_pins[j], digit & (1 << j));
+ }
+ digitalWrite(latch_pins[DIGITS - i - 1], LOW);
+ delay(1);
+ digitalWrite(latch_pins[DIGITS - i - 1], HIGH);
+ delay(1);
+ }
+}
--- /dev/null
+https://www.tinkercad.com/things/3GNvrtWwhQc
--- /dev/null
+https://www.tinkercad.com/things/a091SYpyBV8
--- /dev/null
+https://www.tinkercad.com/things/7eGYywVu5PG
}
// render the image
+ // Note: this was originally made for a couple of younger kids who hadn't learned about switch-case yet
for (i = 0; i < NUM_PIXELS; i++)
{
if (vram[0][i] == EMPTY)
--- /dev/null
+https://www.tinkercad.com/things/0J1F6FpWf9y
--- /dev/null
+https://www.tinkercad.com/things/8ef4pvh4R76
--- /dev/null
+#include <Wire.h>
+
+#define INT_SLAVE1_PIN 3
+#define INT_SLAVE2_PIN 2
+
+#define SLAVE1_ADDRESS 0x09
+#define SLAVE2_ADDRESS 0x0A
+
+size_t i2c_write(uint8_t address, void *data, size_t size);
+size_t i2c_read(uint8_t address, void *data, size_t size);
+void slave1_interrupt(void);
+void slave2_interrupt(void);
+
+volatile bool new_data1 = false;
+volatile bool new_data2 = false;
+
+void setup()
+{
+ Wire.begin();
+ Serial.begin(9600);
+ pinMode(INT_SLAVE1_PIN, INPUT);
+ pinMode(INT_SLAVE2_PIN, INPUT);
+ attachInterrupt(digitalPinToInterrupt(INT_SLAVE1_PIN), slave1_interrupt, RISING);
+ attachInterrupt(digitalPinToInterrupt(INT_SLAVE2_PIN), slave2_interrupt, RISING);
+}
+
+void loop()
+{
+ uint8_t dip_sw;
+
+ if (new_data1)
+ {
+ i2c_read(SLAVE1_ADDRESS, &dip_sw, sizeof(dip_sw));
+ Serial.print("From slave 1: ");
+ Serial.println(dip_sw);
+ new_data1 = false;
+ }
+ if (new_data2)
+ {
+ i2c_read(SLAVE2_ADDRESS, &dip_sw, sizeof(dip_sw));
+ Serial.print("From slave 2: ");
+ Serial.println(dip_sw);
+ new_data2 = false;
+ }
+}
+
+size_t i2c_write(uint8_t address, void *data, size_t size)
+{
+ int error_code;
+ size_t bytes_written;
+
+ Wire.beginTransmission(address);
+ bytes_written = Wire.write((uint8_t *) data, size);
+ error_code = Wire.endTransmission();
+
+ return error_code ? 0: bytes_written;
+}
+
+size_t i2c_read(uint8_t address, void *data, size_t size)
+{
+ size_t bytes_received = Wire.requestFrom(address, size);
+
+ if (bytes_received == size)
+ {
+ for (size_t i = 0; i < size; i++)
+ {
+ ((uint8_t *) data)[i] = Wire.read();
+ }
+ }
+
+ return bytes_received;
+}
+
+void slave1_interrupt(void)
+{
+ new_data1 = true;
+}
+
+void slave2_interrupt(void)
+{
+ new_data2 = true;
+}
\ No newline at end of file
--- /dev/null
+#include <Wire.h>
+
+#define MASTER_INT_PIN A2
+#define INT_PIN 3
+#define SW0_PIN 7
+#define SW1_PIN 6
+#define SW2_PIN 5
+#define SW3_PIN 4
+
+#define SLAVE_ADDRESS 0x09
+
+void i2c_send_handler(void);
+void button_handler(void);
+
+volatile uint8_t dip_sw = 0;
+volatile bool new_data = false;
+
+void setup()
+{
+ pinMode(MASTER_INT_PIN, OUTPUT);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ pinMode(INT_PIN, INPUT_PULLUP);
+ pinMode(SW0_PIN, INPUT_PULLUP);
+ pinMode(SW1_PIN, INPUT_PULLUP);
+ pinMode(SW2_PIN, INPUT_PULLUP);
+ pinMode(SW3_PIN, INPUT_PULLUP);
+
+ attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
+
+ Wire.begin(SLAVE_ADDRESS);
+ Wire.onRequest(i2c_send_handler);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ uint8_t tmp = digitalRead(SW0_PIN) |
+ (digitalRead(SW1_PIN) << 1) |
+ (digitalRead(SW2_PIN) << 2) |
+ (digitalRead(SW3_PIN) << 3);
+ dip_sw = tmp;
+ if (new_data)
+ {
+ new_data = false;
+ digitalWrite(MASTER_INT_PIN, HIGH);
+ delayMicroseconds(5);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ delayMicroseconds(5);
+ }
+}
+
+void i2c_send_handler(void)
+{
+ Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
+}
+
+void button_handler(void)
+{
+ new_data = true;
+}
--- /dev/null
+#include <Wire.h>
+
+#define MASTER_INT_PIN A2
+#define INT_PIN 3
+#define SW0_PIN 7
+#define SW1_PIN 6
+#define SW2_PIN 5
+#define SW3_PIN 4
+
+#define SLAVE_ADDRESS 0x0A
+
+void i2c_send_handler(void);
+void button_handler(void);
+
+volatile uint8_t dip_sw = 0;
+volatile bool new_data = false;
+
+void setup()
+{
+ pinMode(MASTER_INT_PIN, OUTPUT);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ pinMode(INT_PIN, INPUT_PULLUP);
+ pinMode(SW0_PIN, INPUT_PULLUP);
+ pinMode(SW1_PIN, INPUT_PULLUP);
+ pinMode(SW2_PIN, INPUT_PULLUP);
+ pinMode(SW3_PIN, INPUT_PULLUP);
+
+ attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
+
+ Wire.begin(SLAVE_ADDRESS);
+ Wire.onRequest(i2c_send_handler);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ uint8_t tmp = digitalRead(SW0_PIN) |
+ (digitalRead(SW1_PIN) << 1) |
+ (digitalRead(SW2_PIN) << 2) |
+ (digitalRead(SW3_PIN) << 3);
+ dip_sw = tmp;
+ if (new_data)
+ {
+ new_data = false;
+ digitalWrite(MASTER_INT_PIN, HIGH);
+ delayMicroseconds(5);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ delayMicroseconds(5);
+ }
+}
+
+void i2c_send_handler(void)
+{
+ Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
+}
+
+void button_handler(void)
+{
+ new_data = true;
+}
--- /dev/null
+https://www.tinkercad.com/things/78jf9y1YodC
--- /dev/null
+https://www.tinkercad.com/things/bEpoUSShgaZ
--- /dev/null
+https://www.tinkercad.com/things/b5ZB55WFaxX
--- /dev/null
+https://www.tinkercad.com/things/d6absXaO0GD
--- /dev/null
+https://www.tinkercad.com/things/ecuRyTU9AaJ
--- /dev/null
+#include <LiquidCrystal.h>
+#include <string.h>
+
+#define RS 12
+#define EN 11
+#define D4 5
+#define D5 4
+#define D6 3
+#define D7 2
+
+#define COLS 16
+#define ROWS 2
+
+char *text[] =
+{
+ "LOREM IPSUM",
+ "qwertyuiop[",
+ "the quick brown fox jumped over the lazy dog"
+};
+
+LiquidCrystal LCD_screen(RS, EN, D4, D5, D6, D7);
+
+void setup()
+{
+ LCD_screen.begin(COLS, ROWS);
+ LCD_screen.clear();
+}
+
+void loop()
+{
+ uint8_t text_n;
+ int8_t position;
+ uint16_t i, j;
+ uint16_t l;
+ uint16_t print_size;
+
+ // Not necesarily the best implementation, feel free to submit a PR
+ for (text_n = 0; text_n < 3; text_n++)
+ {
+ l = strlen(text[text_n]);
+
+ for (position = COLS - 1; position >= 0; position--)
+ {
+ LCD_screen.setCursor(position, 0);
+ print_size = l;
+ if (print_size > COLS - position)
+ {
+ print_size = COLS - position;
+ }
+ for (i = 0; i < print_size; i++)
+ {
+ LCD_screen.write(text[text_n][i]);
+ }
+ delay(200);
+ LCD_screen.clear();
+ }
+
+ for (j = 0; j < l; j++)
+ {
+ print_size = l - j;
+ if (print_size > COLS)
+ {
+ print_size = COLS;
+ }
+ for (i = 0; i < print_size; i++)
+ {
+ LCD_screen.write(text[text_n][j + i]);
+ }
+ delay(200);
+ LCD_screen.clear();
+ }
+
+ delay(500);
+ }
+}
+
--- /dev/null
+https://www.tinkercad.com/things/des9SoAMtAC
--- /dev/null
+https://www.tinkercad.com/things/4uzv4lu12yT
--- /dev/null
+https://www.tinkercad.com/things/c8JLkjplQKy
--- /dev/null
+https://www.tinkercad.com/things/abCdiMvkJs6
--- /dev/null
+https://www.tinkercad.com/things/b8qUgr1Egv0