Skip to content

Instantly share code, notes, and snippets.

@Ryanhu1015
Created May 14, 2017 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ryanhu1015/7d0cf9e3ce1119e8de233be6eab7b614 to your computer and use it in GitHub Desktop.
Save Ryanhu1015/7d0cf9e3ce1119e8de233be6eab7b614 to your computer and use it in GitHub Desktop.
slave_receive
byte received[8][8]; //build an empty array to store the byte received from master
void setup() {
Serial.begin(57600);
Serial.println("test");
Wire.begin(0x09);
Wire.onReceive(receiveEvent);// this function will be triggered whenever something received
}
void loop()
{
received[3][2] = fromMaster; // just use [3][2] this location to test if i get the correct thing
for (byte x = 0; x < 8; x++)
{
for (byte y = 0; y < 8; y++)
{
PixelRGB *p = Colorduino.GetPixel(x, y);
p->r = received[x][y];
}
}
Colorduino.FlipPage();
}
byte fromMaster;
void receiveEvent(int howMany)
{
while (1 < Wire.available()) { // loop through all but the last
char x = Wire.read(); // receive byte as a character
Serial.print(x);// print the character
}
fromMaster = Wire.read(); // receive byte as an integer
Serial.println(fromMaster);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment