/* Title: blink_led.ino Author: Lucas Lim Date Created: 19/03/2019 Last Modified: 19/03/2019 Purpose: Press the switch button to turn on LED */ // variable declaration // const value will not change const int led=8; // LED connected to PB2 of tiny44 const int sw=7; // switch connected to PA7 of tiny44 int buttonstate; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED as an output and pin SW as an input. pinMode(led, OUTPUT); pinMode(sw, INPUT); } // the loop function runs over and over again forever void loop() { /* digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second */ buttonstate = digitalRead(sw); if (buttonstate == HIGH) digitalWrite(led, LOW); // turn LED on else digitalWrite(led, HIGH); // turn LED off }