Forked from jbobrow/Blinks Send and Receive Test
Last active
September 1, 2017 18:22
-
-
Save bigjosh/4d3ad37169dd31d04936b52b78532696 to your computer and use it in GitHub Desktop.
Quick test for latest Arduino based Blinks API
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
/* Blinks Send/Receive (Test) | |
* | |
* -------------------------------------------------------------------------------------------------- | |
* IMPORTANT: To use this code in Arduino's IDE, first move the Move38-Blinks folder | |
* into the right directory i.e. <user home directory>/Documents/Arduino/hardware/Move38-Blinks | |
* Then open the Arduino IDE and select Tools > Board > "Move38-Blinks" | |
* Now you should be good to go :) (thanks to the hard work of Josh Levine – josh.com) | |
* -------------------------------------------------------------------------------------------------- | |
* | |
* by Jonathan Bobrow | |
* www.Move38.com | |
* 08.29.2017 | |
*/ | |
uint8_t colors[4][3] = {{255,0,0}, // Red | |
{0,255,0}, // Green | |
{0,0,255}, // Blue | |
{255,255,0}}; // Yellow | |
int isSending = 0; // 0 for receive mode, 1,2,3 for receive mode | |
int neighbors[6] = {0,0,0,0,0,0}; | |
void setup() { | |
// put your setup code here, to run once: | |
// animate red circle to show reset or startup | |
for(int i=0; i<FACE_COUNT; i++) { | |
setPixelRGB(i,200,0,0); | |
delay(100); | |
setAllRGB(0,0,0); // Show pixels one at a time, and leave display clear when circle finished | |
} | |
} | |
void loop() { | |
// switch through 4 modes ( 0 = receive, 1,2,3 = sending 1,2,or 3 ) | |
if(buttonPressed()) { | |
isSending = (isSending + 1) % 4; | |
} | |
if(isSending) { | |
// get neighbor states | |
for(int i=0; i<FACE_COUNT; i++) { | |
// send value 1,2, or 3 on every face depending on our state | |
irSendDibit(i,isSending); | |
// show which value is being sent by diplaying color | |
setPixelRGB( | |
i, | |
colors[isSending][0], | |
colors[isSending][1], | |
colors[isSending][2] | |
); | |
} | |
} | |
else { | |
// receiving | |
// set all sides to dark | |
// setAllRGB(0,0,0); | |
// get neighbor states | |
for(int i=0; i<FACE_COUNT; i++) { | |
// check if IR message is available | |
if(irIsAvailable(i)) { | |
// get value read on face | |
int val = irReadDibit(i); | |
// save value read on face... not in use | |
neighbors[i] = val; | |
// set side to the color of the received information | |
setPixelRGB( i, | |
colors[val][0], | |
colors[val][1], | |
colors[val][2]); | |
} | |
} | |
delay(100); // Let the displayed color stay on long enough for at least one frame so actually visible. | |
setAllRGB( 0 , 0 , 0 ); // Clear display for next round! | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment