Shop OBEX P1 Docs P2 Docs Learn Events
Displaying Pushbutton Value in PST on QuickStart Board — Parallax Forums

Displaying Pushbutton Value in PST on QuickStart Board

flyingmanflyingman Posts: 1
edited 2013-05-28 18:17 in Propeller 1
I'm just starting out on the Propeller, and I created this code that uses 1 cog to monitor inputs and sets flags, and 4 more to figure out which button was pressed and send the value to the main program. I'm doing this to better understand cogs and flags (passing information around). The reason why the one OBJ is titled timer is because they will become timers later on in the project. From what I see, this should work. But then again I'm new to spin. It keeps displaying 0 as the pushbutton value when it's pressed.

Code (I also attached the files..):

main.spin
CON

        _clkmode = xtal1 + pll16x                                               
        _xinfreq = 5_000_000


VAR


  LONG t1, t2, t3, t4, input
   
OBJ pst : "Parallax Serial Terminal"
OBJ inputm : "input_monitor"
OBJ timer : "timer"


PUB main


  pst.start(9600)
  inputm.start(@input)
  timer.start(@t1, @t2, @t3, @t4, @input)


  repeat
    pst.str(string(16, "Button 0: "))
    pst.dec(t1)
    pst.newline
    pst.str(string("Button 1: "))
    pst.dec(t2)
    pst.newline
    pst.str(string("Button 2: "))
    pst.dec(t3)
    pst.newline
    pst.str(string("Button 3: "))
    pst.dec(t4)
    pst.newline

input_monitor.spin
VAR

LONG Stack[10]


PUB  start(inputAdr)


  cognew(getinput(inputAdr), @stack)


PUB getinput(inputaddr) | I, I1


  dira[0..3] := 11
  outa[0..3] := 11


  repeat
    repeat I from 0 to 3
    dira[I] := 1
    dira[I] := 0
    I1 := ina[I]
    if I1 == 0
      LONG[inputaddr] := I
    else
      LONG[inputaddr] := 4

timer.spin
VAR

  long  stack[10]
  
PUB start(t1a, t2a, t3a, t4a, inputAdr)


  cognew(main(t1a, inputAdr, 0), @stack)
  cognew(main(t2a, inputAdr, 1), @stack)
  cognew(main(t3a, inputAdr, 2), @stack)
  cognew(main(t4a, inputAdr, 3), @stack)


PUB main(tadr, inputaddr, ibtn)


  repeat
    if inputaddr == ibtn
      LONG[tadr] := 1
    else
      LONG[tadr] := 0

Does anybody see what I'm doing wrong??
Sign In or Register to comment.