QuickStart Touchpad Tutorial demo for PROPGCC
mindrobots
Posts: 6,506
This is a propgcc port of the SPIN only version of the Quickstart button demo by JonnyMac from this thread:
http://forums.parallax.com/showthread.php?132048-QuickStart-module&p=1007660&viewfull=1#post1007660
Nothing exciting but we need simple examples for tutorial purposes. It could probably be trimmed down a bit but I didn't want to lose the essence of how the touchpads worked.
It exhibits the same flicker and instability issues most of the touchpad demos do.
Beau Schwabe's Sigma-Delta might be my next victim of porting. It's a very nice implementation of "sticky buttons".
http://forums.parallax.com/showthread.php?132048-QuickStart-module&p=1007660&viewfull=1#post1007660
Nothing exciting but we need simple examples for tutorial purposes. It could probably be trimmed down a bit but I didn't want to lose the essence of how the touchpads worked.
// // file = QS_padscan.c // propgcc conversion of JonnyMac's SPIN version of Quickstart Button Demo // simple propgcc tutorial demo // // copyright 2011 by Rick Post // terms of use below // #include <propeller.h> int scan_pads(long int delay) { OUTA |= 0x000000ff; // "charge" the pads - force them HIGH DIRA |= 0x000000ff; // set them as output DIRA &= 0xffffff00; // release touch pads back to input waitcnt(delay+CNT); // delay for a "touch" // a touched pad goes to LOW // so if you invert the input bits you can mask them out // and return the "touched" pads as HIGHS return ((~INA) & 0x000000ff); // return the touched pads } int main(void) { int pads = 0; DIRA |= 0x00ff0000; // set LEDs for output and pads for input DIRA &= 0xffffff00; while (1) { pads = scan_pads(CLKFREQ / 100); // scan the pads passing delay to wait for user touch pads = pads << 16; // shift the pad pins (0..7) to the LED pins (16..23) OUTA &= 0xff00ffff; // clear out the scanned pads from last time OUTA |= pads; // set the most recent scanned pads } return(0); } /* +-------------------------------------------------------------------- TERMS OF USE: MIT License +-------------------------------------------------------------------- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------- */
It exhibits the same flicker and instability issues most of the touchpad demos do.
Beau Schwabe's Sigma-Delta might be my next victim of porting. It's a very nice implementation of "sticky buttons".
Comments
I ran into the same button problems. There is a way to "debounce" the pads.
This is what I used. It's a port of the code on the ParallaxSemiconductor web site.
Works well for me. I'd also like to see this in the library distribution if it meets the "standard. . . " whatever that is. I don't know what good C code looks, but I can identify well-written Spin and PBASIC. I see a fair amount of similarity between the C and Spin.
The comments are really helpful for me and I appreciate them.
Great project. Simple. Want to buy a Mac just to blink LEDs on a Propeller now, but I'll just pretend.
Thanks,
Ken Gracey
i would like to understand where does the n=16 come from ?
is it because of the debounce ? if so why 16 ?
dgately
but on the code posted above by @jazzed
There's a loop of 16 that i don't understand.