Created
May 14, 2017 15:34
-
-
Save Ryanhu1015/7d0cf9e3ce1119e8de233be6eab7b614 to your computer and use it in GitHub Desktop.
slave_receive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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