// Forum: https://forum.arduino.cc/t/arduino-should-act-as-a-push-button-when-the-loop-is-done/1180814
// This Wokwi project: https://wokwi.com/projects/379276550865486849
#include <FastLED_NeoPixel.h>
#define MAX_P 122
CRGB leds[MAX_P];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(MAX_P, 3, NEO_BRG + NEO_KHZ800);
int potPin0 = 0; // select the input pin for the potentiometer
int potPin1 = 1; // select the input pin for the potentiometer
int val0 = 0; // variable to store the value coming from the sensor
int val1 = 0; // variable to store the value coming from the sensor
int li=0;
int direction=+1;
uint32_t Red=strip.Color(255, 0, 0);
uint32_t Blank=strip.Color(0, 0, 0);
void setup() {
FastLED.addLeds<NEOPIXEL, 3>(leds, MAX_P);
FastLED.setBrightness(255);
FastLED.clear ();
fadeAnimation(0, 255, 0);
delay(500);
strip.begin();
strip.show();
}
void loop() {
val0 = analogRead(potPin0) / 50; // read the value from the sensor
val1 = analogRead(potPin1) / 34.1; // read the value from the sensor
//decay
for(uint16_t i=0; i<MAX_P; i++) {
uint8_t r= (strip.getPixelColor(i)>>16) & 0xff;
r=(r*(69+val1))/100;
strip.setPixelColor(i, r, 0, 0);
}
strip.setPixelColor(li, Red);
if(li>(MAX_P-1)){
li=MAX_P;
direction=-1;
}else if(li<0){
li=-1;
direction=1;
}
li+=direction;
strip.show();
delay(val0);
}
void fadeAnimation(int red, int green, int blue){
float r, g, b;
// FADE OUT
for(int i = 255; i >= 0; i--) {
r = (i/256.0)*red;
g = (i/256.0)*green;
b = (i/256.0)*blue;
fill_solid(leds, MAX_P, CRGB(r, g, b));
FastLED.show();
delay(8);
}
}