#include #define LED_PIN 9 #define NUM_LEDS 7 #define CLBUTTON 10 Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); int colourchoice = 0; int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button int startPressed = 0; // the moment the button was pressed int endPressed = 0; // the moment the button was released int holdTime = 0; // how long the button was hold int idleTime = 0; // how long the button was idle int currentcolour = 0; int lastcolour = 0; /////////// pot stuff int analogValue; int brightness; // Define the number of samples to keep track of. The higher the number, the // more the readings will be smoothed, but the slower the output will respond to // the input. Using a constant rather than a normal variable lets us use this // value to determine the size of the readings array. const int numReadings = 10; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average void setup() { // put your setup code here, to run once: pinMode(CLBUTTON, INPUT_PULLUP); pixels.begin(); for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } } void loop() { buttonState = digitalRead(CLBUTTON); analogValue = analogRead(A0); // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogValue; // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; } // calculate the average: average = total / numReadings; brightness = map(analogValue, 0, 1023, 0, 255); switch (colourchoice) { case 0: setcolour(0,0,0); break; case 1: setcolour(255,255,255); break; case 2: setcolour(255, 25, 255); break; case 3: setcolour(255,0,0); break; case 4: setcolour(0,255,0); break; case 5: setcolour(0,0,255); break; case 6: setcolour(255,255,0); break; case 7: setcolour(0,255,255); break; case 8: fire(); break; } if (buttonState != lastButtonState) { updateState(); if(buttonState == LOW){ changecolour(); } lastButtonState = buttonState; delay(150); } else { updateCounter(); } delay(50); } void fire() { int r = 226, g = 121, b = 35; delay(150); do { analogValue = analogRead(A0); brightness = map(analogValue, 0, 1023, 0, 255); for(int i=0; i= 3000) { colourchoice = 0; pixels.setBrightness(0); pixels.show(); } } }