Shop OBEX P1 Docs P2 Docs Learn Events
Very basic question. — Parallax Forums

Very basic question.

bdickensbdickens Posts: 110
edited 2008-01-07 01:22 in Propeller 1
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]

Comments

  • bdickensbdickens Posts: 110
    edited 2008-01-05 20:05
    and the tabs are in the right spot. no idea why the post ate them

    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]
  • LeonLeon Posts: 7,620
    edited 2008-01-05 20:41
    I think you need to use "Insert formatted code".

    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
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-05 23:55
    This is the given indentation
    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]
    



    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
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-06 00:44
    I have the same problem posting code. I just go in and re-edit it to add spaces manually. Aggrivating, I know.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-06 01:09
    Please:
    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-06 01:23
    Or ... you can use my code formatter here: www.phipi.com/format. It takes care of the subscript problem and boldfaces the keywords.

    -Phil
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-06 01:29
    Nice smile.gif
    6 lines of Perl I guess?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-06 01:45
    No, just one. wink.gif

    -P.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-06 01:56
    There should be laws against RegEx.....
    O, splendid times of FORTRAN punch cards...
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2008-01-06 02:24
    lol [b]nop[/b]roblemo
    
    
    

    (jk. added roblemo in the edit message box)
  • bdickensbdickens Posts: 110
    edited 2008-01-07 01:22
    Duhhhhh.

    Eyes are getting old. You were right. The resistor was correct, but the power was one hole off.

    Thanks
Sign In or Register to comment.