Created
August 31, 2017 05:55
-
-
Save jbobrow/22363b36651caee631db213d8551dee6 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 | |
*/ | |
int 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++) { | |
setAllRGB(0,0,0); | |
setPixelRGB(i,200,0,0); | |
delay(100); | |
} | |
} | |
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 | |
setAllRGB(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 = irOverFlowFlag(i); | |
// save value read on face... not in use | |
neighbors[i] = val; | |
// set each side to the color of the received information | |
setPixelRGB( i, | |
colors[val][0], | |
colors[val][1], | |
colors[val][2]); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still some flakiness but this should work..,
https://gist.github.com/bigjosh/4d3ad37169dd31d04936b52b78532696/revisions
You need to pull this commit which fixes a bug that made all values returned from
iRreadDibit()
have bit 4 set....bigjosh/Move38-Arduino-Platform@ac8ebbe
Also, seems like I need to cycle the sendstate once though to get receive to work. Hmm...
I am also seeing occasional wrong color pop up in receive state. Hmmm...
Need to track both these down.