Browse Source

Lesson 25 finish

master
Tom Nordal 2 years ago
parent
commit
15509a5b18
  1. 24
      Make a Toggle Switch with Button Switch/src/main.cpp

24
Make a Toggle Switch with Button Switch/src/main.cpp

@ -1,18 +1,28 @@
#include <Arduino.h> #include <Arduino.h>
// put function declarations here: int buttonPin = 2;
int myFunction(int, int); int ledPin = 10;
int buttonState = 1;
int lastButtonState = 1;
int ledState = LOW;
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
int result = myFunction(2, 3); Serial.begin(115200);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if (lastButtonState == HIGH && buttonState == LOW)
{
ledState = !ledState;
digitalWrite(ledPin, ledState);
} }
lastButtonState = buttonState;
// put function definitions here: delay(50); // 50ms debounce
int myFunction(int x, int y) {
return x + y;
} }
Loading…
Cancel
Save