'THERE ARE 6 SAMPLE PICAXE-08 ROBOT CONTROL PROGRAMS LISTED HERE ! 'JUST COPY ( BETWEEN === LINES) & PASTE ONE AT A TIME TO YOUR PICAXE EDITOR. '****************************************************************************** ' 'Picaxe-08 robot control program(s) -ref. Sept. 2004 "Silicon Chip". 'via Rev.Thomas Scarborough, Capetown, South Africa. '------------------------------------------------------------------ 'FIGURE-8 DEMO 'an accurate figure-8 depends on the degree of turn, see below 'this program could be simpler, but it is an EEPROM demo eeprom 0,(2,3,2,3,2,3,2,3,2,3,2,3,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,3) 'data 1=turn left, 2= straight, 3=turn right sound 1,(110,10) 'beep to confirm switch-on pause 500 'wait half a second main: low 0 'turn both motors off if b0=32 then finish 'when at the end of EEPROM terminate program read b0,b1 'transfer EEPROM value at location b0 to b1 b0=b0+1 'increment the EEPROM location b0 high 0 'turn on both motors if b1=1 then left 'if EEPROM data=1 turn left, using subroutine if b1=2 then straight 'if EEPROM data=2 go straight, using subroutine if b1=3 then right 'if EEPROM data=1 turn right, using subroutine goto main right: low 2 'left motor forwards high 4 'right motor backwards pause 500 ' for half a second ' this defines the degree of turn goto main left: high 2 'left motor backwards low 4 'right motor forwards pause 500 ' for half a second ' this defines the degree of turn goto main straight: low 2 'left motor forwards low 4 'right motor forwards pause 800 ' for 0.8 seconds goto main finish: pause 5000 'pause for five seconds sound 1,(110,10) 'reminder to switch off end 'just napping but not off '================================================================================ ' 'Picaxe-08 robot control program(s) -ref. Sept. 2004 "Silicon Chip". 'via Rev.Thomas Scarborough, Capetown, South Africa. '------------------------------------------------------------------ 'LDR TEST 'this adjusts VR1 to suit LDR1 and lighting conditions 'b3=160 when the LDR is directed at the darkest areas of a room 'aim for the widest variation in b3 as the LDR surveys a scene 'keep the jack plug inserted in the robot while taking readings main: readadc 1,b3 'read the light level debug b3 'display the light level on screen (watch b3) pause 100 'pause 0.1 seconds goto main 'repeat the procedure '================================================================================= ' 'Picaxe-08 robot control program(s) -ref. Sept. 2004 "Silicon Chip". 'via Rev.Thomas Scarborough, Capetown, South Africa. '------------------------------------------------------------------ 'LIGHT & BUMP DEMO 'before running this program, use the LDR ADJUST program to adjust VR1 pwm 1,21,30 'start-up beep 'PWM is used here to circumvent a ' potential SOUND/READADC conflict main: if pin3=1 then reverseout 'reverse if S1 bumper bar closes pause 2000 'pause for two seconds readadc 1,b1 'check light level directly in front gosub checkleft 'turn left, using subroutine readadc 1,b0 'check light level to the left gosub checkright 'turn right, using subroutine readadc 1,b2 'check light level to the right if b0127 then turnright 'turn random right goto turnleft ' or left, using subroutines goto main turnright: low 2 'left motor forwards high 4 'right motor backwards high 0 'turn both motors on pause 500 ' for half a second low 0 'turn both motors off pause 500 ' for half a second if b1>127 then tallyho 'drive random forwards goto backwards ' or backwards, using subroutines goto main turnleft: low 4 'right motor forwards high 2 'left motor backwards high 0 'turn both motors on pause 500 ' for half a second low 0 'turn both motors off pause 500 ' for half a second if b1>127 then tallyho 'drive random forwards goto backwards ' or backwards, using subroutines goto main tallyho: low 2 'left motor forwards low 4 'right motor forwards high 0 'turn both motors on pause 500 ' for half a second low 0 'turn both motors off goto main backwards: high 2 'left motor backwards high 4 'right motor backwards high 0 'turn both motors on pause 500 ' for half a second low 0 'turn both motors off goto main '========================================================================== ' 'Picaxe-08 robot control program(s) -ref. Sept. 2004 "Silicon Chip". 'via Rev.Thomas Scarborough, Capetown, South Africa. '------------------------------------------------------------------ 'WALTZING MATILDA DEMO 'this is useful for getting the robot going eeprom 0,(106,40,106,20,106,10,106,40,102,40) 'send waltzing matilda data to EEPROM pause 1000 'pause a second for effect main: gosub wiggle 'wiggle the robot, using subroutine pause 500 'pause half a second gosub waltzing 'play the first line of waltzing matilda 'this is useful for first testing a download gosub tallyho 'drive forwards, using subroutine sound 1,(100,10) 'indicate that the left wheel will reverse gosub aboutturn 'do an about-turn, using subroutine 'useful for establishing motor orientation pause 500 'pause half a second goto main 'repeat the sequence wiggle: gosub left 'turn left, using subroutine gosub right 'turn right, using subroutine gosub right 'turn further right, using subroutine gosub left 'turn left, using subroutine return 'return to where the main program left off tallyho: low 4 'right motor forwards low 2 'left motor forwards high 0 'turn both motors on pause 2000 ' for two seconds low 0 'turn both motors off return aboutturn: low 4 'right motor forwards high 2 'left motor backwards high 0 'turn both motors on pause 2200 ' for 2.2 seconds (or change this to suit motors) low 0 'turn both motors off return left: low 4 'right motor forwards high 2 'left motor backwards high 0 'turn both motors on pause 100 ' for 0.1 seconds low 0 'turn both motors off return right: low 2 'left motor forwards high 4 'right motor backwards high 0 'turn both motors on pause 100 ' for 0.1 seconds low 0 'turn both motors off return waltzing: for b0=0 to 9 step 2 'jump to every 2nd location in EEPROM read b0,b1 'copy data at location b0 to b1 b2=b0 'copy b0 to b2 b2=b2+1 'calculate the location following b0 read b2,b3 'copy the data at this location to b3 sound 1,(b1,b3) 'use b0 and b3 to set pitch and duration gosub staccato 'insert pauses after notes, using subroutine next b0 'jump to the next location in EEPROM return staccato: sound 1,(0,5) 'this inserts 5 milliseconds of silence return 'eeprom 10,(112,40,112,20,112,10,111,40,108,40) 'waltzing matilda second line, if needed 'eeprom 0,(95,20,95,20,98,40,95,40,103,40,101,40) 'eeprom 12,(95,20,95,20,98,40,95,40,106,40,103,40) 'happy birthday data, if needed '================================================================================