Shop OBEX P1 Docs P2 Docs Learn Events
Checking Inputs with a seperate cog — Parallax Forums

Checking Inputs with a seperate cog

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-01-30 13:06 in Propeller 1
Good Evening,
I am trying to start a new cog to constantly look at inputs and run certain Methods contingent upon with Pin went High. I am working with Pin-7
at the moment and also have it pulled Low through a resistor and a push button to send it high. For some reason I can't get both cogs "Full_Duplex_Serial" and the "Button_Down" cog to Blink the LED's at the same time. With the code as is, Pins 16 & 23·are Blinking and it appears that my code is not correct in my Botton_Down Method. Could someone gve me some advise ?
.................................................................................................
CON
·_CLKMODE = XTAL1 + PLL8X····
·_CLKFREQ = 40_000_000········

VAR
·long Stack[noparse][[/noparse]9], Temp
·
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
.......................................................................................................
PUB Main
·cognew(Button_Down(21), @Stack)········'Start new cog to handle the
······························································'Button_Down Method
·dira[noparse][[/noparse]7]~
·dira[noparse][[/noparse]21]~~
·dira[noparse][[/noparse]19]~~

·data.Stop········· ·'Stop any outside process using the Full_Duplex_Serial Cog
·data.start(1,0,2,9600)····················· 'Set up Serial through FullDuplexSerial
·Recieve······················································ ·'Call to my Recieve Method
....................................................................................................
·································
PUB Button_Down(Pin)

·Temp := INA[noparse][[/noparse]7]
·repeat While Temp := 0
·· !outa[noparse][[/noparse]Pin]········································ 'Toggle Pin 21
·· waitcnt(40_000_000 + cnt)

·repeat While Temp :=·1
···!outa[noparse][[/noparse]Pin]········································ 'Toggle Pin 21
·· waitcnt(40_000_000 + cnt)

....................................................................................................

PUB Recieve | rxbyte··································

· repeat
··· rxbyte := data.rx

··· if rxbyte == 1······················································
····· Data_Recieved_1
····
··· if rxbyte == 4············
····· Data_Recieved_4
......................................................................................................
·········
PUB Data_Recieved_1
· dira[noparse][[/noparse]16]~~
····· outa[noparse][[/noparse]16]~~
······· waitcnt(3_000_000 + cnt)
········· outa[noparse][[/noparse]16]~
·········· waitcnt(3_000_000 + cnt)
··········· data.rxflush
············ Recieve
....................................................................................................
············
PUB Data_Recieved_4
· dira[noparse][[/noparse]23]~~

····· outa[noparse][[/noparse]23]~~
······· waitcnt(3_000_000 + cnt)
········· outa[noparse][[/noparse]23]~
·········· waitcnt(3_000_000 + cnt)
·········· data.rxflush
············ Recieve
....................................................................................................

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-29 21:41
    When you start a separate cog, you also get a separate DIRA register which is initialized to zero (inputs).
    You need to move the "DIRA[noparse][[/noparse] Pin ]~~" to the start of the "Button_Down" method.
  • Nick MuellerNick Mueller Posts: 815
    edited 2008-01-29 23:01
    And this code:
     repeat While Temp := 0
    
    


    certainly doesn't do what you intended.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-01-29 23:33
    Thank You Mike for your help, and Nick could you give me an example of what would. New to the Prop :>)
    Thanks,
    JMLStamp2p
  • Gerry KeelyGerry Keely Posts: 75
    edited 2008-01-29 23:44
    I think what you need is

    ·"repeat while ina[noparse][[/noparse]7] == 0"

    This will continually scan pin 7 also note the use of == when testing for equality(not :=)



    Regards



    Gerry
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-01-30 13:06
    Thanks Gerry...
    JMLStamp2p
Sign In or Register to comment.