use this project to know more about your button!
the code:
#define buttonPin 2
#define ledPin 13
bool state = 0;
bool lastRead = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(13,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
state = digitalRead(2);
if(state != lastRead)
{
Serial.println(state);
digitalWrite(ledPin,state)
lastRead = state;
}
}
----------------------------------
#define buttonPin 2
define word "buttonPin" as number 2 so when you write "buttonPin" = when you write 2
#define ledPin 13
define word "ledPin" as number 13 so when you write "ledPin" = when you write 13
bool state = 0;
the state of the button
bool lastRead = 0;
The last reading of the button
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonPin,INPUT);
}
Serial.begin(9600);
defines Serial monitor
pinMode(buttonPin,INPUT);
define "buttonPin" mode
void loop() {
// put your main code here, to run repeatedly:
state = digitalRead(2);
if(state != lastRead)
{
Serial.println(state);
digitalWrite(ledPin,state)
lastRead = state;
}
}
state = digitalRead(2);
put the reading of the button into "state"
if(state != lastRead)
if "state" is not "lastReading"
Serial.println(state);
print "state" into Serial monitor
digitalWrite(ledPin,state)
write the state of the button into pin 13
lastRead = state;
make "lastRead" = "state" value
Comments
Please log in or sign up to comment.