Yes, your code has to be modified.
I modified the code, Kindly check it out, it isn't working
int ledPin = 13;
int inPin1 = 2;
int inPin2 = 7;
int val1 = 0;
int val2 = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inPin1, INPUT_PULLUP);
pinMode(inPin2, INPUT_PULLUP);
digitalWrite(ledPin, LOW);
}
void loop() {
val1 = digitalRead(inPin1);
val2 = digitalRead(inPin2);
if( val1 == LOW )
{
digitalWrite(ledPin, HIGH);
}
else if( val2 == LOW )
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
So what does it do ?
The LED stays on all the time
Either check you've connected to the right pins of the button switches, using a meter, or simply connect to opposite corners which always works.
Having checked the buttons each work as intended, then check your code does what'd expected.
BTW XOR is easy to code:
if (digitalRead(inPin1) != digitalRead (inPin2)) // xor means "different".
digitalWrite (ledPin, HIGH) ;
else
digitalWrite (ledPin, LOW) ;
... or you can use the C++ XOR operator:
void loop() {
digitalWrite( ledPin, digitalRead(inPin1) xor digitalRead(inPin1) );
}
what about
void loop () {
digitalWrite (ledPin, digitalRead (inPin1);
}
then try inPin2
Computer says "no".
corrected
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.