how do i
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
·
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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.
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·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/9/2009 2:40:11 AM GMT
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
·'·· {$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·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/18/2009 1:27:02 AM GMT
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·
·
·
·
·
Sam