No video

Arduino Uno R4 WiFi LESSON 25: Make a Toggle Switch with Button Switch

  Рет қаралды 2,624

Paul McWhorter

Paul McWhorter

Ай бұрын

Pick your Sunfounder kit up so you get the same results I do:
amzn.to/3SciApZ
You can pick up the neat jumper wires I showed in the video here:
amzn.to/3U2vyIe
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In this video I show you how to create a toggle switch using a button switch to turn an LED on and off. The switch is using a 10K pullup resistor. We then use the switch to control an LED. Enjoy!
[Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. ]
#arduinor4wifi
#toggleswitch
#tutorial

Пікірлер: 43
@robertschuldenfrei2402
@robertschuldenfrei2402 Ай бұрын
I am legend only because I took the R3 course in September of 2023. That made the homework assignment fairly easy. That was not the case last year when the toggle assignment was first offered.
@anagramfive
@anagramfive 28 күн бұрын
i am legend! I had no idea how to solve it, but when I was about to see the video I was enlighted to create a binary state for the led that change to inverse everytime the button is pressed. I tryed and it worked!!! (I have not seen the answer yet).
@paulmcwhorter
@paulmcwhorter 28 күн бұрын
LEGEND!
@anagramfive
@anagramfive 28 күн бұрын
@@paulmcwhorter int pinLed=8; int pinBut=10; int butVal; bool ledState=LOW; int dt = 200; void setup() { pinMode(pinLed,OUTPUT); pinMode(pinBut,INPUT); } void loop() { butVal=digitalRead(pinBut); if (butVal==0){ ledState=!ledState; digitalWrite(pinLed,ledState); delay (dt); } }
@louistoweill4232
@louistoweill4232 Ай бұрын
I am legend. I got the three button homework from lesson 25 working well. I feel good for a 76 year old "used-to-be" engineer.
@gabriel38g
@gabriel38g Ай бұрын
I've taken most of these lessons previously. But it's still good to refresh the lesson. 👍 I've also been following along using an ESP32 and most of the code seems to work fine using the same Arduino IDE.😄
@robertschuldenfrei2402
@robertschuldenfrei2402 Ай бұрын
Just for fun I asked ChatGPT to do the last assignment: "Write an Arduino program that will toggle a red LED with a button push." This is exactly what Paul does NOT want you to do. The whole point of this class is to learn how to make things by understanding how the Arduino works. That being said ChatGPT not only gave instructions in plain English how to build the circuit, but it generated the following code: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin int ledState = LOW; // the current state of the LED int buttonState; // the current reading from the input pin int lastButtonState = HIGH; // the previous reading from the input pin unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, ledState); } void loop() { int reading = digitalRead(buttonPin); if (reading != lastButtonState) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { if (reading == LOW && lastButtonState == HIGH) { ledState = !ledState; digitalWrite(ledPin, ledState); } } lastButtonState = reading; }
@jeff_wild
@jeff_wild Ай бұрын
Well, it's an interesting concept: this version compares the time between the last time the button changed state (both from 1 to 0 and 0 to one) and the current time. If that time was longer than 50 millis, THEN it checks to see if the button state changed from 0 to 1. I suppose there may be a good reason for doing it that way; not that we're aiming for maximum efficiency, but this seems like extra processing time to me. Every time through the loop, it does a 32 bit comparison to determine if it can avoid a 16 bit comparison, just to avoid a hard delay. I also find the Chat GPT version a bit tedious to read. The first question I had was, "what does time have to do with the button state?" and then I had to take the time to understand why, and then how, it was used.
@robertschuldenfrei2402
@robertschuldenfrei2402 Ай бұрын
@@jeff_wild It does go to show that there are many ways to "skin the cat." I would never have thought of this approach. All of my programming for the last 60 years has been algorithmic, with one exception, rather than real time. The exception was a queueing model I built in 1972 for Ethan Allen furniture. One of the reasons this course interests me is real time nature of a micro controller like the Arduino. On my own I have learned about interrupts on the Arduino. I hope Paul gets into this in future lessons.
@larryplatzek9017
@larryplatzek9017 Ай бұрын
This Lesson makes you Think but that is not bad! Thank You Paul!
@qzorn4440
@qzorn4440 Ай бұрын
A most excellent video. I seem to learn much more correcting my mistakes. 😉 Thank you.
@DrDave327
@DrDave327 28 күн бұрын
Hey, Paul! I must have not clicked the “comment “ this morning when I posted my homework. I will post again tomorrow.
@jameslewellen150
@jameslewellen150 Ай бұрын
I posted my homework on my KZbin channel. Nice video
@paulmcwhorter
@paulmcwhorter Ай бұрын
LEGEND!
@richardsstark9825
@richardsstark9825 Ай бұрын
Well, I folded on the homework assignment from lesson 24. Even though, I went through setting up a toggle switch from your prior Arduino Uno tutorials and more recently on your Raspberry Pi tutorials, I have trouble understanding the coding to the point of being able to set it up on my own without copying it. Maybe your upcoming tutorial(25) will explain it in a way to "sink in" so to speak.
@so_u_own_a_BEAGLE
@so_u_own_a_BEAGLE Ай бұрын
Hello Sir, I diligently follow your YT & lyk u explain. one ques i wanna ask - can we control esp32cam camera using arduino uno r4 wifi- aeduino ide. Pls make small video on this
@scottwait3585
@scottwait3585 Ай бұрын
Thank you paul
@patrickfox-roberts7528
@patrickfox-roberts7528 Ай бұрын
thanks paul
@antoniomuntaner8111
@antoniomuntaner8111 Ай бұрын
I heard that an output pin, such as the one connected to a led can be read (digitalRead) so you know if led is on or off. If this is true it could simplify the code.
@patrickfox-roberts7528
@patrickfox-roberts7528 Ай бұрын
it is true
@shineeyman
@shineeyman Ай бұрын
This is the solution I ended up discovering. I knew I wanted to both read and write from the ledPin but wasn't sure how to do it or if it was possible. My first attempt was to declare both a pinMode(ledPin, OUTPUT); and a pinMode(ledPin,INPUT); in the void setup but as one might expect, this didn't work. So then I took a shot in the dark and just tried to digitalRead from the ledPin even though it was set up as an OUTPUT and to my surprise it worked. I'm guessing this could lead to some problems with a more complex program or circuit but I was avoiding googling as instructed and this solution worked for me so I went with it. Interested to see if @paulmcworther has any input on this!
@josephmalina9822
@josephmalina9822 Ай бұрын
quick question for you, if i have an uno r3, can i still follow along this tutorial since its more recent?
@paulmcwhorter
@paulmcwhorter Ай бұрын
I would take the earlier set of lessons on this channel, which are targeted towards the R3. Really the info in the earlier class is still relevant today.
@josephmalina9822
@josephmalina9822 Ай бұрын
​@@paulmcwhorter thanks a lot! Appreciate it.
@jerrobison
@jerrobison Ай бұрын
Do I get bonus points for solving this with a while statement? 😊
@shineeyman
@shineeyman Ай бұрын
I did the same! kzbin.info/www/bejne/l5WraYCAqM-jaKcsi=3yiv5sdJYX0PVszk
@stephenbrown5648
@stephenbrown5648 Ай бұрын
It would be easier to match your braces if you indent!!!
@jeff_wild
@jeff_wild 25 күн бұрын
Ctrl-T will format your code, including indentation.
@Adrian427
@Adrian427 Ай бұрын
Well, I didn't manage to complete the homework from Lesson 24, I did get this one done. Thanks, Paul, for the great work you do. HW: kzbin.info/www/bejne/p3ayZZuOgch5a5Y
@robertschuldenfrei2402
@robertschuldenfrei2402 Ай бұрын
Homework: kzbin.info/www/bejne/g3nUXoGChLuSr8U
@paulmcwhorter
@paulmcwhorter Ай бұрын
LEGEND!
@richardsstark9825
@richardsstark9825 Ай бұрын
My homework : kzbin.info/www/bejne/oIKrm6yQeM6mfJYsi=Vhy1jePLqri1El8D Used if/else rather than if/if to set up a toggle button. . I found it easier to follow what the values were through the iterations of the setup loop. Still doubt I could have set it up on my own.
@jeff_wild
@jeff_wild Ай бұрын
My homework: kzbin.info/www/bejne/nqjFnKt3oqqhq80
@paulmcwhorter
@paulmcwhorter Ай бұрын
LEGEND!
Arduino Uno R4 WiFi LESSON 26: Control RGB LED Color with Pushbuttons
40:08
M5Stack Cardputer: ESP32-S3 Pocket Computer
17:06
ExplainingComputers
Рет қаралды 78 М.
Get 10 Mega Boxes OR 60 Starr Drops!!
01:39
Brawl Stars
Рет қаралды 10 МЛН
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 13 МЛН
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 212 МЛН
I spent all summer building THIS! (relay computer)
22:34
WillsBuilds
Рет қаралды 24 М.
I tried finding Hidden Gems on AliExpress AGAIN! (SPECIAL Part 10)
15:11
I Built a Transparent Boomerang (it's lethal)
13:10
Mike Shake
Рет қаралды 3,2 МЛН
Arduino Uno R4 Review - Best Arduino Board Ever?
9:16
Gary Explains
Рет қаралды 28 М.
Using the Arduino Uno R4 WiFi Built In LED Matrix.
1:11:28
Paul McWhorter
Рет қаралды 9 М.
Forget WiFi! This Wireless Method is WAY Better?
12:14
GreatScott!
Рет қаралды 543 М.
I tried Future Technology! (that you can use TODAY)
12:22
GreatScott!
Рет қаралды 271 М.
Get 10 Mega Boxes OR 60 Starr Drops!!
01:39
Brawl Stars
Рет қаралды 10 МЛН