SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By tfowler
#190337
Hello,

I am trying to understand the 'color selector' project before I move on:

https://learn.sparkfun.com/tutorials/sp ... r-selector

It's just three buttons connected to digital pins and a potentiometer connected to an analog pin which together control the color and brightness of an LED.

The potentiometer is straightforward -- the middle pin inputs to A0 on the redboard and thereby provides a reading.

But I don't understand how the redboard figures out which button has been pressed. Each button is connected to a digital pin. If these pins are providing power, then pressing a button changes its voltage to low. But how does the board obtain that information? If, on the other hand, each button is inputting to the digital pin, where is power coming from?

Best,
-Trent
By skimask
#190339
Keep reading.

The PINS aren't providing power. They're getting rid of the power that's already there.
User avatar
By darrellg
#190341
The pins to which the buttons are connected are pulled up to Vcc, which is why the pinMode function uses the INPUT_PULLUP option. There is an internal resistor in the microcontroller that is applied between power and the pin that holds the pin high. When you push the button, you are shorting the pin to ground, causing it to go low. If you look at the code for that lesson, you'll notice that it is looking for the pin to go low, which is what will happen when the button is pushed.
By tfowler
#190360
"The pins to which the buttons are connected are pulled up to Vcc"

What's Vcc?

So if I understand correctly, the microcontroller is what's providing the power. All three buttons are connected to pins in a circuit which sits at high voltage until a button is pushed, at which point the power on that leg is grounded, the voltage reads low, and the microcontroller sets the color of the LED.

Is that right?
User avatar
By darrellg
#190362
tfowler wrote:What's Vcc?
In this case, it's 3.3V.
tfowler wrote:So if I understand correctly, the microcontroller is what's providing the power. All three buttons are connected to pins in a circuit which sits at high voltage until a button is pushed, at which point the power on that leg is grounded, the voltage reads low, and the microcontroller sets the color of the LED.

Is that right?
Yes, that's correct.