I have built an 3D binary clock with LEDs. Its multiplexed: 3 digital pins for the floors and 5 for the LEDs.
There are 3 floors: 2x5 LEDs and 1x1LED to show 32 by the minutes.
To set the clock, I have 2 Buttons and a potentiometer. If you press the first button, all minutes will light up and you can set the hours with the poti. By pressing the second button, all hour LEDs light up and you can set the minutes with the poti.
My problem is: The buttons will give "any" input but not the desired - IF it is USB powered. If it is Battery powered, it all works fine.
I first set the buttons to digital pins, but there was a 0-1 mess, so I put them into analog inputs and catch them only if the value is >1000...
But not even that works if it is USB powered.
The buttons HAVE the 10k-resistors like in the tutorial here. It doesn't work...what can I do?
Problem is only if USB powered. I don't get it....
What is typically done (despite the tutorial) is to use the internal pullup resistor, and use the button push to connect the pin to ground.
No external resistor is needed.
ben0bi:
I drawed a schematic by hand, I will scan it in later. But I saw this problem on the schematic:
If I just plug a cable to the inputs wich is not connected to anything, it will also give this error input values...
On the schematic I saw, that I connected the buttons like this:
GND---10kOhm--+--Btn---PinX <-- means the cable from button to pin has no ground line...
|
+5V-----------+
But I think I should do it like that here, not?
+5V------Btn--+--PinX <-- but here, the +5V has no ground line...is that "acceptable"?
|
GND--10kOhm---+
is that the problem?
Definitely - the first circuit doesn't switch between 0V and 5V, it switches between 5V and open-circuit. An open-circuit input is an aerial picking up any signal from near by. You really don't want this!
You don't need the external resistors - just configure the internal pull-ups on the relevant pins and run them to buttons that switch to ground.
I just reviewed the DIgitalReadSerial tutorial, where i got that stuff from.
"The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply."
On the image it is not that obvious because the button is set up that the in-/out pins are on both sides of the breadboard and not "in" on the one and "out" on the other side. That's a little bit confusing, I am the proof
I will upload all the schematic and code so you can build your own one. I think it's a cool little thingie when it works.
Here is a blog post about my first try. But I disassembled it because of exact that problem. (buttons and stuff are not documented there but I made them) (I could not find the error.)...Now I have a much nicer looking one in a cardboard box. Photos of that one will come later...