Button B4 for -ON/OFF LED D3.
i know how to read if thres only 1 button 1 led on each arduinos
bool b1,b1prev,dataOut;
void setup() {
// put your setup code here, to run once:
pinMode(A0,INPUT_PULLUP);
pinMode(12,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
digitalWrite(12,Serial.read());
}
b1prev=b1;
b1=!digitalRead(A0);
if(b1 and !b1prev)
{
dataOut= not dataOut;
Serial.write(dataOut);
}
}
but in 2 led 2 buttons on each arduinos case, can u help me?
thx
The first thing to do is to either add pullup resistors to the inputs or activate the built in pullup resistors by using INPUT_PULLUP in pinMode(). Unless you do that then the state of the inputs will be uncertain when the buttons are not pressed
yeah sure i did for 1 button 1 led on each arduinos
bool b1,b1prev,dataOut;
void setup() {
// put your setup code here, to run once:
pinMode(A0,INPUT_PULLUP);
pinMode(12,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
digitalWrite(12,Serial.read());
}
b1prev=b1;
b1=!digitalRead(A0);
if(b1 and !b1prev)
{
dataOut= not dataOut;
Serial.write(dataOut);
}
}
my prob is how to read 2 serial for those 2 buttons