Basic Stamp Kit Project

Discussion in 'The Projects Forum' started by dbaker63, Apr 20, 2010.

  1. dbaker63

    Thread Starter New Member

    Mar 17, 2010
    6
    0
    I know this is probably way below the programming level of most of you but i am totally stuck! I am try to write a program that will display the ABC's on a 7 segment display(not all letters will work i know) and play the ABC song simultaneously.The problem is i dont know anything about music and my programming knowledge is basic at best. I have the 7 segment display part down. The music i am having a hard time with and getting both portions to work together. I am using:
    1 Basic Stamp kit from paralax
    stamp board
    7 segment display
    a push button
    pzieoelectric speaker
    associated wire/ resistors

    here is the program i have so far....
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    DEBUG "Program Running!"
    IF IN3 = 3 THEN
    Notes DATA "C","C","G","G","A","A","G","F","F","E","E",
    "D","D","D","C","G","G","F","F","F","E","E","A","G","G","G","F",
    "E","E","A","Q"
    Octaves DATA 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,7, 7, 7, 7, 7, 7
    Durations DATA 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4,
    8, 8, 8, 8, 2, 4, 4, 2, 2, 2, 4, 4, 2, 4, 4, 4, 2, 4, 4, 2
    Dots DATA 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
    0, 0, 0, 1, 0
    BeatsPerMin CON 200
    index VAR Byte
    offset VAR Nib
    noteLetter VAR Byte
    noteFreq VAR Word
    noteDuration VAR Word
    noteOctave VAR Nib
    noteDot VAR Bit
    wholeNote VAR Word
    wholeNote = 60000 / BeatsPerMin * 4
    DO UNTIL noteLetter = "Q"
    READ Notes + index, noteLetter
    LOOKDOWN noteLetter, [ "C", "d", "D", "e", "E",
    "F", "g", "G", "a", "A",
    "b", "B", "P", "Q" ], offset
    LOOKUP offset, [ 2093, 4435, 4699, 4978, 5274,
    5588, 3136, 6272, 6645, 7040,
    7459, 7902, 0, 0 ], noteFreq
    READ Octaves + index, noteOctave
    noteOctave = 8 - noteOctave
    noteFreq = noteFreq / (DCD noteOctave)
    READ Durations + index, noteDuration
    noteDuration = WholeNote / noteDuration
    READ Dots + index, noteDot
    IF noteDot = 1 THEN noteDuration = noteDuration * 3 / 2
    FREQOUT 5, noteDuration, noteFreq
    index = index + 1
    LOOP
    OUTH = %00000000 ' OUTH initialized to low.
    DIRH = %11111111 ' Set P8-P15 to all output-low.
    ' Digit:
    ' BAFG.CDE
    DO
    IF IN3 = 1 THEN
    OUTH = %11110101 ' A
    PAUSE 1000
    OUTH = %00110111 ' b
    PAUSE 1000
    OUTH = %01100011 ' C
    PAUSE 1000
    OUTH = %10010111 ' d
    PAUSE 1000
    OUTH = %01110011 ' E
    PAUSE 1000
    OUTH = %01110001 ' F
    PAUSE 1000
    OUTH = %11110110 ' g
    PAUSE 1000
    OUTH = %10010101 ' h
    PAUSE 1000
    OUTH = %10000100 ' I
    PAUSE 1000
    OUTH = %10000111 ' j
    PAUSE 1000
    OUTH = %00100011 ' L
    PAUSE 1000
    OUTH = %11010110 ' m
    PAUSE 1000
    OUTH = %00010101 ' n
    PAUSE 1000
    OUTH = %11100111 ' O
    PAUSE 1000
    OUTH = %11110001 ' P
    PAUSE 1000
    OUTH = %11111100 ' q
    PAUSE 1000
    OUTH = %00010001 ' r
    PAUSE 1000
    OUTH = %01110110 ' s
    PAUSE 1000
    OUTH = %00000111 ' u
    PAUSE 1000
    OUTH = %01110011 ' w
    PAUSE 1000
    OUTH = %10110101 ' x
    PAUSE 1000
    OUTH = %10110110 ' y
    PAUSE 1000
    OUTH = %11010011 ' z
    PAUSE 1000
    DIRH = %00000000 ' I/O pins to input,
    ' segments off.
    ENDIF
    LOOP

    ENDIF

    ANY help would be GREATLY appreciated! Thank you!
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Here's a hint:

    Code ( (Unknown Language)):
    1. '{$STAMP BS2}
    2. '{$PBASIC 2.5}
    3. DEBUG "Program Running!"
    4. IF IN3 = 3 THEN
    5.     Notes DATA "C","C","G","G","A","A","G","F","F","E","E",
    6.     "D","D","D","C","G","G","F","F","F","E","E","A","G","G","G","F",
    7.     "E","E","A","Q"
    8.     Octaves DATA 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
    9.     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,7, 7, 7, 7, 7, 7
    10.     Durations DATA 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4,
    11.     8, 8, 8, 8, 2, 4, 4, 2, 2, 2, 4, 4, 2, 4, 4, 4, 2, 4, 4, 2
    12.     Dots DATA 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
    13.     0, 0, 0, 1, 0
    14.     BeatsPerMin CON 200
    15.     index VAR Byte
    16.     offset VAR Nib
    17.     noteLetter VAR Byte
    18.     noteFreq VAR Word
    19.     noteDuration VAR Word
    20.     noteOctave VAR Nib
    21.     noteDot VAR Bit
    22.     wholeNote VAR Word
    23.     wholeNote = 60000 / BeatsPerMin * 4
    24.     DO UNTIL noteLetter = "Q"
    25.     READ Notes + index, noteLetter
    26.     LOOKDOWN noteLetter, [ "C", "d", "D", "e", "E",
    27.     "F", "g", "G", "a", "A",
    28.     "b", "B", "P", "Q" ], offset
    29.     LOOKUP offset, [ 2093, 4435, 4699, 4978, 5274,
    30.     5588, 3136, 6272, 6645, 7040,
    31.     7459, 7902, 0, 0 ], noteFreq
    32.     READ Octaves + index, noteOctave
    33.     noteOctave = 8 - noteOctave
    34.     noteFreq = noteFreq / (DCD noteOctave)
    35.     READ Durations + index, noteDuration
    36.     noteDuration = WholeNote / noteDuration
    37.     READ Dots + index, noteDot
    38.     IF noteDot = 1 THEN noteDuration = noteDuration * 3 / 2
    39. '
    40. ' ==> Insert code to output bits on P8-P15 here to light LEDs.  
    41. '     The FREQOUT command will provide the delay.
    42. '
    43.       FREQOUT 5, noteDuration, noteFreq
    44.     index = index + 1
    45.    LOOP
    46.    OUTH = %00000000 ' OUTH initialized to low.
    47.    DIRH = %11111111 ' Set P8-P15 to all output-low.
    48. ' Digit:
    49. ' BAFG.CDE
    50. DO
    51.   IF IN3 = 1 THEN
    52.     OUTH = %11110101 ' A
    53.     PAUSE 1000
    54.     OUTH = %00110111 ' b
    55.     PAUSE 1000
    56.     OUTH = %01100011 ' C
    57.     PAUSE 1000
    58.     OUTH = %10010111 ' d
    59.     PAUSE 1000
    60.     OUTH = %01110011 ' E
    61.     PAUSE 1000
    62.     OUTH = %01110001 ' F
    63.     PAUSE 1000
    64.     OUTH = %11110110 ' g
    65.     PAUSE 1000
    66.     OUTH = %10010101 ' h
    67.     PAUSE 1000
    68.     OUTH = %10000100 ' I
    69.     PAUSE 1000
    70.     OUTH = %10000111 ' j
    71.     PAUSE 1000
    72.     OUTH = %00100011 ' L
    73.     PAUSE 1000
    74.     OUTH = %11010110 ' m
    75.     PAUSE 1000
    76.     OUTH = %00010101 ' n
    77.     PAUSE 1000
    78.     OUTH = %11100111 ' O
    79.     PAUSE 1000
    80.     OUTH = %11110001 ' P
    81.     PAUSE 1000
    82.     OUTH = %11111100 ' q
    83.     PAUSE 1000
    84.     OUTH = %00010001 ' r
    85.     PAUSE 1000
    86.     OUTH = %01110110 ' s
    87.     PAUSE 1000
    88.     OUTH = %00000111 ' u
    89.     PAUSE 1000
    90.     OUTH = %01110011 ' w
    91.     PAUSE 1000
    92.     OUTH = %10110101 ' x
    93.     PAUSE 1000
    94.     OUTH = %10110110 ' y
    95.     PAUSE 1000
    96.     OUTH = %11010011 ' z
    97.     PAUSE 1000
    98.     DIRH = %00000000 ' I/O pins to input,
    99.     ' segments off.
    100.   ENDIF
    101. LOOP
    102.  
    103. ENDIF
    104.  
     
  3. ELECTRONERD

    Senior Member

    May 26, 2009
    1,146
    16
    One thing that might help you is learning to code by algorithms. Before you concoct your code, you need to write down in steps the order in which things occur. For example:

    MCU detects that Switch 1 (SW1) is ON ---> MCU turns ON LED for 1 second ---> MCU turns OFF LED for 1 second ---> LOOP

    Try making a series of algorithms for what you want to do, then see if your code corresponds to your original code.

    Austin
     
Loading...