Merry Christmas Robot
My son and I did a Christmas themed robot project for hack the halls. We used the BS2e controlled CBA robot, a SoundPal playing "The First Noel" while driving a circle around a Christmas tree decoration using a Ping))). The tree is decorated with my Propeller chip LED marque that says "Merry Christmas", and the star on the tree is an S2 robot badge. Here's the video:
Here's the code to load "The First Noel" on the SoundPal
The LED Marque is covered in this thread: http://forums.parallax.com/showthread.php?136152-LED-Marquee-Module-for-Gadget-Gangster-Platform-(w-video)
The software which makes the robot go in a circle around the tree is described here: http://forums.parallax.com/showthread.php?139096-Wall-Following-Examples-(video-and-code)
Here's the code to load "The First Noel" on the SoundPal
' ================================================== ======================= ' ' File...... SoundPALNoel.bs2 ' Purpose... Constants and Standard Subroutines for SoundPAL ' Author.... Parallax, Inc. ' E-mail.... support@parallax.com ' Started... 2007.05.01 ' Updated... 2007.10.29 ' ' {$STAMP BS2e} ' {$PBASIC 2.5} ' ' ================================================== ======================= ' -----[ Program Description ]--------------------------------------------- ' This is a blank template defining constants and subroutines that ' provide an interface to the Parallax SoundPAL (p/n 28825) Miniature ' Sound Player. ' -----[ I/O Definitions ]------------------------------------------------- iopin PIN 8 'Pin number used for communicaiton with SoundPAL. 'Change as needed. ' -----[ Constants ]------------------------------------------------------- baud CON $8000 + 84 'Communication baudrate is 9600 for BS2, BS2e, and BS2pe. reset CON $8000 + 813 'Reset baudrate is 1200 for BS2, BS2e, and BS2pe. 'See BASIC Stamp manual for settings with other Stamps. 'Commands play CON $01 'Play the segment at the following address ($01-$FF). repeat CON $02 'Begin a repeat block. ' Next arg is repeat count (1-254; 255 = endlessly). again CON $03 'End the repeat block. 'Playing styles marcato CON $04 'Normal, separated notes. staccato CON $05 'Very short notes. legato CON $06 'Connected notes. glissando CON $07 'Connected, sliding notes. 'Tempos tmp0 CON $08 'Quarter note = 133 beats/min. tmp1 CON $09 'Quarter note = 266 beats/min. (default) tmp2 CON $0A 'Quarter note = 532 beats/min. tmp3 CON $0B 'Quarter note = 1064 beats/min. 'Octaves oct0 CON $0C 'A_0 = 110Hz oct1 CON $0D 'A_0 = 220Hz oct2 CON $0E 'A_0 = 440Hz (default) oct3 CON $0F 'A_0 = 880Hz 'Slur or tie, connecting two subsequent notes only. slur CON $10 'Glissando rates: gl1 is fastest; gl15 is slowest. gl1 CON $11 gl2 CON $12 gl3 CON $13 gl4 CON $14 gl5 CON $15 gl6 CON $16 gl7 CON $17 gl8 CON $18 gl9 CON $19 gl10 CON $1A gl11 CON $1B gl12 CON $1C gl13 CON $1D gl14 CON $1E gl15 CON $1F 'Notes. When unmodified by addition of duration, these are all quarter notes. ZZZ CON $80 'Rest C_0 CON $81 'Low C natural. (Middle C in oct2.) Cs0 CON $82 'Low C sharp. Df0 CON $82 'Low D flat. D_0 CON $83 'Low D natural. Ds0 CON $84 'Low D sharp. Ef0 CON $84 'Low E flat. E_0 CON $85 'Low E natural. F_0 CON $86 'Low F natural. Fs0 CON $87 'Low F sharp. Gf0 CON $87 'Low G flat. G_0 CON $88 'Low G natural. Gs0 CON $89 'Low G sharp. Af0 CON $89 'Low A flat. A_0 CON $8A 'Low A natural. As0 CON $8B 'Low A sharp. Bf0 CON $8B 'Low B flat. B_0 CON $8C 'Low B natural. C_1 CON $8D 'Medium C natural. (Middle C in oct1.) Cs1 CON $8E 'Medium C sharp. Df1 CON $8E 'Medium D flat. D_1 CON $8F 'Medium D natural. Ds1 CON $90 'Medium D sharp. Ef1 CON $90 'Medium E flat. E_1 CON $91 'Medium E natural. F_1 CON $92 'Medium F natural. Fs1 CON $93 'Medium F sharp. Gf1 CON $93 'Medium G flat. G_1 CON $94 'Medium G natural. Gs1 CON $95 'Medium G sharp. Af1 CON $95 'Medium A flat. A_1 CON $96 'Medium A natural. As1 CON $97 'Medium A sharp. Bf1 CON $97 'Medium B flat. B_1 CON $98 'Medium B natural. C_2 CON $99 'High C natural. (Middle C in oct0.) Cs2 CON $9A 'High C sharp. Df2 CON $9A 'High D flat. D_2 CON $9B 'High D natural. Ds2 CON $9C 'High D sharp. Ef2 CON $9C 'High E flat. E_2 CON $9D 'High E natural. F_2 CON $9E 'High F natural. Fs2 CON $9F 'High F sharp. Gf2 CON $9F 'High G flat. 'Duration modifiers. Add value to note to change duration. s CON $20-$80 'Sixteenth note. e CON $40-$80 'Eighth note. de CON $60-$80 'Dotted eighth note. q CON $80-$80 'Quarter note. dq CON $C0-$80 'Dotted quarter note. h CON $A0-$80 'Half note. dh CON $E0-$80 'Dotted half note. 'Canned sound sequences, accessed via the "play" command. charge CON $40 'Charge! taps CON $44 'Taps reveille CON $5D 'Reveille firstpost CON $7D 'First Post (horse race bugle call) intro CON $8D 'Doo-doot doo doot doot DOOT nyah CON $93 'Nyah nyah nyah nyah NYAH nyah! dead CON $97 'Funeral dirge batthymn CON $9D 'Battle Hymn of the Republic dixie CON $A5 'Dixie cucaracha CON $AC 'La Cucaracha popweasel CON $AF 'Pop! Goes the Weasel marsell CON $B3 'Marsellaise rulebrit CON $B9 'Rule Brittania matilda CON $C0 'Walzing Matilda kradoucha CON $C6 'Kradoutcha ("There's a place in France...") wedding CON $CD 'Wedding March ode2joy CON $D2 'Ode to Joy dudu CON $DA 'Du, Du Liegst Mir im Herzen notme CON $E1 'Rude sound uhoh CON $E5 'Uh oh! siren CON $E8 'American style siren. Infinite loop: reset to exit. phone CON $EE 'Rings once. whistle CON $F3 'Wolf whistle. cricket CON $FA 'Play using oct3 for cricket; oct0 for frog. BPART CON 35 'EEPROM address of B section ' -----[ Initialization ]-------------------------------------------------- PAUSE 10 GOSUB DoReset ' -----[ Program Code ]---------------------------------------------------- ' Because working RAM is smaller than EEPROM we save the song in two sections GOSUB SaveAPart GOSUB SaveBPart GOSUB WaitDone ' Now play the song. SEROUT iopin, baud, ["=", play, 1, 0, "!"] END ' -----[ Subroutines ]----------------------------------------------------- '------[ SaveAPart ]-------------------------------------------------------- ' Save the A section to EEPROM and it requires 35 bytes SaveAPart: GOSUB WaitDone SEROUT iopin, baud, ["="] ' Loop the whole song 3 times SEROUT iopin, baud, [repeat, 3] '2 ' pickup notes SEROUT iopin, baud, [tmp0, e+E_0, e+D_0] '5 ' Loop the remaining A section SEROUT iopin, baud, [repeat, 2] '7 SEROUT iopin, baud, [dq+C_0, e+D_0, e+E_0, e+F_0, h+G_0, e+A_0, e+B_0] '14 SEROUT iopin, baud, [q+C_1, q+B_0, q+A_0, dq+G_0, e+ZZZ, q+A_0, q+B_0] '21 SEROUT iopin, baud, [q+C_1, q+B_0, q+A_0, q+G_0, q+A_0, q+B_0] '27 SEROUT iopin, baud, [q+C_1, q+G_0, q+F_0, h+E_0, e+E_0, e+D_0] '33 SEROUT iopin, baud, [again] '34 ' The B Section will get stored here. SEROUT iopin, baud, [again] '35 SEROUT iopin, baud, [0] '36 bytes SEROUT iopin, baud, ["#", 1] 'Save to EEPROM. RETURN '------[ SaveBPart ]-------------------------------------------------------- ' Save the B section to EEPROM and it requires 26 bytes SaveBPart: GOSUB WaitDone SEROUT iopin, baud, ["="] SEROUT iopin, baud, [dq+C_0, e+D_0, e+E_0, e+F_0, h+G_0, e+C_1, e+B_0] SEROUT iopin, baud, [dq+A_0, e+B_0, e+C_1, e+A_0, q+G_0, q+A_0, q+B_0] SEROUT iopin, baud, [q+C_1, q+B_0, q+A_0, q+G_0, q+A_0, q+B_0] SEROUT iopin, baud, [q+C_1, q+G_0, q+F_0, h+E_0] SEROUT iopin, baud, [again] SEROUT iopin, baud, [0] '26 byte SEROUT iopin, baud, ["#", BPART] 'Save to EEPROM. RETURN '------[ WaitDone ]-------------------------------------------------------- 'Wait for the SoundPAL to stop playing. WaitDone: SEROUT iopin, baud, ["?"] 'Send an enquiry. SERIN iopin, baud, 2, Waitdone,[WAIT($FF)] 'Wait 2msec for reply or try again. RETURN 'Reply received: return. '------[ DoReset ]--------------------------------------------------------- 'Reset the SoundPAL. DoReset: DO UNTIL iopin : LOOP 'Make sure SoundPAL is powered up. SEROUT iopin, reset, [0] 'Output 9 low bits at 1200 baud (i.e. a 7.5ms pulse). RETURN
The LED Marque is covered in this thread: http://forums.parallax.com/showthread.php?136152-LED-Marquee-Module-for-Gadget-Gangster-Platform-(w-video)
The software which makes the robot go in a circle around the tree is described here: http://forums.parallax.com/showthread.php?139096-Wall-Following-Examples-(video-and-code)
Comments
Looks like a winner for the Hack the Halls contest. :thumb:
-Tommy