door display using pushbutton
pongmstr2
Posts: 16
can someone please help me with this code i can't understand why it doesn't work.· I'm trying to have a +3.3 volt signal on pin 7·turn on a led and keep it on untill a 3.3 volt signal on pin 1·turns everything off and effectivly acts like· a reset.··Can somewone please provide me with the right sample code.
--Henry--
pub toggle
· dira[noparse][[/noparse]7]~~
· repeat
···· if ina[noparse][[/noparse]0] ==1
····· outa[noparse][[/noparse]7]~~
···· else
···· if ina[noparse][[/noparse]1] ==1
····· !outa[noparse][[/noparse]7]
··
--Henry--
pub toggle
· dira[noparse][[/noparse]7]~~
· repeat
···· if ina[noparse][[/noparse]0] ==1
····· outa[noparse][[/noparse]7]~~
···· else
···· if ina[noparse][[/noparse]1] ==1
····· !outa[noparse][[/noparse]7]
··
Comments
Maybe the indentation got lost in the post and is correct at your code .... just want to mention it.
! is the wrong operator for that. It will toggle the LED as long as the reset button is pushed (which will be the case for a lot of repeats). When you release·the button·the LED can be in any state on or off.
~ will clear the bit.
! is the not operator. ! 0 -> 1 and ! 1 -> 0 (in your case, as you only use one bit of the result)
Proper Switch wiring
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5
Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.
Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
dira[noparse][[/noparse]0]~
dira~
What do you want input 0 to do (you don't say in your description)? And what happens when you use your current code? And yeah... make sure you have your inputs (pin 0 and 1) pulled low.
Also, note that you can use elseif rather than else with an if inside the else.
DogP
Are you sure you are presenting +3.3V pulses to pins 0 and 1?
How are you determining what happens to pin 7? If you have an LED there, how is it connected?
What value resistors are you using? When something doesn't work and you ask for help, you really
have to provide all the information, software and hardware and descriptions of what happens. Often
the problem is not where you think it is and, if you're missing information, it may be difficult to help.