#include #define PIN 7 #define NUMPIXELS 20 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define motorIN1 5 #define motorIN2 6 #define button1 D1 #define button2 D2 int sequenceCount = 0; void setup() { Serial.begin(9600); // NeoPixel strip strip.begin(); setAllPixels(strip.Color(0, 0, 0)); // Turn off all pixels strip.show(); // Motor pinMode(motorIN1, OUTPUT); pinMode(motorIN2, OUTPUT); digitalWrite(motorIN1, LOW); digitalWrite(motorIN2, LOW); // Buttons pinMode(button1, INPUT_PULLUP); pinMode(button2, INPUT_PULLUP); Serial.println("NeoPixels are off."); } void loop() { if (digitalRead(button1) == LOW) { Serial.println("Button 1 pressed: Turning on NeoPixels at full brightness."); turnOnFullBrightness(); } if (digitalRead(button2) == LOW) { Serial.println("Button 2 pressed: Executing sequence."); sequenceCount = 0; while (sequenceCount < 8) { executeSequence(); sequenceCount++; } Serial.println("Sequence execution completed 8 times."); } } void turnOnFullBrightness() { setAllPixels(strip.Color(255 / 2, 255 / 6, 0)); // Full brightness warmer light strip.show(); Serial.println("NeoPixels are at full brightness."); } void executeSequence() { Forward(); Stop(); Reverse(); delay(2000); } void Forward() { Serial.println("Motor spinning forward for 4 seconds. NeoPixels brightening for 4 seconds."); analogWrite(motorIN2, 0); analogWrite(motorIN1, 50); for (int brightness = 0; brightness <= 255; brightness++) { setAllPixels(strip.Color(brightness / 2, brightness / 6, 0)); strip.show(); delay(16); } analogWrite(motorIN1, 0); // Stop motor after brightening Serial.println("Motor stopped after forward spin. NeoPixels are at full brightness."); } void Stop() { Serial.println("Motor stopped for 7 seconds. NeoPixels stay at full brightness."); analogWrite(motorIN2, 0); analogWrite(motorIN1, 0); setAllPixels(strip.Color(255 / 2, 255 / 6, 0)); // Full brightness strip.show(); delay(7000); Serial.println("Stop duration complete. Motor and NeoPixels are in ready state."); } void Reverse() { //Spin motor in reverse for 4 seconds and dim NeoPixels Serial.println("Motor spinning in reverse for 4 seconds. NeoPixels dimming for 8 seconds."); analogWrite(motorIN1, 0); analogWrite(motorIN2, 50); for (int brightness = 255; brightness >= 128; brightness--) { setAllPixels(strip.Color(brightness / 2, brightness / 6, 0)); strip.show(); delay(16); // } analogWrite(motorIN2, 0); // Stop motor after 4 seconds Serial.println("Motor stopped after reverse spin. NeoPixels continue dimming for 4 more seconds."); //Continue dimming NeoPixels for the remaining 4 seconds for (int brightness = 127; brightness >= 0; brightness--) { setAllPixels(strip.Color(brightness / 2, brightness / 6, 0)); strip.show(); delay(31); } Serial.println("NeoPixels dimming complete. Sequence execution finished."); } void setAllPixels(uint32_t color) { for (int i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, color); } }