Very basic question.
bdickens
Posts: 110
My need for a solution trumped my natural tendency to keep hunting for a solution.
I've got an LED wired to Pin 15, and a switch wired to 16 with the usual resistors. We wrote this program expecting that when we pushed the button the LED would change state.
So a 1 on the switch should light the led.
Oddly enough, it works, but only for a second, then even if the switch is down, the LED goes off. If we open, then close the switch again, it seems to work but again, shuts off after a second.
What am I missing ?
Code below
====================================================
Con
ibutton = 16
oled = 15
Pub Button2Led
Dira[noparse][[/noparse]ibutton] := 0
Dira[noparse][[/noparse]oled] := 1
repeat
outa[noparse][[/noparse]oled] := ina[noparse][[/noparse]ibutton]
I've got an LED wired to Pin 15, and a switch wired to 16 with the usual resistors. We wrote this program expecting that when we pushed the button the LED would change state.
So a 1 on the switch should light the led.
Oddly enough, it works, but only for a second, then even if the switch is down, the LED goes off. If we open, then close the switch again, it seems to work but again, shuts off after a second.
What am I missing ?
Code below
====================================================
Con
ibutton = 16
oled = 15
Pub Button2Led
Dira[noparse][[/noparse]ibutton] := 0
Dira[noparse][[/noparse]oled] := 1
repeat
outa[noparse][[/noparse]oled] := ina[noparse][[/noparse]ibutton]
Comments
Con
ibutton = 16
oled = 15
Pub Button2Led
Dira[noparse][[/noparse]ibutton] := 0
Dira[noparse][[/noparse]oled] := 1
repeat
outa[noparse][[/noparse]oled] := ina[noparse][[/noparse]ibutton]
I can't see anything wrong with your code. It worked OK on my hardware with a couple of changes for the different pins I'm using.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Post Edited (Leon) : 1/5/2008 10:15:25 PM GMT
The issue is most likely that you use no pull-down resistor.
A CMOS input pin is in an "undefined" state, sometimes even oscillating if not connected to a defined voltage.
Using a push button switch needs also an resistor in the opposite ditrection of the swich, called "pull-up" when connected to Vdd, or "pull-down" respectively
start your code with [noparse][[/noparse] code ]
end it with [noparse][[/noparse] /code ]
Inside that code avoid things like [noparse][[/noparse] i ] or [noparse][[/noparse] 1 ] , best use an space after each opening bracket
-Phil
6 lines of Perl I guess?
-P.
O, splendid times of FORTRAN punch cards...
(jk. added roblemo in the edit message box)
Eyes are getting old. You were right. The resistor was correct, but the power was one hole off.
Thanks