
© Royalty Free/Corbis
Exercise 1
Exercise 2



| The Arduino chip has uncommitted inputs.
That is, when an I/O pin is not connected and acting as an input,
it cannot be assured to be either HIGH or LOW.
Pull-up and pull-down resistors are needed to commit the
input to the non-active (open) state for switches. |
/* using a push button*/
int LED1=8;
int BTN1=10;
void setup(){
pinMode(LED1,OUTPUT);
pinMode(BTN1,INPUT);
}
void loop(){
if (digitalRead(BTN1)==0){
digitalWrite(LED1,LOW);
} else if (digitalRead(BTN1)==1){
digitalWrite(LED1,HIGH);
}
}
/* using a push button*/
int LED1=8;
int BTN1=10;
void setup(){
pinMode(LED1,OUTPUT);
pinMode(BTN1,INPUT);
}
void loop(){
if (!digitalRead(BTN1)){
digitalWrite(LED1,LOW);
} else if (digitalRead(BTN1)){
digitalWrite(LED1,HIGH);
}
}
/* using a push button*/
int LED1=8;
int BTN1=10;
void setup(){
pinMode(LED1,OUTPUT);
pinMode(BTN1,INPUT);
}
void loop(){
digitalWrite(LED1,digitalRead(BTN1);
}