Shop OBEX P1 Docs P2 Docs Learn Events
simple counting program — Parallax Forums

simple counting program

supportsupport Posts: 15
edited 2011-08-07 16:39 in Propeller 1
hello all, i'm just trying to write a simple program to count every time a pushbutton is pressed and show the number on a terminal screen, so basically the output would look like:

1
2
3
4
5
6
7

etc..

i'm using the parallax proto board usb, and i know how to do the hardware part of it. any help would be much apreciated thanks.

--Henry--

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2011-08-07 13:48
    Did you search in the forum?

    There should be tons of threads dealing with buttons. Search for button and maybe debounce.

    You know that buttons are bouncing? Bouncing means that when pushed/released the electrical contact is not stable because the mechanics bounces back and forth for a short time. If you don't take this into account in your program, the counter would not increase in single steps but jump over several values with each push.

    Counting and sending data to a terminal should not be a big problem, right?!
  • supportsupport Posts: 15
    edited 2011-08-07 14:11
    the debouncing issue is not that important, i can fix it with hardware, i'm having problems with the code. i'm trying to do it with 12 blocks as well but havent been able to find an increment block. Idealy that would be the easyest way.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-08-07 14:30
    I don't know about the 12 Blocks program, but you can read about writing code for buttons starting around page 34 in the free download PE Kit manual:

    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf

    Your code would then say something like
    Repeat {forever}
    
        IF ina[22] == %1 {If button on pin 22 is pressed.}
          ButtonCounter := (ButtonCounter + 1)  {Increment the counter by 1.}
          waitcnt(clkfreq/100 + clk) {Wait a little to debounce the button.}
    
    {Display ButtonCounter using whatever way you want to do it.}      
    
    
  • supportsupport Posts: 15
    edited 2011-08-07 15:24
    thankx, that is exactly the kind of code i need, but how do i display the numbers 1, 2, 3, ... on say the computer monitor that this prop wll be connected to using the usb cable. The prop will allways be connected to the computer.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-08-07 16:13
    support wrote: »
    thankx, that is exactly the kind of code i need, but how do i display the numbers 1, 2, 3, ... on say the computer monitor that this prop wll be connected to using the usb cable. The prop will allways be connected to the computer.

    Go to the following page:

    http://forums.parallax.com/showthread.php?89958-Propeller-Education-Kit-Labs-Tools-and-Applications

    And look at the two sections under PE Kit Tools: PC Terminal Communication and there is Debug LITE for the Parallax Serial Terminal·. The serial terminal turns your computer into a display that allows you to debug SPIN code. I think the manual to which I linked earlier tells step by step how to set that up. In fact, that manual is a very good way to get started learning SPIN, etc.

    I hope that helps get you started.
  • supportsupport Posts: 15
    edited 2011-08-07 16:39
    Thank you all for your help i got it going woohhoo
Sign In or Register to comment.