Shop OBEX P1 Docs P2 Docs Learn Events
basic question reading inputs — Parallax Forums

basic question reading inputs

EllEll Posts: 2
edited 2008-10-15 06:05 in Propeller 1
I am sorry for posting such a basic question but, I have been trying to read a switch closing and turning on an LED when it does. I am not new to programing pics,but I am·new to the spin language,·but I am no expert either.It would seem like it would be a simple if..then statement. If someone could show me a simple program displaying how the if statement works I would be indebted. This is what I had. I turned on the block indicators I can not think of what I would be doing wrong.

{switch}
pub sw

dira[noparse][[/noparse]0]~~
··
· repeat
···if ina[noparse][[/noparse]1] == 1
···· outa[noparse][[/noparse]0]~~

·

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-10-15 00:01
    Here's some code from the PEkit Labs.

    [size=2][code]
    
    [b]PUB[/b] ButtonLed                                ' Pushbutton/Led Method
    
        [b]dira[/b][noparse][[/noparse]­0]  := 1                            ' P0  → output
        [b]dira[/b][noparse][[/noparse]­1] := 0                             ' P1 → input (this command is redundant)
                                                 
        [b]repeat[/b]                                   ' Endless loop
    
           [b]outa[/b][noparse][[/noparse]­0] := [b]ina[/b][noparse][[/noparse]­1]                    ' Copy P1 input to P0 ouput       
    
    
    




    [/code][/size]




    Try the PEkit labs, you'll find a lot of information there.
    http://forums.parallax.com/showthread.php?p=617192

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS

    Post Edited (Oldbitcollector) : 10/15/2008 3:46:28 AM GMT
  • EllEll Posts: 2
    edited 2008-10-15 00:41
    thank you very much. I'll check those websites out
  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-10-15 04:41
    Ell,

    If you want to get tricky, you can configure one of the counters to function as a simple·logic inverter gate with a 12.5ns propagation delay that·won't require any processor overhead.· That way you are free to do other things in code rather than using an IF/THEN statement to set the pin state.

    Note: you only need to call "PUB Inverter" once in your code.
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
     
    APIN = 0        'Input Pin
    BPIN = 3        'Output Pin
     
    PUB MainProgram
        Inverter                                'Start counter to function as an inverter
        repeat                                  'Endless loop ; Keep COG alive
    
    PUB Inverter
        DIRA[noparse][[/noparse]BPIN]~~                            'Make BPin an Output
        CTRA :=  %01001 <<26 | BPIN <<9 | APIN  'Setup counter for POS detector with Feedback mode
        FRQA := 1                               'Start Counter
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-10-15 06:05
    @Beau: I hadn't thought of using a counter like that. I haven't played with the counters but I know there must be a lot of uses for them.
    Thanks for the enlightenment smile.gif
Sign In or Register to comment.