Shop OBEX P1 Docs P2 Docs Learn Events
Using LEDS to match notes — Parallax Forums

Using LEDS to match notes

I'm trying to use LED'S to match certain frequencies but whenever I add that part of the code the Boe-Bot just goes straight and completely ignores the rest of the code. This is what I have(just the LED part):
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Nib ' Counts alternate contacts.
old7 VAR Bit ' Stores previous IN7.
old5 VAR Bit ' Stores previous IN5.
FreqDetectable CON 3000
C5 CON 523
F5 CON 699
G5 CON 784
A5 CON 880
Be5 CON 987
C6 CON 1047 ' Piano notes
D6 CON 1175
E6 CON 1319
F6 CON 1397
G6 CON 1568
A6 CON 1760
Be6 CON 1976
C7 CON 2093
D7 CON 2349
E7 CON 2637
F7 CON 2793
G7 CON 3136
A7 CON 3520
Be7 CON 3951

Gf5 CON 740
Ef5 CON 622
Bef5 CON 466
Cs6 CON 1111
Df6 CON 1111
Ds6 CON 1247
Ef6 CON 1247
Fs6 CON 1482
Gf6 CON 1482
Gs6 CON 1664
Af6 CON 1664
Bef6 CON 1868
Cs7 CON 2221
Df7 CON 2221
Ds7 CON 2493
Ef7 CON 2493
Fs7 CON 2964
Gf7 CON 2964
Gs7 CON 3328
Af7 CON 3328
As7 CON 3735
Bef7 CON 3735

C8 CON 4186
PZS1 PIN 4
Piezospeaker1 PIN 4
Piezospeaker2 PIN 4

'
[ Main Routine ]

'
[ Subroutines ]
HIGH 14:HIGH 13:HIGH 12:HIGH 11
Display_Color: ' Subroutine label
LOW 14: LOW 13: LOW 12: LOW 11 ' Turn off all LEDs
SELECT FreqDetectable
CASE "A5", "A6", "Af6"
HIGH 14
CASE "Be6", "Bef6", "Be7"
HIGH 13
CASE "C6", "Cs6", "C7", "Cs7"
HIGH 12
CASE "D6", "Df6", "D7", "Df7"
HIGH 11
CASE "E6", "Ef6", "E7", "Ef7"
HIGH 11
HIGH 12
CASE "G5", "G6", "G7"
HIGH 14
HIGH 13
HIGH 11
CASE "F5", "F6", "F7"
HIGH 14
HIGH 13
ENDSELECT
RETURN

How would I go about assigning specific notes to LED patterns so that when those notes play the LED pattern also occurs at the same time?

Comments

  • You are using strings for your conditions (such as "A5", "A6", "Af6"). You should use just the constants (such as A5, A6, Af6). It would be good to have a CASE ELSE as well, so you can tell when you didn't get a hit at all.

    When you post code, it is best to post it all and put it in between "[c.o.d.e] and [/.c.o.d.e]", thus (lose the periods):
    SELECT ...
       CASE ...
         do something
       CASE  ELSE
         DEBUG "No Match, FreqDetectable:  ", FreqDetectable, CR)
    ENDSELECT
    

  • GenetixGenetix Posts: 1,754
    edited 2015-12-13 21:28
    TristanZ222,

    You should post all of your code as either an attachment or in code blocks.

    To use code blocks put [ code ] on the line before your code and [ /code ] on the line after it.
    (I added the extra spaces so the editor doesn't think I am attaching code to this message.)

    So if you type (minus the extra spaces between the brackets):
    [ code ]
    ' Sample Code
    Line 1
    Line 2
    Line 3
    ...
    [ /code ]

    It will look like this:
    ' Sample Code
    Line 1
    Line 2
    Line 3
    ...
    
Sign In or Register to comment.