const int led = 8;
const int button = 7;
//note: reads LOW(0V) when button NOT pressed
// and HIGH(5V) when button IS pressed
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(button, INPUT);
//turn off led intially
digitalWrite(led, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
while(digitalRead(button) == HIGH) // button pressed
{
digitalWrite(led, HIGH); // led on
}
while(digitalRead(button) == LOW) // button not pressed
{
digitalWrite(led, LOW); // led off
}
}