Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. /* Blinks Send/Receive (Test)
  2. *
  3. * --------------------------------------------------------------------------------------------------
  4. * IMPORTANT: To use this code in Arduino's IDE, first move the Move38-Blinks folder
  5. * into the right directory i.e. <user home directory>/Documents/Arduino/hardware/Move38-Blinks
  6. * Then open the Arduino IDE and select Tools > Board > "Move38-Blinks"
  7. * Now you should be good to go :) (thanks to the hard work of Josh Levine – josh.com)
  8. * --------------------------------------------------------------------------------------------------
  9. *
  10. * by Jonathan Bobrow
  11. * www.Move38.com
  12. * 08.29.2017
  13. */
  14.  
  15. int colors[4][3] = {{255,0,0}, // Red
  16. {0,255,0}, // Green
  17. {0,0,255}, // Blue
  18. {255,255,0}}; // Yellow
  19.  
  20.  
  21. int isSending = 0; // 0 for receive mode, 1,2,3 for receive mode
  22.  
  23. int neighbors[6] = {0,0,0,0,0,0};
  24.  
  25. void setup() {
  26. // put your setup code here, to run once:
  27.  
  28. // animate red circle to show reset or startup
  29. for(int i=0; i<FACE_COUNT; i++) {
  30. setAllRGB(0,0,0);
  31. setPixelRGB(i,200,0,0);
  32. delay(100);
  33. }
  34. }
  35.  
  36. void loop() {
  37.  
  38. // switch through 4 modes ( 0 = receive, 1,2,3 = sending 1,2,or 3 )
  39. if(buttonPressed()) {
  40. isSending = (isSending + 1) % 4;
  41. }
  42.  
  43. if(isSending) {
  44.  
  45. // get neighbor states
  46. for(int i=0; i<FACE_COUNT; i++) {
  47.  
  48. // send value 1,2, or 3 on every face depending on our state
  49. irSendDibit(i,isSending);
  50.  
  51. // show which value is being sent by diplaying color
  52. setAllRGB(colors[isSending][0],
  53. colors[isSending][1],
  54. colors[isSending][2]);
  55. }
  56.  
  57. }
  58. else {
  59. // receiving
  60.  
  61. // set all sides to dark
  62. setAllRGB(0,0,0);
  63.  
  64. // get neighbor states
  65. for(int i=0; i<FACE_COUNT; i++) {
  66.  
  67. // check if IR message is available
  68. if(irIsAvailable(i)) {
  69.  
  70. // get value read on face
  71. int val = irOverFlowFlag(i);
  72.  
  73. // save value read on face... not in use
  74. neighbors[i] = val;
  75.  
  76. // set each side to the color of the received information
  77. setPixelRGB( i,
  78. colors[val][0],
  79. colors[val][1],
  80. colors[val][2]);
  81. }
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement