I am trying to work on a switch case using a potentiometer and 4 LED lights. I have been struggling with this project for weeks and I am at my wits end. If anyone has any idea on what I am doing incorrectly please say so. I am attempting to have the potentiometer go through five different cases where different combinations of the lights are active and at certain points; beginning and end they are both off.
const int Red = 11;
const int Blue = 10;
const int Green = 9;
const int Yellow = 5;
const int potpin = A1;
int val; // variable needed to read from Analog Pin 1.
int newvariable = A1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Red, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Blue, OUTPUT);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 1, 4);
Serial.println(val);
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
if(analogRead(potpin); newvariable!=0)
{
newvariable++;}
else if(newvariable>=200 && analogRead(potpin)==HIGH)
{
newvariable == 1;}
else if(newvariable<=275 && analogRead(potpin)==HIGH)
{
newvariable == 2;}
switch (val) {
case 1:
// LED Bulbs light up in order according to value from the potentiometer
// Bulbs light up as listed when variables equal case 1.
val>=5 && val<=34;
digitalWrite(Red, HIGH);
digitalWrite(Blue, LOW);
digitalWrite(Green, HIGH);
digitalWrite(Yellow, LOW);
break;
case 2:
// LED Bulbs light up in order according to value from the potentiometer
// Bulbs light up as listed when variables equal case 2.
val>=35 && val<=68;
digitalWrite(Red, LOW);
digitalWrite(Blue, HIGH);
digitalWrite(Green, LOW);
digitalWrite(Yellow, HIGH);
break;
case 3:
// LED Bulbs light up in order according to value from the potentiometer
// Bulbs light up as listed when variables equal case 3.
val>=69 && val<=102;
digitalWrite(Red, LOW);
digitalWrite(Blue, HIGH);
digitalWrite(Green, HIGH);
digitalWrite(Yellow, LOW);
break;
case 4:
// LED Bulbs light up in order according to value from the potentiometer
// Bulbs light up as listed when variables equal case 4.
val>=103 && val<=136;
digitalWrite(Red, HIGH);
digitalWrite(Blue, LOW);
digitalWrite(Green, LOW);
digitalWrite(Yellow, HIGH);
break;
case 5:
// LED Bulbs light up in order according to value from the potentiometer
// Bulbs light up as listed when variables equal case 5.
val>=137 && val<=170;
digitalWrite(Red, HIGH);
digitalWrite(Blue, HIGH);
digitalWrite(Green, HIGH);
digitalWrite(Yellow, HIGH);
default: // if no condition is met, then LED Lights will revert to being off.
digitalWrite(Red, LOW);
digitalWrite(Blue, LOW);
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
}
}