'------------------------------------------------------------------------------------ '-------------Secratary Bot--------------------------------------------------- '----------Signs documents, plays songs-------------- '---------------------------------------------------------------------- ''' Credit of counter code for Impact Sound Sensor which my altered version is based off of goes to Jeff Li January 15, 2009 '''''''''''''''''''''''''''''http://wtcs.ca/wiki/index.php/Sound_Sensing_BoeBot ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. ' -----[ Variables ]---------------------------------------------------------- pulseCount VAR Byte ' FOR...NEXT loop counter. counter VAR Word ' Loop counter old3 VAR Bit ' Stores previous IN7. old5 VAR Bit ' Stores previous IN5. '--------------------==================Initialization===========================-------------------- counter = 1 ' Start alternate corner count. old3 = 0 ' Make up old values. old5 = 1 '=================================================================================================================== '============================================================================================================ PAUSE 2000 ' -----[ Main Routine ]------------------------------------------------------- Cmd VAR Byte LastDirection VAR Byte LastDirection = 0 DO GOSUB GetCmd IF (Cmd >0) THEN GOSUB EXECmd ENDIF PAUSE 500 IF (IN2 = 0) AND (IN4 = 0) THEN 'Center AND Down triggers GOSUB Stand_Still ELSEIF (IN0 = 0) THEN ' Left Trigger contacts GOSUB Lift_Pen PAUSE 500 ELSEIF (IN1 = 1) THEN ' Down Trigger contacts GOSUB Smiley PAUSE 500 ELSEIF (IN2 = 0) THEN ' Right Trigger contacts GOSUB Signature_1 PAUSE 500 ELSEIF (IN3 = 0) THEN ' Center Trigger contacts GOSUB Drop_Pen ELSEIF (IN4 = 0) THEN ' Up Trigger contacts GOSUB Smiley PAUSE 500 ELSE GOSUB Stand_Still ' Apply a forward pulse ENDIF ' and check again LOOP '-------------------------------------------------------------------------------------------------------------' ' -----[ Subroutines ]-------------------------------------------------------- Signature_1: PAUSE 1500 FOR pulseCount = 0 TO 5 PAUSE 10 PULSOUT 13, 750 PULSOUT 12, 650 PAUSE 20 NEXT FOR pulseCount = 0 TO 5 PAUSE 10 PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT FOR pulseCount = 0 TO 5 PAUSE 10 PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT FOR pulseCount = 0 TO 5 PAUSE 10 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT RETURN '-====================================================================================================================== '======================= I had to put the Musicc code in its own subroutine because once the bot was turned on '======================= it began to play the jingle. '====================================================Music Code via http://forums.parallax.com/forums/default.aspx?f=6&m=378167 Jingle_Bell: IF (IN1 = 0) THEN ' Down Trigger contacts GOSUB Jingle_Bells PAUSE 500 Jingle_Bells: Notes DATA "E", "E", "E", "E", "E", "E", "E", "G", "C", "D", "E", "F", "F", "F", "F", "F", "E", "E", "E", "E", "D", "D", "E", "D", "G", "E", "E", "E", "E", "E", "E", "E", "G", "C", "D", "E", "F", "F", "F", "F", "F", "E", "E", "E", "G", "G", "F", "D", "C", "Q" Octaves DATA 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 Durations DATA 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1 Dots DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 index VAR Byte offset VAR Nib noteLetter VAR Byte noteFreq VAR Word noteDuration VAR Word noteOctave VAR Nib noteDot VAR Bit DO UNTIL noteLetter = "Q" READ Notes + index, noteLetter LOOKDOWN noteLetter, [ "C", "D", "E", "F", "G", "Q" ], offset LOOKUP offset, [ 4186, 4698, 5274, 5588, 6272, 0 ], noteFreq READ Octaves + index, noteOctave noteOctave = 8 - noteOctave noteFreq = noteFreq / (DCD noteOctave) READ Durations + index, noteDuration noteDuration = 1000 / noteDuration READ Dots + index, noteDot IF noteDot = 1 THEN noteDuration = noteDuration * 3 / 2 FREQOUT 9, noteDuration, noteFreq index = index + 1 LOOP END 'End Music Rutine RETURN 'Return main routine ENDIF '=========================================================================== '======================================================================= Smiley: PAUSE 2000 FOR pulseCount = 0 TO 100 ' 360 spin PAUSE 10 PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT PAUSE 1000 ' lift pen FOR pulsecount = 0 TO 10 PULSOUT 15, 650 NEXT PAUSE 1000 FOR pulsecount = 0 TO 240 ' Back up PULSOUT 13, 650 PULSOUT 12, 850 NEXT PAUSE 1000 FOR pulsecount = 0 TO 60 ' turn left PULSOUT 13, 650 PULSOUT 12, 650 NEXT PAUSE 1000 ' drop pen FOR pulsecount = 0 TO 10 PULSOUT 15, 850 NEXT PAUSE 1000 ' lift pen FOR pulsecount = 0 TO 10 PULSOUT 15, 650 NEXT PAUSE 1000 FOR pulsecount = 0 TO 70 ' turn right PULSOUT 13, 850 PULSOUT 12, 850 NEXT PAUSE 1000 ' drop pen FOR pulsecount = 0 TO 10 PULSOUT 15, 850 NEXT PAUSE 1000 ' lift pen FOR pulsecount = 0 TO 10 PULSOUT 15, 650 NEXT PAUSE 1000 ' turn left FOR pulsecount = 0 TO 80 PULSOUT 13, 750 - pulsecount PULSOUT 12, 750 - pulsecount NEXT PAUSE 1000 ' turn left FOR pulsecount = 0 TO 120 PULSOUT 13, 750 + pulsecount PULSOUT 12, 750 - pulsecount NEXT PAUSE 1000 ' turn left FOR pulsecount = 0 TO 60 PULSOUT 13, 750 - pulsecount PULSOUT 12, 750 - pulsecount NEXT PAUSE 1000 ' lower pen to ground FOR pulsecount = 0 TO 10 PULSOUT 15, 850 NEXT PAUSE 2000 FOR pulsecount = 0 TO 18 ' small spin PAUSE 10 PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT PAUSE 1000 ' lift pen FOR pulsecount = 0 TO 10 PULSOUT 15, 650 NEXT RETURN Signature_2: PAUSE 1000 ' drop pen FOR pulsecount = 0 TO 10 PULSOUT 15, 850 NEXT PAUSE 1000 FOR pulsecount = 0 TO 30 ' Back up PULSOUT 13, 650 PULSOUT 12, 850 NEXT PAUSE 100 FOR pulsecount = 0 TO 30 ' Move forward PULSOUT 13, 850 PULSOUT 12, 750 NEXT FOR pulsecount = 0 TO 30 ' Move forward PULSOUT 13, 850 PULSOUT 12, 750 NEXT PAUSE 1000 ' lift pen FOR pulsecount = 0 TO 10 PULSOUT 15, 650 NEXT PAUSE 1000 ' lift pen FOR pulsecount = 0 TO 10 PULSOUT 15, 650 NEXT Stand_Still: ' Dont move PULSOUT 13,750 PULSOUT 12,750 PAUSE 20 RETURN Lift_Pen: 'lift pen from ground FOR pulseCount = 0 TO 10 PULSOUT 15, 650 PAUSE 20 NEXT RETURN Drop_Pen: 'lift pen from ground FOR pulseCount = 0 TO 10 PULSOUT 15, 850 PAUSE 20 NEXT RETURN Drop_Pen2: 'lift pen from ground FOR pulseCount = 0 TO 5 PULSOUT 15, 850 PAUSE 20 NEXT RETURN '=============================================================================================================== ' This code Was meant for a makeshift sound sensor hooked up through homecooked wiring though I altered it where necessary- '-to make it functional with the new sensor and to work in a loop with the switch. 'It seems like alot of this was dead weight since Jeff's sound sensor looked like it was reading in multiple levels 'in experimenting and watching the debugger I found that it read as 9, but never any more or less. 'WIth this knowledge I change the limits he set up to differentiate between by setting them all to 9 marked by--> (*****) '=============================================================================================================== GetCmd: LastVal VAR Byte equalWaitCounter VAR Word equalWaitCounter = 0 ShortFlashCounter VAR Word ShortFlashCounter = 0 clap VAR Bit Cmd = 0 LastVal = 10 TestStart: PAUSE 1 clap = IN5 IF (Clap = 0) THEN LOW 1 ELSE HIGH 1 ENDIF ' also other sencor set value ' irsec = IN6 IF (LastVal = clap) THEN IF (clap = 1) THEN IF (LastDirection = 1) THEN GOSUB Forward_Pulse ENDIF IF ( LastDirection = 2) THEN GOSUB Backward_pulse ENDIF ENDIF IF ( equalWaitCounter <150) THEN equalWaitCounter = equalWaitCounter+1 GOTO TestStart ELSE RETURN ENDIF ENDIF LastVal = clap IF (clap = 1) THEN equalWaitCounter = 0 GOTO TestStart ELSE DEBUG CR, "Cmd add ", DEC equalWaitCounter IF ( equalWaitCounter > 8) THEN Cmd = Cmd +1 ENDIF equalWaitCounter = 0 IF (Cmd < 7) THEN GOTO TestStart ENDIF ENDIF RETURN EXECmd: DEBUG CR, "Cmd = ", DEC Cmd '(******) IF (Cmd = 1) THEN LastDirection = 9 GOSUB Forward_Pulse ENDIF '========================================================================================= ' In changeing all these values to my guarnteed 9 then as long as the counter continued ' to sense Lastdirection AND add up IF (Cmd = 2) THEN ' LastDirection = 9 ' GOSUB Backward_pulse ' I was also able to notice that I could change the threshold in order to add more clap ENDIF ' commands. (I don't know if there is a limit to the number of clap commands ' IF (Cmd = 3) THEN ' LastDirection = 9 ' GOSUB Stop_pulse GOSUB Turn_Left ENDIF IF (Cmd = 4) THEN LastDirection = 9 GOSUB Stop_pulse GOSUB Turn_Right ENDIF IF (Cmd = 5) THEN LastDirection = 9 GOSUB Drop_Pen GOSUB Stand_Still ENDIF IF (Cmd = 6) THEN LastDirection = 9 PAUSE 20 GOSUB Drop_Pen2 PAUSE 20 GOSUB Signature_2 PAUSE 20 GOSUB Lift_Pen ENDIF IF (Cmd = 7) THEN LastDirection = 9 ''******************************************************************************************* GOSUB Stop_pulse ''******************************************************************************************* GOSUB Jingle_Bells ' Really interesting, When it ran the music code the bot stoped taking all commands ' after it finished playing. Also If I place it not last in the claps then it would ' automaticlly play when its # of claps was reached. I have no idea why?!?!?!?!?!?!? ' I just reset it after i played the tune ^_^ ENDIF ''******************************************************************************************* Cmd = 0 ''******************************************************************************************* RETURN '(******) '---------------------------- 'Forward_Pulse: ' PULSOUT 13, 850 ' PULSOUT 12, 650 'RETURN Forward_Pulse: FOR pulseCount = 0 TO 15 PAUSE 10 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT RETURN Turn_Left: FOR counter = 0 TO 30 PULSOUT 13, 650 PULSOUT 12, 650 NEXT RETURN Turn_Right: FOR counter = 0 TO 30 PULSOUT 13, 850 PULSOUT 12, 850 NEXT RETURN Backward_pulse: FOR counter = 0 TO 30 PULSOUT 13, 650 PULSOUT 12, 850 NEXT RETURN Stop_pulse: PULSOUT 13, 750 PULSOUT 12, 750 RETURN