Rainbowduino Code

Back to Blog post
#include <Rainbowduino.h>
#include <Wire.h>

char x[50];

void setup(){
  
  Wire.begin(9);                // Start I2C Bus as a Slave (Device Number 9), change for every rainbowduino
  Wire.onReceive(receiveEvent); // register event  
  Serial.begin(9600);
  Serial.println("Starting");
  Rb.init();
  Rb.drawChar('S',0,1,random(0xFFFFFF));  
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 
  x[0] = '9';
  x[1] = 0;
    
}

void loop()
{
     for (int j = 0; j < strlen(x); j++)
     {
       Rb.blankDisplay();
       Rb.drawChar(x[j],0,1,random(0xFFFFFF)); 
       delay(200);
     }
  delay(250);
  

}

void receiveEvent(int howMany) {
  Serial.println(".");
  int i = 0;
  
//  x = Wire.read();
  
  while(Wire.available())    // slave may send less than requested
  {
    x[i] = Wire.read();    // receive a byte as character
    Serial.print(x[i]);         // print the character

    i++;
  }

  x[i] = 0;
}

Back to Blog post

No comments:

Post a Comment