// Using Adafruit NeoPixel strip for cold box // Potentiometer for brightness control // //LED Strip: https://learn.adafruit.com/adafruit-neopixel-uberguide/the-magic-of-neopixels?view=all //Button: https://docs.arduino.cc/built-in-examples/digital/Button //Potentiometer: https://docs.arduino.cc/learn/electronics/potentiometer-basics/ // // // Libraries #include // Custon Functions #define ARRAY_SIZE(array) ((sizeof(array))/(sizeof(array[0]))) //Pins #define LED_PIN 6 // pin for LED control signal //#define LED_COUNT 120 // number of LEDs #define LED_COUNT 240 // number of LEDs #define POT_PIN A0 //pin for potentiometer input #define BUTTON_PIN 2 //input pin for button // Global Variables int potVal = -100; //potentiometer value int lastPotVal = 0; //last potentiometer value to prevent continuous overwriting int colourIndex = 0; //colour index value int lastColourIndex = 0; //last colour index value to prevent continous overwriting int buttonState = 0; //button state (HIGH or LOW) const int delayValue = 50; //delay for looping in ms //Initialize LED strip Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // Initialising Code void setup() { // put your setup code here, to run once: Serial.begin(9600); //initialise serial monitor Serial.println("==============================="); //start of code pinMode(LED_PIN, OUTPUT); //pin mode pinMode(POT_PIN, INPUT); //pin mode pinMode(BUTTON_PIN, INPUT); //pin mode strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Turn OFF all pixels ASAP //strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) strip.setBrightness(250); } //Continuours code void loop() { // put your main code here, to run repeatedly: potVal = analogRead(POT_PIN); //read potentiometer buttonState = digitalRead(BUTTON_PIN); //read button //Serial.print("Potentiometer value: "); //Serial.println(potVal); //Serial.print("Button Stage: "); //Serial.println(buttonState); float bright = 255*((float(potVal)+1)/1024); //Serial.print("Brighness Value: "); //Serial.print(bright); //Serial.print("\t Int: "); //Serial.println(int(bright)); // LED Colours set for brightness uint32_t white = strip.Color(int(bright),int(bright),int(bright)); //set color uint32_t yellow = strip.Color(int(bright),int(bright), int(0)); //set color uint32_t blue = strip.Color(int(0),int(0),int(bright)); //set color uint32_t lime = strip.Color(int(0),int(bright),int(0)); //set color uint32_t red = strip.Color(int(bright),int(0),int(0)); //set color //array with colours for looping uint32_t colourList[] = {white, yellow, blue, lime, red}; if (buttonState == HIGH){ colourIndex ++; if (colourIndex > ARRAY_SIZE(colourList)) {colourIndex = 0;} delay(500); //wait 1 s to allow button to unpress } //Serial.print("Colour Index: "); //Serial.print(colourIndex); //Serial.print("\tLast Colour Index: "); //Serial.println(lastColourIndex); //only do colour change if input changed if (lastColourIndex != colourIndex){ strip.fill(colourList[colourIndex]); strip.show(); lastColourIndex = colourIndex; Serial.println("Colour Change"); } //only do brighness change if input changed if ( abs(lastPotVal-potVal) >5){ strip.fill(colourList[colourIndex]); strip.show(); lastPotVal = potVal; Serial.println("Brighness Change"); } delay(delayValue); //1s delay between loops }