I am new to arduino and electronics. I am attempting to follow several videos online and putting the led on the arduino it lights up but as soon as I connect it to the breadboard it does not. this is the code I am using and a pic of the breadboard. I have put the short led pin on the left.
pic located at "http://www.zerobitsolutions.com/sites/arduino.jpg"
I can guess what you want to achieve.
Pushing the button increases the brightness of the LED
Off (0) -> Very Dim (51) -> Dim (102) -> Normal (153) -> Bright (204) -> Very Bright (255) -> Off (0) -> ...
So you should put the shorter pin on the RIGHT instead because the shorter pin is cathode (-)
Hi, just a quick question. Im a beginner as well, and Im looking at the same piece of code. Im wondering about this line:
boolean debounce(boolean last)
Dont we have to set some kind of value on this "last"? When the program scans and reaches this line, what does it think this last is? I see its not defined anywhere else outside of that part. thanks XD
d1n0:
Hi, just a quick question. Im a beginner as well, and Im looking at the same piece of code. Im wondering about this line:
boolean debounce(boolean last)
Dont we have to set some kind of value on this "last"? When the program scans and reaches this line, what does it think this last is? I see its not defined anywhere else outside of that part. thanks XD
Maybe should be this boolean debounce(boolean lastbutton)
Wait, let me rephrase my question. I dont wana open the new topic since this is a same piece of code. Look at this:
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
In that IF loop, he is comparing last and current. Ok I understand that current has a value whatever is read on the switchPin. However, Last does not have any value, defined anywhere in the program. So it can be either true or false. What decides if its true or false?
The only logical answer is that there is a hidden default value which Im not seeing. As in boolean last; means boolean last = false ;
Is that correct? can anyone confirm this?
This is a function declaration. The bit between parentheses is the parameter list for the function. In this case, the local (to the debounce() function) variable last will receive the value put in the parentheses when the function is called.
currentButton = debounce(lastButton);
Here, the debounce() function is being called. The value of lastButton is being passed to the function, and last will receive that value.
This is a function declaration. The bit between parentheses is the parameter list for the function. In this case, the local (to the debounce() function) variable last will receive the value put in the parentheses when the function is called.
currentButton = debounce(lastButton);
Here, the debounce() function is being called. The value of lastButton is being passed to the function, and last will receive that value.
Does that help?
EDIT: I figured it out. This function is not part of the void setup. my mistake
I was under the impression the program reads line by line, and that void setup is done first, only once , then it passes to void loop. Im asking about this first cycle. Does he not test that IF loop in void setup at first cycle then? Only when its actually being called?
Thanks for your patience, Im sure the question is trivial, however I am just a beginner in this world.
Nope, that function is not called in Void Setup, only in the main loop.
Void Setup is executed first which only sets the pin modes for the switch and LED pins.
Void Loop is executed next, this is the part that calls the Debounce function.
You could move the debounce function code block to the bottom of the code after the end of the main loop code and it should still work the same. (I think, try it )