need a "kick start" with my spin object
karli
Posts: 16
··· I'm only 2 months into spin code <and> have finished the Propeller·I/O Timing Basics Lab
··· <and> started on Methods and Cogs··<and> managed to run 3 LEDs in three [noparse][[/noparse]new]cogs
··· on my Prop 40 pin chip proto board as well as my Prop Stck USB·· <and> I'm
··· reasonably proud of myself (haha) but this object has got· me stumped <and> ·kept me indoors
··· all through the 4th July weekend.
··· All I want to do is: translate 1 of 5 button presses (on one push button, P21)
····into· a 2 sec window (or gate) and
··· decode the push button activity into turning on 1 of 5 LEDs.
··· A typical push and release can be done in 250msec,so a 2 sec window should be adequate.
··· i.e., if I push once, the first LED comes on (like P4 as used in all the Lab setups {eg: outa[noparse][[/noparse]9..4])
··· if I push 3x then P4 goes off and P6 comes on, etc.
··· If I were to take longer than 2 sec to complete 5 presses, the previously started 2 sec gate
··· would delete the presses that occurred and only decode the presses in the last 2sec gate
·· into the appropriate LED (1 through 5).
·· I studied the example-solutions #4 and 5 on pages 28/29 of the I/O timing basics manual
·· and I think I got them 'nailed'· ---and--- I have feeling the answer is in there;
·· I'm basically a hardware guy and I kept thinking how to translate this function, using a couple
·· of ICs into spin code.· Maybe that's what slowed me down and I need to Init my mind set.
·· Anyone who can 'kick start' me onto the right track with this object will be rewarded
·· with a pizza.· (we can work out the pizza delivery details via 1-on-1 email)
·· thanks!
··· karli
··· <and> started on Methods and Cogs··<and> managed to run 3 LEDs in three [noparse][[/noparse]new]cogs
··· on my Prop 40 pin chip proto board as well as my Prop Stck USB·· <and> I'm
··· reasonably proud of myself (haha) but this object has got· me stumped <and> ·kept me indoors
··· all through the 4th July weekend.
··· All I want to do is: translate 1 of 5 button presses (on one push button, P21)
····into· a 2 sec window (or gate) and
··· decode the push button activity into turning on 1 of 5 LEDs.
··· A typical push and release can be done in 250msec,so a 2 sec window should be adequate.
··· i.e., if I push once, the first LED comes on (like P4 as used in all the Lab setups {eg: outa[noparse][[/noparse]9..4])
··· if I push 3x then P4 goes off and P6 comes on, etc.
··· If I were to take longer than 2 sec to complete 5 presses, the previously started 2 sec gate
··· would delete the presses that occurred and only decode the presses in the last 2sec gate
·· into the appropriate LED (1 through 5).
·· I studied the example-solutions #4 and 5 on pages 28/29 of the I/O timing basics manual
·· and I think I got them 'nailed'· ---and--- I have feeling the answer is in there;
·· I'm basically a hardware guy and I kept thinking how to translate this function, using a couple
·· of ICs into spin code.· Maybe that's what slowed me down and I need to Init my mind set.
·· Anyone who can 'kick start' me onto the right track with this object will be rewarded
·· with a pizza.· (we can work out the pizza delivery details via 1-on-1 email)
·· thanks!
··· karli
Comments
I haven't actually coded this or tested it, but I hope it will give you a jump start:
You'll need 2 cogs to do what I propose. One (timer cog) simply rattles off 2 second windows (high/true for 2 seconds then low/false for a few milliseconds. You can either use a global variable which is set high by the timer cog or have it set a pin high.
The main cog is the one that watches the button to see if anything has been pressed.
PSEUDO-CODE
I'm sure there are more clever ways to do this, but maybe this will help you get started.
pgb
1. You need to be able to detect a switch press and perhaps debounce
2. You need to be able to increment a counter and translate this in to which led needs to be lit (forget at the moment about the 2 seconds)
3. You need to get to grips with waitcnt, start simple
4. Combine these elements into a loop
5. Eat the pizza that YOU earnt!
Graham
In that case look at tracking in an array the time of the last 5 button presses + 2sec. Everytime round the loop check if cnt has reached any of these times, if yes remove the buttom from the array. The number of times in the array is the no of button presses you are interested in. The only thing you dont describe is want happens if more than 5 presses in 2 sec? Either ignore in which case replace the oldest time with the new button press time (+2 sec) or an error in which case what do you want?