another reason to have an external device pull down the input is to support open-collector outputs which allow devices that operate at different voltage level to interface to one another
So tell me if I'm understanding this whole concept correctly or not. When your powering any device (button, led, sensor, etc...) 5v is going into one leg then the other leg you connect to ground but put a resistor between it and the controller board. This resistor is a "pull down" resistor because it will pull the voltage (or current?) down in order not the blow out the controller in case of a short circuit? But then in the software you can set a "input pullup" which I hear is actually a built in resistor?? But would it be a gate to convert it from a 0 to a 1? Idk am I making any sense? I want to have a fundamental understanding of whats going on.
I mean I keep changing my setup as I'm experimenting and doing different challenges. But I did send you a picture before its up there. A bit messy but i mean theres a clear view of the resistors and leds.
I think you are making this more complicated than it need to be.
Push button NOT pushed : IOpin is HIGH
Push button pushed : IOpin is LOW
That's it.
You can use the internal pull-up instead of the 10K resistor
no
the input pin has no default state, something needs to drive the input voltage above the theshold for the input to be recognizeds as HIGH or below the threshold for the input to be recognized as LOW.
there are 3 options
- connect a SPDT switch that either connects the input to 5V which is HIGH, or ground which is LOW
- use a pull-down resistor which makes the input LOW and wire a switch between the pin and 5V which makes the pin HIGH, or
- use a pull-up resistor that make the input HIGH and wire a switch between the pin and ground which makes the input LOW when the switch is pressed
the Arduino has an option to enable an internal pull-up resistor, so that approach is the most common
@mattyp77
Do you realize how much identifying information you have in your photographs? Clean your desk. Cathy and Steven would like that.
I built your project in the simulator, which goes so far as to simulate contact switch bounce and it is quite a trick to get the LEDs to toggle.
You may have bounceless buttons or incredible luck; it would be folly to go forward thinking you have a good solution, or a solution that works at all, in hand.
I added this at the end of the sketch, just before the closing brace of your loop():
static int lastGreenState;
static unsigned long lastPrintTime;
if (lastGreenState != LED_GREEN_STATE) {
static int counter;
Serial.print(counter);
counter++;
Serial.print(" ");
Serial.println(LED_GREEN_STATE ? "ON" : "OFF");
lastGreenState = LED_GREEN_STATE;
lastPrintTime = millis();
}
if (millis() - lastPrintTime > 1500) {
Serial.println("and... ");
lastPrintTime = millis();
}
It prints every change to the state of the green LED, and also prints "and..." when you haven't been pressing the button. You can asee that in real simulated life, the code is so fast it catches the switch opening and closing multiple times, on press and release:
As @gcjr points out, if you catch an even number of bounces, one thing. An odd number, another.
I removed the printing between button presses here:
0 ON
1 OFF
2 ON
3 OFF
4 ON
5 OFF
6 ON
7 OFF
8 ON
9 OFF
10 ON
11 OFF
12 ON
13 OFF
14 ON
15 OFF
16 ON
17 OFF
18 ON
19 OFF
20 ON
21 OFF
22 ON
23 OFF
HTH
a7
simple straight forward answer. no snark included. Thank you
So sorry sir. I am working with a broken knee. Cant bend my leg. I need crutches to walk and I'm basically living on my own. Im doing the best I can and I figured for such a simple set up the picture showed plenty of detail.
"it would be folly to go forward thinking you have a good solution, or a solution that works at all, in hand."
For christ sake what kind of community is this. I'm trying to learn here and some of you just throw out insults. I'm not sure why my code isn't working in your simulator or whatever else you may have done but I'm telling you it did for me repeatedly like many many times. I tested it thoroughly and I don't see how it wouldn't work. The if statement makes it impossible for the the led state to change twice unless the button was pressed, released, and pressed again. Which solves my main problem as I stated in the beginning that "1 single button press was looping around how ever many times and therefor changing the state of the light more than once." If it works for me AND IT DOES! but it doesn't for you, I guess that means I do in fact have bounceless buttons. To tell someone who is trying to learn and join an educational community that it is foolish to believe that they can ever come up with a good solution is incredibly fucked up and wrong! I know I have a long way to go. I've worked in construction my whole life. Computers and programming was a hobby of mine from childhood. I learned BASIC in high school and was at the top of my class. But I did not follow through. Life took me in other directions. Now in my late 30's I'm trying to put in some more work because Im enjoying the living shit out of it and I'm hoping I can make a career change. But I'm not the smartest person not the dumbest person in the world. I'm at the very least average. And I only have so much energy to dedicate to this stuff after 60 hour back breaking weeks. I get distracted for months. In fact I haven't really been doing any programming for at least 6 months. But when I do put my mind to it I think I hold my own more than a enough. Before falling off for the past 6 months as I mentioned I was studying Python and was doing really well. I wrote a few truly creative and perfectly working programs. I've written a few graphic games with pygame. Never had anybody in the python community say no shit like that to me. Shame on me for taking shit that other people like to dish out to heart. But shame on you for being an asshole.
That is exactly what happens when a switch bounce occurs
It's all in your head.
People helping you solve a problem is all the sympathy you need. You are looking for sympathy beyond that. We all are infirm in one way or another. Some of us have died. Get back to work.
I get that. I was wrong when I did say one time to someone something along the lines of "are you sure you need a debounce delay because my code is working perfect for me". And it is. So it can only mean that I have bounceless buttons. Which I also suspected to be the case. I was thinking that some were putting a delay to prevent a situation of the loop catching 1 button press more than once. I realize where I was wrong with that
I owe you a heartfelt apology for my comments earlier. Upon reflecting, I see how they were completely out of line and dismissive of your efforts and experiences. I was wrong to make assumptions about your solution, and I can understand how that came across as frustrating and condescending.
I certainly didn’t intend to belittle you or your work, but I realize now that the way I phrased things probably made you feel unsupported. That’s on me. Everyone in this community should feel respected and encouraged, no matter where they are on their learning journey, and I failed to provide that.
Your experience in both construction and programming is valuable, and I should have recognized that rather than dismissing your solution outright. It's clear you’ve put in the work, and your passion for learning shines through. I deeply regret not acknowledging that more thoughtfully.
I’m genuinely sorry for any hurt my words caused, and I’ll strive to be more constructive in the future. Thanks for calling me out, and I appreciate your patience.
a7
I appreciate that and I understand that I simply should not let something like that bother me so much. But for the record I'm not looking for sympathy. I don't think asking for help is asking for sympathy. This is a free community for peoples enjoyment. I just want him to know that that was a bullshit statement. no sympathy
your good. thanks
Sometimes our language-to-language translations miss the target, at times by a lot (even English to "English"). Nobody wants you to be held back from your goal. However; Steve and Cathy want you to remove their information from your photos. : )
lol I'd like to know what this Steve and Cathy business is all about but somehow I get the feeling that your not gonna let me in on it
lol what can I say...
Well.. Here's another way.
-jim lee