/* Written by: Zuzanna Last update: 1st March 2024. This file contains code for Rewise GFG Steelworks Retrofit - Blast Furnace Sector. Lookout for line with star symbol or // - these are comments that are here to guide you through the code. -------------------------- These are wiring instructions (sensor -> arduino) -------------------------- LED Strip - Arduino Nano GND -> GND 5V -> 5V DIN -> Pin 6 -------------------------- Button - Arduino Nano + -> Pin 8 - -> GND -------------------------- Red LED - Arduino Nano + -> Pin 5 - -> GND */ //------------------ LIBRARIES ------------------ #include //------------------ VARIABLES ------------------ #define button_pin 8 #define led_pin 5 #define RGB_pin 6 #define BRIGHTNESS 50 #define NUMPIXELS 15 // Number of pixel in RGB strip int led_on_time = 5; // time for led to stay ON in seconds int led_off_time =15; // time for led to stay OFF in seconds int RGB_ON_TIME= 50; // total transition time from red to orange to yellow and yellow to orange to red int paletteThreshold = 1500; //------------------ CREATING INSTANCES ------------------ Adafruit_NeoPixel strip(NUMPIXELS, RGB_pin, NEO_GRB + NEO_KHZ800); unsigned long off_time, on_time; bool RGB_ON = false; //------------------------ VOID SETUP()------------------------ void setup() { Serial.begin(9600); strip.begin(); pinMode(button_pin, INPUT_PULLUP); pinMode(led_pin, OUTPUT); strip.setBrightness(BRIGHTNESS); // Set the brightness of the LED strip digitalWrite(led_pin,LOW); off_time = millis(); strip.clear(); } //------------------------ VOID LOOP()------------------------ void loop() { if (millis()- off_time > (led_off_time * 1000) && !RGB_ON) { off_time = millis(); on_time = millis(); digitalWrite(led_pin, HIGH); RGB_ON = true; Serial.println("LED ON"); } if (millis()- on_time > (led_on_time * 1000) && RGB_ON) { off_time = millis(); on_time = millis(); digitalWrite(led_pin, LOW); RGB_ON = false; Serial.println("LED OFF"); } if (digitalRead(button_pin) == LOW && RGB_ON == true) { //colorTransition(255, 0, 0, 255, 255, 0); //colorTransition(255, 255, 0, 255, 0, 0); rainbowCycle(3); } else { strip.clear(); strip.show(); } } //------------------------ Functions ------------------------ void colorTransition(int startR, int startG, int startB, int endR, int endG, int endB) { int steps = 100; // Number of steps in the transition for (int i = 0; i <= steps; i++) { int r = map(i, 0, steps, startR, endR); int g = map(i, 0, steps, startG, endG); int b = map(i, 0, steps, startB, endB); colorWipe(strip.Color(r, g, b)); delay((RGB_ON_TIME * 10) / 2); } } void colorWipe(uint32_t color) { for (int i = 0; i < NUMPIXELS; i++) { strip.setPixelColor(i, color); strip.show(); } } /* Function "rainbowCycle" is responsible for filling with colour all the pixels in the strip*/ void rainbowCycle(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256 * 10; j++) { // 5 cycles of all colors on wheel for (i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Sunset(((i * 256 / strip.numPixels()) + j) & 255)); // Chanage "Sunset" to different colour scheme if you wish to have different colours } strip.show(); //Show the light delay(wait); // Wait } } /* Function "Wheel" is responsible for setting colours on the LED ring*/ uint32_t Wheel(byte WheelPos) { if (WheelPos < 85) { return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if (WheelPos < 170) { WheelPos -= 85; return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } } /* Function "Sunset" is responsible for setting red/ orange/ yellow colours on the LED ring*/ uint32_t Sunset(unsigned int i) { paletteThreshold = 1019; if (i > 1019) return Sunset(i % 1020); if (i > 764) return strip.Color((i % 255), 0, 255 - (i % 255)); //blue -> red if (i > 509) return strip.Color(255 - (i % 255), 0, 255); //purple -> blue if (i > 255) return strip.Color(255, 128 - (i % 255) / 2, (i % 255)); //orange -> purple return strip.Color(255, i / 2, 0); //red -> orange }