Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #define neoPinLeft 16
  4. #define neoPinRight 17
  5. #define togglePinIn 15
  6.  
  7. int brightness = 100;
  8. int leftMax = 36;
  9. int rightMax = 8;
  10. bool toggle = false;
  11. //toggle settings
  12. int reading;
  13. int previous;
  14. long time = 0;
  15. long debounce = 200;
  16. int state = 1;
  17. int numberOfStates = 4;
  18. int colorArray[4];
  19.  
  20. Adafruit_NeoPixel stripLeft = Adafruit_NeoPixel(leftMax, neoPinLeft, NEO_RGB);
  21. Adafruit_NeoPixel stripRight = Adafruit_NeoPixel(rightMax, neoPinRight, NEO_RGB);
  22. uint32_t color = stripLeft.Color(0, 225, 0);
  23. //const int numOfGroups = 5;
  24. //const int globalGroup[numOfGroups];
  25.  
  26.  
  27.  
  28. void setup() {
  29.  
  30. pinMode(togglePinIn, INPUT);
  31. //setting Group ranges
  32. //globalGroup[1] = [startOfGroupOne, endOfGroupOne]
  33.  
  34. stripLeft.begin();
  35. stripLeft.show();
  36.  
  37. stripRight.begin();
  38. stripRight.show();
  39.  
  40. //setting color array
  41. colorArray[0] = stripLeft.Color(225, 0, 0);
  42. colorArray[1] = stripLeft.Color(0, 225, 0);
  43. colorArray[2] = stripLeft.Color(0, 0, 225);
  44. colorArray[3] = stripLeft.Color(0, 0, 0);
  45. }
  46.  
  47. void loop() {
  48.  
  49. checkToggle();
  50. setColor();
  51.  
  52.  
  53. for (int i = 0; i < leftMax; i++) {
  54. stripLeft.setPixelColor(i, color);
  55. }
  56. for (int i = 0; i < rightMax; i++) {
  57. stripRight.setPixelColor(i, color);
  58. }
  59. stripLeft.setBrightness(brightness);
  60. stripRight.setBrightness(brightness);
  61. stripLeft.show();
  62. stripRight.show();
  63. }
  64.  
  65. void checkToggle() {
  66. bool reading = digitalRead(togglePinIn);
  67.  
  68. // Check if state changed from high to low (button press).
  69. if (reading == LOW && previous == HIGH) {
  70. // Short delay to debounce button.
  71. delay(20);
  72. // Check if button is still low after debounce.
  73. reading = digitalRead(togglePinIn);
  74. if (reading == LOW) {
  75. toggle++;
  76. if (toggle > (numberOfStates-1))
  77. toggle=0;
  78. }
  79. }
  80.  
  81. // Set the last button state to the old state.
  82. previous = reading;
  83. /*
  84. reading = digitalRead(togglePinIn);
  85.  
  86. if (previous != reading)
  87. {
  88. time = millis();
  89. }
  90. previous = reading;
  91. //cutout && previous == LOW was (reading == HIGH && previous == LOW && (millis() - time) > debounce)
  92. if (reading == HIGH && (millis() - time) > debounce) {
  93.  
  94. //set neopixle toggle state
  95. if (state > (numberOfStates - 1)) {
  96. toggle = 0;
  97. }
  98. else
  99. {
  100. toggle = toggle + 1 ;
  101. }
  102. }
  103. */
  104. }
  105.  
  106. void setColor() {
  107. color = colorArray[state];
  108. }
  109. /*
  110. void setPixle(group) {
  111. for (int outterGroupCount = 0; outterGroupCount < = numberOfGroups; outterGroupCount++)
  112. {
  113. int currentGroup[] = group[outterGroupCount];
  114. for(int innerGroupCount = currentGroup[1]; innerGroupCount <= currentGroup[2]; innerGroupCount++)
  115. {
  116. strip.setPixelColor(innerGroupCount, color);
  117. if(innerGroupCount < maxLeftStrip)
  118. {
  119. strip2.setPixelColor(innerGroupCount, color);
  120. }
  121. }
  122. }
  123. }
  124. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement