diff --git a/Make a Toggle Switch with Button Switch/src/main.cpp b/Make a Toggle Switch with Button Switch/src/main.cpp index cb9fbba..7d0f940 100644 --- a/Make a Toggle Switch with Button Switch/src/main.cpp +++ b/Make a Toggle Switch with Button Switch/src/main.cpp @@ -1,18 +1,28 @@ #include -// put function declarations here: -int myFunction(int, int); +int buttonPin = 2; +int ledPin = 10; +int buttonState = 1; +int lastButtonState = 1; +int ledState = LOW; + void setup() { // put your setup code here, to run once: - int result = myFunction(2, 3); + Serial.begin(115200); + pinMode(buttonPin, INPUT); + pinMode(ledPin, OUTPUT); + } void loop() { // put your main code here, to run repeatedly: -} - -// put function definitions here: -int myFunction(int x, int y) { - return x + y; + buttonState = digitalRead(buttonPin); + if (lastButtonState == HIGH && buttonState == LOW) + { + ledState = !ledState; + digitalWrite(ledPin, ledState); + } + lastButtonState = buttonState; + delay(50); // 50ms debounce } \ No newline at end of file