Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #define neoPinLeft 16
- #define neoPinRight 17
- #define togglePinIn 15
- int brightness = 100;
- int leftMax = 36;
- int rightMax = 8;
- bool toggle = false;
- //toggle settings
- int reading;
- int previous;
- long time = 0;
- long debounce = 200;
- int state = 1;
- int numberOfStates = 4;
- int colorArray[4];
- Adafruit_NeoPixel stripLeft = Adafruit_NeoPixel(leftMax, neoPinLeft, NEO_RGB);
- Adafruit_NeoPixel stripRight = Adafruit_NeoPixel(rightMax, neoPinRight, NEO_RGB);
- uint32_t color = stripLeft.Color(0, 225, 0);
- //const int numOfGroups = 5;
- //const int globalGroup[numOfGroups];
- void setup() {
- pinMode(togglePinIn, INPUT);
- //setting Group ranges
- //globalGroup[1] = [startOfGroupOne, endOfGroupOne]
- stripLeft.begin();
- stripLeft.show();
- stripRight.begin();
- stripRight.show();
- //setting color array
- colorArray[0] = stripLeft.Color(225, 0, 0);
- colorArray[1] = stripLeft.Color(0, 225, 0);
- colorArray[2] = stripLeft.Color(0, 0, 225);
- colorArray[3] = stripLeft.Color(0, 0, 0);
- }
- void loop() {
- checkToggle();
- setColor();
- for (int i = 0; i < leftMax; i++) {
- stripLeft.setPixelColor(i, color);
- }
- for (int i = 0; i < rightMax; i++) {
- stripRight.setPixelColor(i, color);
- }
- stripLeft.setBrightness(brightness);
- stripRight.setBrightness(brightness);
- stripLeft.show();
- stripRight.show();
- }
- void checkToggle() {
- bool reading = digitalRead(togglePinIn);
- // Check if state changed from high to low (button press).
- if (reading == LOW && previous == HIGH) {
- // Short delay to debounce button.
- delay(20);
- // Check if button is still low after debounce.
- reading = digitalRead(togglePinIn);
- if (reading == LOW) {
- toggle++;
- if (toggle > (numberOfStates-1))
- toggle=0;
- }
- }
- // Set the last button state to the old state.
- previous = reading;
- /*
- reading = digitalRead(togglePinIn);
- if (previous != reading)
- {
- time = millis();
- }
- previous = reading;
- //cutout && previous == LOW was (reading == HIGH && previous == LOW && (millis() - time) > debounce)
- if (reading == HIGH && (millis() - time) > debounce) {
- //set neopixle toggle state
- if (state > (numberOfStates - 1)) {
- toggle = 0;
- }
- else
- {
- toggle = toggle + 1 ;
- }
- }
- */
- }
- void setColor() {
- color = colorArray[state];
- }
- /*
- void setPixle(group) {
- for (int outterGroupCount = 0; outterGroupCount < = numberOfGroups; outterGroupCount++)
- {
- int currentGroup[] = group[outterGroupCount];
- for(int innerGroupCount = currentGroup[1]; innerGroupCount <= currentGroup[2]; innerGroupCount++)
- {
- strip.setPixelColor(innerGroupCount, color);
- if(innerGroupCount < maxLeftStrip)
- {
- strip2.setPixelColor(innerGroupCount, color);
- }
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement