Have an issue with getting the led light strip to turn on properly when pressure applied to strip potentiometer. Basically the lights flicker heaps and don’t always stay on properly. Any assistance would be appreciated.
const int SENSOR_A = A0;
const int SENSOR_B = A5;
const int BUTTON = 8;
int prevPressureA = 0;
int prevPressureB = 0;
int pressureValueA;
int pressureValueB;
const int RED_PIN = 6;
const int GREEN_PIN = 5;
const int BLUE_PIN = 3;
//0 = FALSE
int RANDOM = 1;
int OFF = 0;
void setup() {
//defining the whether a pin is an input or output
pinMode(BUTTON, INPUT);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
//changing the colour
//RGB_light(255, 0, 0), shortcut
void RGB_light(int red, int green, int blue) {
if (OFF == 1) {
red, green, blue = 0;
} else if (RANDOM == 1) {
red = random(200);
green = random(200);
blue = random(200);
}
analogWrite(RED_PIN, red);
analogWrite(BLUE_PIN, blue);
analogWrite(GREEN_PIN, green);
}
void colours(int colourCode) {
}
void loop() {
//reading the the sensor values right now
pressureValueA = analogRead(SENSOR_A);
pressureValueB = analogRead(SENSOR_B);
//checking if previous pressure is more than current pressure
if (prevPressureA < pressureValueA or prevPressureB < pressureValueB) {
RGB_light(255, 100, 0);
}
//resetting the light with the button
if (digitalRead(BUTTON) == HIGH) {
OFF = 1;
RGB_light(0, 0, 0);
OFF = 0;
}
//for the next loop, the current pressure becomes the old pressure
prevPressureA = pressureValueA;
prevPressureB = pressureValueB;
}