Shop OBEX P1 Docs P2 Docs Learn Events
BASIC STAMP "Robot Song Project" - The Beatles — Parallax Forums

BASIC STAMP "Robot Song Project" - The Beatles

BrendanTheONeillBrendanTheONeill Posts: 1
edited 2014-12-02 08:49 in BASIC Stamp
Just copy+paste this code into BS2 and do a "Syntax Check" then upload. It's a good Beatles song.


' {$STAMP BS2}

' {$PBASIC 2.5}


a CON 831
b CON 932
c CON 1047
d CON 1109
e CON 1245
f CON 1397
ah CON 1661


DO
FREQOUT 4, 150, a
FREQOUT 4, 150, b
FREQOUT 4, 150, d
FREQOUT 4, 150, b
FREQOUT 4, 350, f
FREQOUT 4, 350, f
FREQOUT 4, 600, e

PAUSE 50

FREQOUT 4, 150, a
FREQOUT 4, 100, b
FREQOUT 4, 150, d
FREQOUT 4, 150, b
FREQOUT 4, 350, e
FREQOUT 4, 350, e
FREQOUT 4, 550, d

PAUSE 50

FREQOUT 4, 150, a
FREQOUT 4, 150, b
FREQOUT 4, 100, d
FREQOUT 4, 100, b
FREQOUT 4, 450, d
FREQOUT 4, 250, e
FREQOUT 4, 250, c
FREQOUT 4, 250, b
FREQOUT 4, 350, a

PAUSE 100

FREQOUT 4, 250, a
FREQOUT 4, 400, e
FREQOUT 4, 600, d

PAUSE 200

FREQOUT 4, 150, a
FREQOUT 4, 150, b
FREQOUT 4, 100, d
FREQOUT 4, 100, b
FREQOUT 4, 300, f
FREQOUT 4, 300, f
FREQOUT 4, 500, e

PAUSE 50

FREQOUT 4, 100, a
FREQOUT 4, 100, b
FREQOUT 4, 100, d
FREQOUT 4, 100, b
FREQOUT 4, 450, ah
FREQOUT 4, 250, c
FREQOUT 4, 250, d
FREQOUT 4, 250, c
FREQOUT 4, 350, b

PAUSE 50

FREQOUT 4, 100, a
FREQOUT 4, 100, b
FREQOUT 4, 100, d
FREQOUT 4, 100, b
FREQOUT 4, 450, d
FREQOUT 4, 250, e
FREQOUT 4, 250, c
FREQOUT 4, 250, b
FREQOUT 4, 350, a

PAUSE 100

FREQOUT 4, 250, a
FREQOUT 4, 400, e
FREQOUT 4, 600, d

PAUSE 100
LOOP

Comments

  • JonnyMacJonnyMac Posts: 9,014
    edited 2014-12-01 09:40
    Cool. Your next step is to learn how to use DATA statements so you can put songs into other programs and call them at will. With the holidays on use, you could make a really fun musical decoration.
  • IroneIrone Posts: 116
    edited 2014-12-01 16:08
    Hello,
    Jessica Uelman put a thread named Christmas Carols with Light Display on 12-4-09 and it has four songs on it. Please look it up in advanced search. I made up my own song called Good King Wenceslas. Here is my code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    'Good King Wenceslas
    
    Notes         DATA    "R", "D", "D", "D", "E", "D", "D", "A", "B", "A", "B", "d", "D", "D",
                          "D", "D", "D", "E", "D", "D", "A", "B", "A", "B", "d", "D", "D",
                          "A", "G", "g", "E", "g", "E", "D", "B", "A", "B", "d", "D", "D",
                          "A", "A", "B", "d", "D", "D", "E", "A", "G", "g", "E", "D", "G", "D", "Q"
    
    Octaves       DATA    0,    7,   7,   7,   7,   7,   7,   6,   6,   6,   6,   7,   7,   7,
                          7,    7,   7,   7,   7,   7,   6,   6,   6,   6,   7,   7,   7,
                          7,    7,   7,   7,   7,   7,   7,   6,   6,   6,   7,   7,   7,
                          6,    6,   6,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7,   7
    
    Durations     DATA    1000, 4,   4,   4,   4,   4,   4,   2,   4,   4,   4,   4,   2,   2,
                          4,    4,   4,   4,   4,   4,   2,   4,   4,   4,   4,   2,   2,
                          4,    4,   4,   4,   4,   4,   2,   4,   4,   4,   4,   2,   2,
                          4,    4,   4,   4,   4,   4,   2,   4,   4,   4,   4,   2,   2,   1
    
    index         VAR     Byte
    
    offset        VAR     Nib
    
    noteLetter    VAR     Byte
    
    noteFreq      VAR     Word
    
    noteDuration  VAR     Word
    
    noteOctave    VAR     Nib
    
    
    
    DO UNTIL noteLetter = "Q"
    
      READ Notes + index, noteLetter
            DEBUG"  ", noteletter
    
    
    
      LOOKDOWN noteLetter, [  "C",  "d",  "D",  "e",  "E",
    
                              "F",  "g",  "G",  "a",  "A",
    
                              "b",  "B",  "R",  "Q"     ], offset
    
    
    
      LOOKUP offset,        [ 4186, 4435, 4699, 4978, 5274,
    
                              5588, 5920, 6272, 6645, 7040,
    
                              7459, 7902,    0,    0     ], noteFreq
            DEBUG "       ", DEC4 noteFreq
    
    
    
      READ Octaves + index, noteOctave
    
      noteOctave = 8 - noteOctave
    
      noteFreq = noteFreq / (DCD noteOctave)
    
    
    
      READ Durations + index, noteDuration
    
      noteDuration = 1000 / noteDuration
    
    
    
      FREQOUT 8, noteDuration, noteFreq
    
    
    
      index = index + 1
    
         Display_Color:                                   ' Subroutine label
    
      LOW 15: LOW 14: LOW 13: LOW 12: LOW 11         ' Turn LEDs off
    
      SELECT noteLetter
    
        CASE "A", "a"
    
          HIGH 15
    
        CASE "B", "b"
    
          HIGH 14
    
        CASE "C", "c"
    
          HIGH 13
    
        CASE "D", "d"
    
          HIGH 12
    
        CASE "E", "e"
    
          HIGH 11
    
        CASE "F", "f"
    
          HIGH 15
    
          HIGH 13
    
          HIGH 11
    
        CASE "G", "g"
    
          HIGH 14
    
          HIGH 12
    
       ENDSELECT
    
    RETURN
    
    LOOP
    
    END
    

    By the way, welcome to the forums.
  • ercoerco Posts: 20,256
    edited 2014-12-02 08:49
    Good man, Brendon O. Welcome to the forums, keep those cards & projects coming! :)
Sign In or Register to comment.