Shop OBEX P1 Docs P2 Docs Learn Events
How do I make a tone play as long as a sensor is reading? — Parallax Forums

How do I make a tone play as long as a sensor is reading?

Trying to program an eight key "piano". I would like to make it play a note for as long as the sensor is activated. I think I want the BuzzerDur to be a word variable, but not sure how to make this work.
IF photo>2000 THEN
BuzzerDur????
Any advice would be great!

Comments

  • Unfortunately, the Basic Stamp cannot make a tone indefinitely. While it's making a tone, it can't do anything else like test for a sensor being activated. It's possible to do this sort of thing using external parts to make the tones with the Stamp controlling them. A lot depends on how "clean" you want the sounds to be. For simple square waves, you can use a 555 timer with the Stamp switching in different resistor values for different frequencies.

    It's possible for a Stamp to make a tone for a time, then quickly test a sensor, then go back to making a tone. The amount of time to test the sensor depends on the type of sensor. If the time is short enough, you might not notice the gap in the tone being produced.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2016-12-02 03:50
    I'll second Mike's post. You will need to determine what the shortest interval is that you can tolerate before checking the sensor again -- 64th note, perhaps? The output will likely include a buzzing sound, that corresponds to that interval. It might be possible to eliminate the buzz with a high-pass filter, though.

    -Phil
  • ercoerco Posts: 20,254
    Sounds like the perfect job for a SoundPal! One of Phil's creations, IIRC. Made by but sadly, discontinued by Parallax.

    Looks to still be available here.

    PDF here.
Sign In or Register to comment.