Shop OBEX P1 Docs P2 Docs Learn Events
Simple LED and Freqout help needed. — Parallax Forums

Simple LED and Freqout help needed.

NWUpgradesNWUpgrades Posts: 292
edited 2009-05-04 02:22 in BASIC Stamp
I am trying to modify the program toggle.bs2 to have 6 LED's and 2 Piezo speakers. I want the LED's to sound at the same time as the LED's. When I run the program the way I have it, the LED's light up and then the speakers sound. Is it even possible to do this? Here is the modified program: Note that the LED's are on pins 0-3 and 14-15. Thanks

' {$STAMP BS2}
·· ' {$PBASIC 2.5}
· thePin VAR Nib ' pin 0 - 15
· Setup:
· DIRA = %1111 ' make LEDs output, low
· Main:
· DO
· FREQOUT 12, 2000, 1500·· ' Signal to Piezo speaker 1
· FREQOUT 13, 2000, 1000·· ' Signal to Piezo speaker 2
· FOR thePin = 0 TO 15 ' loop through pins
· TOGGLE thePin ' toggle current pin
· DEBUG HOME, BIN6 OUTA ' show on Debug
· PAUSE 100 ' short delay
· NEXT
· LOOP ' repeat forever



·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-04 01:40
    The Stamp cannot do anything else while the FREQOUT is doing its thing. You can turn on (or off or toggle) an I/O pin (to control an LED) before you do the FREQOUT, but you can't change the I/O pin until the FREQOUT is done. You can divide the FREQOUT period into pieces and fiddle with the LED between the pieces, but that will cause some noise in the tones as the FREQOUT stops, then there's a brief pause while the LED changes and the FREQOUT is started up again. Like:

    for i = 1 to 10
    freqout 12,200,1500
    toggle 0
    next i
    for i = 1 to 10
    freqout 13,200,1000
    toggle 1
    next i
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-05-04 02:22
    That is what I had thought. Thanks for the sample, though. I will give it a try.
Sign In or Register to comment.