Shop OBEX P1 Docs P2 Docs Learn Events
Use touchbuttons to activate different sets of code - PropBASIC + P8X34A QuickStart — Parallax Forums

Use touchbuttons to activate different sets of code - PropBASIC + P8X34A QuickStart

JakobLoverJakobLover Posts: 5
edited 2011-12-12 20:45 in Propeller 1
Hi! I'm relatively new to programming and especially to my new Parallax Propeller P8X34A QuickStart board. I'm building a 5x5x5 LED cube controlled by this microcontroller, and I want to start different sets of code by touching one of the buttons. For example... When you press the first touchbutton, it starts this set of code, but when you click the next button, you activate another animation... Can someone help me out? If you would be very kind, could you write the code for me, and put in "CODE GOES HERE" or something? That would be awesome.

Remember that it's PropBASIC and not Spin!

Thanks in advance,
-Jakob

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-11 18:26
    JakobLover wrote: »
    Remember that it's PropBASIC and not Spin!

    Jakob, Welcome to the forum. Sorry, I cann't help with the PropBASIC but if you change your mind and are looking for some Spin code to do this, I've probably got a program that would be easy to modify to do what you want.

    Hopefully someone has a PropBASIC version of Beau's pad demo.
  • JakobLoverJakobLover Posts: 5
    edited 2011-12-11 19:39
    ok, can you send me the spin code? i'm sure I can implement the compiled version of my PropBASIC program into the spin outline. Can you post it here maybe? So other people can see it too? :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-12 10:54
    Jakob,

    Here's a demo program. I procrastinated some other projects and heavily documented this program.

    Here's what it looks like using the "Documentation" feature of the Propeller Tool.
    Object "ButtonMenu111212a" Interface:
    PUB  Setup
    PUB  MainLoop
    PUB  Method7
    PUB  Method6
    PUB  Method5
    PUB  Method4
    PUB  Method3
    Program:     165 Longs
    Variable:      4 Longs
      Public Notes
      This program demonstrates using the touchpads
      on a QuickStart board to select which methods
      of a program to execute.
      Most of the methods may be exited by pressing
      pad 0 (far right pad) on the QuickStart board.
      The methods in this program only flash the
      boards LEDs.  These methods are intended to
      illustrate some of the ways to exit a method.
      The exit strategies illustrated are:
      (Method7)
      A "repeat while" loop that checks
      a condition once per loop.  If the condition
      is true the loop repeats.  If the condition
      is not met, the program flow returns to the
      place in code immediately after the call to
      the method.
      (Method6, Method4 & Method3)
      One or more "abort" statements returns
      the flow of the program to immediately after
      the call to the method with an abort trap
      (see page 48 of Propeller Manual v1.2 for
      more information about aborts and abort
      traps).
      (Method5)
      The method must finished its programmed
      execution before the flow of the program
      returns to the place in code immediately
      after the call to the method.
      None of these exit strategies return a value
      (other than the default zero).
      
     The variable "delay" is used by the "Buttons" object
     to indicate how much time a pad's voltage should be allowed
     to decay prior to testing its state (to see if pad has been pressed).
     The variable "ledByte" makes it easier to display (with LEDs)
     which buttons have been pressed.  The button states are held
     in this single byte so when used with "outa[23..16]" the LEDs
     corresponding to each pad will be lit.
     The array "button" holds the current pad states.
     Examples: button[0] will equal 1 while pad zero (far right pad)is pressed.
               button[7] will equal 0 while pad seven (far left pad) is not pressed.
     The object "Buttons" fills the array "button" with ones or zeros corresponding
     to the state (whether or not it is pressed) of each pad.
    
    __________
    PUB  Setup
     The program will start with this method "Setup" since it is the first public
     method.
     I called it "Setup" since this is where things that need to happen just once
     occur.  (Setup or Init is a common name for this type of method.)
     At 80MHz (the QuickStart's default clock speed), this will be 800,000 clock cycles.
    _____________
    PUB  MainLoop
     MainLoop is likely where the program will speed most of its time.
     
     Touching pad 7 (far left pad) will start Method7.
     Pads 6 through 3 also launch corresponding methods.
     Touching pads 2 through 0 will only light their corresponding LED.
     Pad 0 (far right pad) will return the flow of the program back to
     this method ("MainLoop") from many of the other methods (all but
     Method5).
         
    ____________
    PUB  Method7
     Method7 only checks if it should exit between the LEDs flashing sets.
     (About once every four seconds.)
     Holding the "_ExitPad" (pad 0) will trigger the exit.
     The program flow returns to "MainLoop" only if "_ExitPad" (pad 0) is held
     while the pad's state is checked (with the line "while button[_ExitPad] == 0"
     at the bottom of the loop.
    
    ____________
    PUB  Method6
     Method6 ends with an abort.
     The method check for the abort state frequently
     (About four times a second.)
     Pressing the "_ExitPad" (pad 0) initiates the abort.
     Any of the above aborts returns the flow of the program back to "MainLoop".
    
    ____________
    PUB  Method5
     Method5 will only exit after it executes five sets of LEDs flashing.
     There is no operator interaction.
     This method takes about 15 seconds to complete.
     By reaching the end of the method, the program flow
     automatically returns to the place in code immediately after
     the call to this method (line 100).
    ____________
    PUB  Method4
     Method4 ends with an abort.
     The method checks for the abort state frequently.
     (About 8 times a second.)
     Pressing the "_ExitPad" (pad 0) initiates the abort.
     This method rotates (to the left) a pattern across the LEDs.
     This "abort" returns the flow of the program back to "MainLoop".
    
    ____________
    PUB  Method3
     Method3 ends with an abort
     The method checks for the abort state frequently.
     (About 8 times a second.)
     Pressing the "_ExitPad" (pad 0) initiates the abort.
     This method rotates (to the right) a pattern across the LEDs.
      Methods 2 and 1 are left as an exercise for the reader.
    

    Hopefully I explained enough with comments for it to make sense.

    I tried to show you how to start methods with the buttons and also how to end a method (most by pressing pad 0).

    Let me know if you need part of it explained more.
  • JakobLoverJakobLover Posts: 5
    edited 2011-12-12 20:45
    Thank you so much! :)
Sign In or Register to comment.