Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // the number of the pushbutton pin
- const int buttonPin = PB0;
- // the number of the LED pin
- const int ledPin = PB1;
- int ledState = 0;
- int buttonState = 0;
- void setup() {
- pinMode(ledPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- }
- void loop() {
- // Read the button
- int btn = digitalRead(buttonPin);
- // when button state has changed and is pressed
- if (btn != buttonState && btn == HIGH) {
- // toggle the logical LED state
- if (ledState == HIGH) {
- ledState = LOW;
- } else {
- ledState = HIGH;
- }
- // and make the logical real
- digitalWrite(ledPin, ledState);
- }
- buttonState = btn;
- }
Add Comment
Please, Sign In to add comment