QS Board Programming the touchpads
skylight
Posts: 1,915
I'm dabbling around with learning how to program with spin and have managed to get the leds chasing in several ways and happy with that I now wish to learn how to use the touchpads, this is where I have run into a little problem.
the program so far:
I'm not sure if i'm using the correct syntax as I havn't even got that far, as soon as i try to load I get a dialog saying it cannot find Touch Button.spin in any of the editor tabs yet i have it loaded on the next tab to the one that the code above is on.
the program so far:
{{ A simple chase of the quickstart board Leds }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR byte time OBJ Buttons : "Touch Buttons" PUB LedCounter time:=4 Buttons.start(_CLKFREQ / 100) dira[16..23] := %1111_1111 If Buttons.state repeat outa[16..23] :=1 waitcnt(clkfreq/time + cnt) outa[16..23] :=2 waitcnt(clkfreq/time + cnt) outa[16..23] :=4 waitcnt(clkfreq/time + cnt) outa[16..23] :=8 waitcnt(clkfreq/time + cnt) outa[16..23] :=16 waitcnt(clkfreq/time + cnt) outa[16..23] :=32 waitcnt(clkfreq/time + cnt) outa[16..23] :=64 waitcnt(clkfreq/time + cnt) outa[16..23] :=128 waitcnt(clkfreq/time + cnt)What I want to do is get the If statement bit to only run the chase if i'm touching one of the pads,
I'm not sure if i'm using the correct syntax as I havn't even got that far, as soon as i try to load I get a dialog saying it cannot find Touch Button.spin in any of the editor tabs yet i have it loaded on the next tab to the one that the code above is on.
Comments
You have to check your indentation - either it's only wrong in the post or you have to fix it in the code. All instructions that shall be executed if the if-condition is true have to be intended relatively to the if. (the repeat has to be shifted and therefore all instructions in the repeat loop also need to be shifted)
The current code would look for the state only once. So if you don't push a button at program start, your program will immediately shut down the propeller.
So, maybe you should rather do something like
repeat until Buttons.state
and remove the if statement.
I will also try the repeat until as suggested and let you know how i got on
Now I need to work out how to get a specific pad to trigger the chase rather than any pad.
I did change a line in the code though designating the outputs as some Leds were not turning on, the change was as below:
Original line
dira[16..23] := 11_1111
to
dira[16..23] :=%11111111
this turns on all leds in sequence
must have made an error in posting as it was like that in the original post but ended up wrong afterwards.
also noticed I didn't need to add the underscore it still worked
So change the code above to:
Andy
This one works on my Quickstart:
You need to touch the most right button !
Andy