Shop OBEX P1 Docs P2 Docs Learn Events
door display using pushbutton — Parallax Forums

door display using pushbutton

pongmstr2pongmstr2 Posts: 16
edited 2009-06-30 20:59 in Propeller 1
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]
··

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-30 05:57
    pub toggle
      dira[noparse][[/noparse]7]~~
      repeat
        if ina[noparse][[/noparse]0] ==1
          outa[noparse][[/noparse]7]~~
        else
        [color=red]' indentation needed here[/color]
          if ina[noparse][[/noparse]1] ==1
            [s][color=red]![/color][/s]outa[noparse][[/noparse]7][color=orange]~[/color]
       
    
    

    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)
  • pongmstr2pongmstr2 Posts: 16
    edited 2009-06-30 07:00
    thanks, hopefully i can get my project working
  • mctriviamctrivia Posts: 3,772
    edited 2009-06-30 07:04
    you do have a pull down resister on pin 7 right?

    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.
  • DogPDogP Posts: 168
    edited 2009-06-30 18:10
    It shouldn't matter, but it may be a good idea to explicitly set 0 and 1 to inputs:
    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
  • pongmstr2pongmstr2 Posts: 16
    edited 2009-06-30 18:24
    when input 0 goes high from the 3.3 volt pulse, i want pin 7 to turn on and stay on until another high pulse from pin 1 resets everything ( turns pin 7 low again). right now with the current code i can get pin 7 to turn on and stay on, but i can't get it to reset with the pulse from pin 1 maby its stuck in a loop?? pin 0 and 1 are pulled low with 2 resistors.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-30 18:47
    Try leaving out the else and correcting the indentation like:
    pub toggle
      dira[noparse][[/noparse] 7 ]~~    ' Pin 7 is an output
      repeat
         if ina[noparse][[/noparse] 0 ] ==1   ' Is pin 0 high?
            outa[noparse][[/noparse] 7 ]~~   ' Turn on pin 7
         if ina[noparse][[/noparse] 1 ] ==1   ' Is pin 1 high?
            outa[noparse][[/noparse] 7 ]~   ' Turn off pin 7
    


    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.
  • pongmstr2pongmstr2 Posts: 16
    edited 2009-06-30 20:59
    it works, thank you all for your contributions and help. The switch was wired wrong!
Sign In or Register to comment.