Hi all,
Thanks to AAC, I decided to buy an Arduino, Mega2560. I've been playing with it couple of days now and trying to learn basics. Now that I started to write my own codes, rather than uploading examples and observe, I came across a situation, where I have no idea why the Arduino acts this way.
On the breadboard, I have 3 LEDs, 3 current limiting resistances (1k each) and a potentiometer. I adjust the brigthness of the yellow RED according to the analog value being read from pot. Using an 'if' statement, I want green LED to be lit when the analog value from the pot is less than '127'. And when the value is above '127', I want the red LED to be lit.
int potValue=0;
int outValue=0;
int highValue=0;
int lowValue=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
potValue=analogRead(A0);
outValue=map(potValue, 0, 1023, 0, 255);
analogWrite(11,outValue);
if(outValue<127){
analogWrite(10,0);
analogWrite(12,255);
lowValue=analogRead(12);
delay(100);
}
else
analogWrite(12,0);
analogWrite(10,255);
highValue=analogRead(10);
delay(100);
Serial.print(outValue);
Serial.print("\t");
Serial.print(highValue);
Serial.print("\t");
Serial.println(lowValue);
}
When I upload this code, the yellow LED lights according to the analog value from the pot. When the analog value is above '127', red LED lights as well, however, when the analog value is below '127', green LED lights and red LED blinks continuously. And this is where my confusion begins.
Any help?
Edit: All sorted out guys, thanks anyways.
Thanks to AAC, I decided to buy an Arduino, Mega2560. I've been playing with it couple of days now and trying to learn basics. Now that I started to write my own codes, rather than uploading examples and observe, I came across a situation, where I have no idea why the Arduino acts this way.
On the breadboard, I have 3 LEDs, 3 current limiting resistances (1k each) and a potentiometer. I adjust the brigthness of the yellow RED according to the analog value being read from pot. Using an 'if' statement, I want green LED to be lit when the analog value from the pot is less than '127'. And when the value is above '127', I want the red LED to be lit.
int potValue=0;
int outValue=0;
int highValue=0;
int lowValue=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
potValue=analogRead(A0);
outValue=map(potValue, 0, 1023, 0, 255);
analogWrite(11,outValue);
if(outValue<127){
analogWrite(10,0);
analogWrite(12,255);
lowValue=analogRead(12);
delay(100);
}
else
analogWrite(12,0);
analogWrite(10,255);
highValue=analogRead(10);
delay(100);
Serial.print(outValue);
Serial.print("\t");
Serial.print(highValue);
Serial.print("\t");
Serial.println(lowValue);
}
When I upload this code, the yellow LED lights according to the analog value from the pot. When the analog value is above '127', red LED lights as well, however, when the analog value is below '127', green LED lights and red LED blinks continuously. And this is where my confusion begins.
Any help?
Edit: All sorted out guys, thanks anyways.
Last edited: