From last few days i was trying to hookup with Arduino uno as i am building a project which works on ADC and some manual switches.
I put up Two Potentiometer in parallel and connected switches with both of them in series so i can read two different digital value whenever i press either one and process my functionality accordingly.
And i put Three led's to pin 11,12,13.
And one Switch for interruption from current execution at pin 9.
CODE:
//Analog pin
const int analogInPin = A0;
//output pin
const int led1 = 11;
const int led2 = 12;
const int led3 = 13;
//input pin
const int Button = 9;
//variables
int sensorValue=0;
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(Button,INPUT_PULLUP);
}
void loop() {
//read the analog in value:
sensorValue = analogRead(analogInPin);
if(sensorValue>=490 && sensorValue<=510) //This condition should met when i press first button with first potentiometer.
{
digitalWrite(led1,1); //led1 will glow
digitalWrite(led2,0); //led2 will be off
digitalWrite(led3,1); //led3 will glow
}
if(sensorValue>=790 && sensorValue<=810) //This condition should met when i press second button with second potentiometer.
{
digitalWrite(led1,0); //led1 will be off
digitalWrite(led2,1); //led2 will glow
digitalWrite(led3,1); //led3 will glow
}
delay(2);
}
Everything is working fine in this code but i needed to include that Button pin to this code so that whenever i presses that Button, only status of led3 got change and status of both of the led's should remain same.
//Analog pin
const int analogInPin = A0;
//output pin
const int led1 = 11;
const int led2 = 12;
const int led3 = 13;
//input pin
const int Button = 9;
//variables
int sensorValue=0;
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(Button,INPUT_PULLUP);
}
void loop() {
//read the analog in value:
sensorValue = analogRead(analogInPin);
if(sensorValue>=490 && sensorValue<=510) //This condition should met when i press first button with first potentiometer.
{
digitalWrite(led1,1); //led1 will glow
digitalWrite(led2,0); //led2 will be off
digitalWrite(led3,1); //led3 will glow
}
if(sensorValue>=790 && sensorValue<=810) //This condition should met when i press second button with second potentiometer.
{
digitalWrite(led1,0); //led1 will be off
digitalWrite(led2,1); //led2 will glow
digitalWrite(led3,1); //led3 will glow
}
if(digitalRead(Button)==0)
{
digitalWrite(led3,0); //status of led3 should change only and status of both of above led's should remain same
}
delay(2);
}
Here If(Button==0) is the condition when button is actually pressed and i need it to work like changing the status of led3 only without altering the status of led1 and led2
I am putting my every effort to make it right but getting unsuccessful in doing so, Any Help is appreciated Thanks..