Shop OBEX P1 Docs P2 Docs Learn Events
how do i — Parallax Forums

how do i

ball29ball29 Posts: 5
edited 2009-11-22 15:55 in BASIC Stamp
hi i have a standard boe bot and im alittle lost on a program i need to writh

i need to write a program that does the following.

wait for button/buttons to be pressed

PB1 pressed - beep at a frequency of 2800 HZ for .2 seconds on .1 seconds off, 5 times, then stop and wait for button press

PB2 pressed - beep at a frequency of 800 HZ for .2 seconds on and .1 seconds off, 3 times, then stop and wait for button press

both PB1 and PB2 pressed at the same time - beep continously for 2 seconds at a frequency of 4500 HZ , then stop and wait for button press

i need to use subroutines

and im lost on how to write this one if any one could help i would really apreciat it


·

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-11-09 01:22
    Write what you can and post it here so we can look at it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ball29ball29 Posts: 5
    edited 2009-11-09 01:55
    thats my problem i dont n ware to even start i was trying to modify the roming with wisker program but i couldnt get it to do anything it just came up with errors
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-09 02:15
    Back up. Write a program that just works with a single pushbutton and makes the one sound. Make sure you review the portions of the Stamp Manual on the BUTTON statement and the FREQOUT statement.

    Once you have that program running, write another program that uses the other pushbutton and makes the other sound.

    You will need to figure out how to detect whether both buttons are pressed at the same time, but start with the single button case.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-11-09 02:28
    Programming Speaker Control
    The FREQOUT command is a convenient way of sending high/low signals to a speaker to
    make sound. The [font=TimesNewRoman,Italic size=3][font=TimesNewRoman,Italic size=3]BASIC Stamp Manual [/font][/font]shows the command syntax as this:
    FREQOUT Pin, Duration, Freq1 {, Freq2}
    As with most of the other commands used in this book, Pin is a value you can use to
    choose which BASIC Stamp I/O pin to use. The Duration argument is a value that tells
    the FREQOUT command how long the tone should play, in milliseconds. The Freq1
    argument is used to set the frequency of the tone, in Hertz. There is an optional Freq2
    argument that can be used to mix frequencies.
    Here is how to send a tone to I/O pin P9 that lasts for 1.5 seconds and has a frequency of
    2 kHz:
    FREQOUT 9, 1500, 2000
    Example Program: TestPiezoWithFreqout.bs2
    This example program sends the 2 kHz tone to the speaker on I/O pin P9 for 1.5 seconds.
    You can use the Debug terminal to see when the speaker should be beeping and when it

    should stop.

    ' What's a Microcontroller - TestPiezoWithFreqout.bs2
    ' Send a tone to the piezo speaker using the FREQOUT command.
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    DEBUG "Tone sending...", CR
    FREQOUT 9, 1500, 2000

    DEBUG "Tone done."


    Programming Pushbutton Control
    The BASIC Stamp can be programmed to make decisions using an IF…THEN…ELSE
    statement. The example program you are about to run will flash the LED on and off
    when the pushbutton is pressed using an IF…THEN…ELSE statement. Each time through
    the DO…LOOP, the IF…THEN…ELSE statement checks the state of the pushbutton and

    decides whether or not to flash the LED.


    ' What's a Microcontroller - PushbuttonControlOfTwoLeds.bs2
    ' Blink P14 LED if P3 pushbutton is pressed, and blink P15 LED if
    ' P4 pushbutton is pressed.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    DO

    DEBUG HOME
    DEBUG ? IN4
    DEBUG ? IN3
    IF (IN3 = 1) THEN
    HIGH 14
    PAUSE 50
    ELSEIF (IN4 = 1) THEN
    HIGH 15
    PAUSE 50
    ELSE
    PAUSE 50
    ENDIF
    LOW 14
    LOW 15
    PAUSE 50

    LOOP

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 11/9/2009 2:40:11 AM GMT
  • ball29ball29 Posts: 5
    edited 2009-11-09 22:28
    thanks alot for the help if i have any other questions ill let you no i really apreciat it yeah.gif
  • ball29ball29 Posts: 5
    edited 2009-11-17 18:26
    hi i was wondering if any one had any more ideas this is what i have so far but i can not seem to get the last part to work when i push the two buttons at the same time is their anything i can do to get them to signal at the same time and im not sure if their is an easy way to use subrotines to get it to work better hear is what i was trying to get it to do again

    hi i have a standard boe bot AND im alittle lost ON a program i need TO writh
    WRITE a program that does the following.
    WAIT FOR BUTTON/buttons TO be pressed
    PB1 pressed - beep at a frequency of 2800 HZ FOR .2 seconds ON .1 seconds off, 5 times, THEN STOP AND WAIT FOR BUTTON press
    PB2 pressed - beep at a frequency of 800 HZ FOR .2 seconds ON AND .1 seconds off, 3 times, THEN STOP AND WAIT FOR BUTTON press
    both PB1 AND PB2 pressed at the same time - beep continously FOR 2 seconds at a frequency of 4500 HZ , THEN STOP AND WAIT FOR BUTTON press
    use subroutines




    ' {$STAMP BS2} ' Stamp directive.
    ' {$PBASIC 2.5} ' PBASIC directive.
    DEBUG "Program Running!"
    '
    [noparse][[/noparse] Variables ]
    pulseCount VAR Byte ' FOR...NEXT loop counter.
    '
    [noparse][[/noparse] Initialization ]
    FREQOUT 4, 2000, 3000 ' Signal program start/reset.
    '
    [noparse][[/noparse] Main Routine ]
    DO
    DEBUG HOME
    DEBUG ? IN10
    DEBUG ? IN9
    IF (IN10 = 0) THEN
    FREQOUT 4, 2000, 2800 '
    PAUSE 1000
    FREQOUT 4, 2000, 2800 '
    PAUSE 1000
    FREQOUT 4, 2000, 2800 '
    PAUSE 1000
    FREQOUT 4, 2000, 2800 '
    PAUSE 1000
    FREQOUT 4, 2000, 2800 '
    PAUSE 1000
    ELSEIF (IN9 = 0) THEN
    FREQOUT 4, 2000, 800 '
    PAUSE 1000
    FREQOUT 4, 2000, 800 '
    PAUSE 1000
    FREQOUT 4, 2000, 800 '
    PAUSE 1000

    ELSEIF (IN10 = 0) AND (IN9=0)THEN
    FREQOUT 4, 2000, 4500 '
    PAUSE 10

    ELSE
    PAUSE 50
    ENDIF

    PAUSE 50
    LOOP

    '
    [noparse][[/noparse] Subroutines ]
    'beep 5 times
    FREQOUT 4, 2800, 3000
    RETURN
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-11-18 00:28
    Try this

    ·'·· {$STAMP BS2}
    '·· {$PBASIC 2.5}
    '
    ' =========================================================================

    '
    [noparse][[/noparse] Program Description ]

    '
    [noparse][[/noparse] Revision History ]

    '
    [noparse][[/noparse] I/O Definitions ]

    '
    [noparse][[/noparse] Constants ]

    '
    [noparse][[/noparse] Variables ]
    · Laps······ VAR······ Byte
    '
    [noparse][[/noparse] EEPROM Data ]

    '
    [noparse][[/noparse] Initialization ]

    '
    [noparse][[/noparse] Program Code ]
    Main:

    · DO······································ · ·'··········Please Note that you should not have more than·4 GOSUB in any one·DO LOOP
    ·············································· ·'········ _______________________________________________________________________________
    IF (IN10 = 0) THEN
    GOSUB Freq_2800······················· '·<<<<<<<<<<<···· ·ONE

    ELSEIF (IN9 = 0) THEN
    ·GOSUB Freq_800······················ · '·<<<<<<<<<<<····· Two

    ELSE

    IF (IN10 = 0) AND (IN9=0)THEN······· '·<<<<<<<<<<<··· This line may need to be first Line that it look at not last Line
    ·GOSUB Freq_00·························· ·'·<<<<<<<<<<< ·· Three

    ·ENDIF
    ·ENDIF

    DEBUG HOME

    DEBUG ? IN10
    DEBUG ? IN9

    LOOP········································ '________________________________________________________________··································

    '
    [noparse][[/noparse] Subroutines ]

    Freq_2800:

    Laps = 0

    DO

    Laps = Laps + 1

    FREQOUT 4, 2000, 2800 '

    PAUSE 1000

    LOOP UNTIL laps = 5

    RETURN

    Freq_800:

    Laps = 0

    DO

    Laps = Laps + 1

    FREQOUT 4, 2000, 800 '

    PAUSE 1000

    LOOP UNTIL Laps = 3

    RETURN

    Freq_00:

    FREQOUT 4, 2000, 4500 '

    PAUSE 10

    RETURN
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 11/18/2009 1:27:02 AM GMT
  • ball29ball29 Posts: 5
    edited 2009-11-18 16:58
    hi i really wanted to thank you for all your help that was verry helpfull and i really appreciate the information hop.gifyeah.gifroll.gif
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-11-22 15:55
    Ball29

    Would you please post your code when you have finish·when you·get it to work the way you want it to work

    I may learn something new

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.