Shop OBEX P1 Docs P2 Docs Learn Events
LED and Piezo — Parallax Forums

LED and Piezo

arien009arien009 Posts: 7
edited 2010-11-11 18:58 in BASIC Stamp
Hi,

May I know what command can I use to get the LED to flash and piezospeakers to beep at the same time? Eg. LED to flash 6 times with 1 second interval, and concurrently piezospeaker to beep with 1 second interval.

Thanks.

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2010-11-08 11:50
    If the led and resistor were connected to PIN2 and the pizo connected to PIN5 =>

    If the pizo has a built in oscillator, then you just send it a output:

    FOR i = 1 to 6
    PIN2 = 1 turns on LED
    PIN5 = 1 turns on pizo
    PAUSE 1000 do nothing for 1000 milliseconds
    PIN2 = 0 turn off LED
    PIN5 = 0 turn off pizo
    PAUSE 1000
    next i



    Otherwise you would:
    FOR i = 1 to 6
    PIN2 = 1 turns on LED
    FREQOUT 5,1000, 2000 oscillates pizo at 2000Hz for 1000 milliseconds
    PIN2 - 0 turns off LED
    PAUSE 1000 do nothing for 1000ms
    next i

    You'll need to setup your pins as outputs of course. I hope this helps



    P.S. yea I didn't use the code feature so all my formatting is gone. sorry.
  • arien009arien009 Posts: 7
    edited 2010-11-08 16:17
    Hi, does the boe-bot come with an oscillator?

    What if I do not have one?
  • electrosyselectrosys Posts: 212
    edited 2010-11-09 04:42
    Some piezo speakers has a built in oscillator, they will output a beep if you just connect a relevant voltage to it's +pin and -pin
    No, I don't think the beo-bot piezo speakers has a built in oscillator, you have to use the FREQOUT command (look at Spiral_72 code)
    You could also have a look at the (What’s a Microcontroller? v3.0 (.pdf) and the ( BASIC Stamp Manual v2.2 (.pdf)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-11-09 07:57
    There's no reason you can't drive the LED from the same pin you're using with FREQOUT for the piezo. The LED will be driven at the audio frequency but will look as if it's on constantly during those one-second intervals that the piezo is beeping.

    -Phil
  • arien009arien009 Posts: 7
    edited 2010-11-11 18:58
    thanks people!
Sign In or Register to comment.