Hello All,
I am very new to this, and I am trying my best to post this question appropriately given that another user was kind of rude when I didn’t properly format my post.
Anyhow, here’s the problem. I have a 5 LED set up. I have five different scenarios in the code. When I enter a number between 1 and 100, I want them to light up based on how close to 100 I am. For instance, when I enter 60, I want three LEDs to light up…at 80…four will light up.
The code I wrote is accepted by the Arudino. When I press 1…1 LED lights up. If I press 0…all go dim. However, when I enter any number higher than 1, nothing else happens. I took a look at my serial data. When I enter the number 0, I see that the number 48 appears on the serial data screen. If I press 1, it shows up as 49…and so on and so forth between numbers 1 through 10.
Any help? Here is my code:
const int ledPin1 = 9;
const int ledPin2 = 10;
const int ledPin3 = 11;
const int ledPin4 = 12;
const int ledPin5 = 13;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
int value = 0;
}
void loop()
{
int value;
if(Serial.available())
{
delay(50);
while(Serial.available() >0)
{
value=Serial.read();
Serial.println(value, DEC);
if(value<='99' && value>='80'){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,HIGH);
digitalWrite(9,HIGH);
}
else if(value<='79' && value>='60'){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
}
else if(value<='59' && value>='40'){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
else if(value<='39' && value>='20'){
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
else if(value<='19' && value>='1'){
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
else {
digitalWrite(13, LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
}
}
}