/* Written by: Zuzanna Last update: 1st March 2024. This file contains code for Rewise GFG Steelworks Retrofit - Steel Shop 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 Ring - Arduino Uno GND -> GND 5V -> 5V DIN -> Pin 6 -------------------------- Button - Arduino Uno + -> Pin 8 - -> GND If you want to change the colours for LED ring, change the add function at the bottom with RGB values. */ //------------------ LIBRARIES ------------------ #include #include #ifdef __AVR__ #include #endif //------------------ VARIABLES ------------------ #define N_PIXELS 24 // Number of pixels in strip #define LED_PIN 6 // NeoPixel LED strip is connected to this pin int fullBrightness = 100; // Change the value here to control the brightness (0 to 255). 0 turns it off, 255 is the brightest option. int paletteThreshold = 1500; const unsigned int button = 8; //Stop button //------------------ CREATING INSTANCES ------------------ Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800); //------------------------ VOID SETUP()------------------------ void setup() { // put your setup code here, to run once: delay(3000); // power-up safety delay pinMode(button, INPUT_PULLUP); strip.setBrightness(fullBrightness); // setting brightness level of LED ring strip.begin(); // initializing neopixel strip strip.show(); // Turns leds pixel by pixel on to pink for (int i = 0; i < N_PIXELS; i++) { strip.setPixelColor(i, strip.Color(255, i * 2, 30)); delay(20); strip.show(); } // Turns off all Neopixel LEDs strip.clear(); } //------------------------ VOID LOOP()------------------------ void loop() { // put your main code here, to run repeatedly: if (!digitalRead(button)) // if button is pressed { delay(10); if (!digitalRead(button)) { // if button is pressed rainbowCycle(3); // display light on LED ring. Change the value to make it faster (lower value) or slower (higher value) } } else { strip.clear(); } strip.show(); delay(10); } //------------------------ Functions ------------------------ /* 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 * 5; 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)); // Chnage "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 }