/* Daisy Chain Number Blocks ** ** 2020-December Maddie Pelz mpelz@mit.edu ** Code based on example from Scott Lawrence ** ** When activated, the first block in the row will show 1, and then increment and send a higher number to the next block (showing that number on an oled) ** ** Host--->RX(device 0)TX--->RX(device 1)TX--->RX(device 2)TX---> Etc */ #include #include #include #define OLED_RESET -1 Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET); void setup() { // initialize serial: Serial.begin(9600); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); //for Clearing the display display.setTextSize(5); display.setTextColor(WHITE); display.setCursor(0, 0); display.println("Hello"); display.display(); delay(3000); } void loop() { display.clearDisplay(); int ch, digit, next_digit; // wait for something to come in if( Serial.available() == 0 ) return; // read in a character. ch = Serial.read(); if( ch >= '1' && ch <= '3' ) { digit = ch - '0'; display.setTextSize(5); display.setTextColor(WHITE); display.setCursor(0, 0); display.println(digit); display.display(); next_digit = (digit + 1); //send digit to oled and then digit plus 1 on to next arduino (or serial output for testing) Serial.print(next_digit) + '0'; } }