basic question reading inputs
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]~~
·
{switch}
pub sw
dira[noparse][[/noparse]0]~~
··
· repeat
···if ina[noparse][[/noparse]1] == 1
···· outa[noparse][[/noparse]0]~~
·

Comments
[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
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.
Thanks for the enlightenment