Here I go again Well i wanted to give my running light some sound , and so i wanted to try to use Pin 8 as a push button but I can't get it to work.
I tried delay (); but that affects the whole code and speed of the light, so I tried "blink with millis" but that doesn't work either. I found out that the button has to be pressed about 30ms to get registered by the soundboard.
It should work like this , when the loop begins, the "button" should be pressed 30-50ms then released. (The Soundboard playes the rest of the sound automatically) When the loop is done and begins again the switch should be pressed again for 30-50ms
The Original Code is
#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(255, 0, 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);
}
}