Hi,
I purchased a " Grove - Dual Button" but cant get the 2nd button working.
Here is my hardware setup:
- Arduino MKR GSM 1400
- Arduino MKR Connector Carrier (Grove compatible)
- Grove - White LED
- Grove - Dual Button
I conntected the external “Grove - White LED” to D3 and " Grove - Dual Button" to D1. The build-in LED of the Arduino MKR GSM 1400 is on D6.
I want to control with each button of the module one LED, but currently only the button labeled “1” turns on an LED. I tested the assignment of the LEDs with other sketches and they work.
Please advise.
Here is my sketch:
int button1 = 1; //set the button1 pin
int button2 = 2; //set the button2 pin
int LED = 6; //set the LED pin
int LEDex = 3; //set the LED pin
bool state1 = 1; //set button1 state
bool state2 = 1; //set button2 state
void setup()
{
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(LED,OUTPUT);
pinMode(LEDex,OUTPUT);
}
void loop()
{
state1 = digitalRead(button1);
state2 = digitalRead(button2);
if (state1 == 0)
{
digitalWrite(LEDex,HIGH);
}
else
{
digitalWrite(LEDex,LOW);
}
if (state2 == 0)
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}
}