Instructables

Hack the Snap Circuits Rover

Featured

Step 6: Program the Robot

Picture of Program the Robot
rbotprogpic.JPG
rbotcomplete.JPG
To create a new flowchart, in the Programming editor click File and then click New Flowchart to start entering your flowchart.. Use my example flowchart to make your own flowchart.

I’ve divided up each function into columns to make the flowchart easier to read. In the first column under “start” is a command to pause for 5000 miliseconds so once you switch the robot on, it will wait five seconds before proceeding through the motor tests. In the second column under the "Forward" lable are the commands to test the robot’s left forward motion. Under the "Backward" label are the commands to test the robot's backward motion. Under the label “Left Turn” are the commands to turn the robot left. And under the label "Right Turn are the commands to turn the robot right.

You can also convert the flowchart into BASIC program code. Click Flowchart and then click Convert Flowchart to BASIC. The following is what the code will look like in BASIC (I added the comments in the code to describe what the code does):

'BASIC converted from flowchart:
'C:\Documents and Settings\Desktop\dancebot.cad
'Converted on 9/9/2012 at 08:41:37

main:
  pause 5000           'Wait five seconds before proceeding
label_C1:                 'begin loop
                                   'FORWARD
  high 0                     'switch left forward motor on
  high 2                     'switch right forward motor on
  pause 500             'Wait .5 seconds before proceeding
  low 0                       'switch left forward motor off
  low 2                       'switch right forward motor off
                                   'BACKWARD
  high 1                      'switch left backward motor on
  high 4                      'switch right backward motor on
  pause 500              'Wait .5 seconds before proceeding
  low 1                        'switch left backward motor off
  low 4                        'switch right backward motor off
                                    'RIGHT
  high 0                      'switch left forward motor on
  high 4                      'switch right backward motor on
  pause 500              'Wait .5 seconds before proceeding
  low 0                        'switch left forward motor off  
  low 4                        'switch right backward motor off
                                    'LEFT
  high 1                      'switch left backward motor on                      
  high 2                      'switch right forward motor on
  pause 500              'Wait .5 seconds before proceeding
  low 1                        'switch left backward motor off
  low 2                        'switch right forward motor off
  goto label_C1       ' end loop

The code is very simple but should demonstrate how easy it is to program the robot.

To run the program, make sure the Snap Circuits Slide Switch S1 is switched off else the left motor might turn while the program is still downloading to the PICAXE and may accidentally disconnect the programming cable as the robot to turn right. Next, make sure that the Snap Circuits 9 volt Battery Block B5 is switched on or the program will not download to the PICAXE. Connect the Snap Circuits USB Programming Cable to your computer.

1.  Connect the orange snap to the S-In snap on the 8 Pin Socket U14 block (the PICAXE chip carrier).

2.  Connect the yellow snap to the S-Out snap on the 8 Pin Socket U14 block (the PICAXE chip carrier).

3.  Connect the black snap to the GND, or negative (-) snap on the 8 Pin Socket U14 block (the PICAXE chip carrier).

In the Programming Editor click PICAXE and then click Program. A status bar will display to show the progress of the download of the program to the PICAXE.

Wait a moment after the program finished downloading and disconnect the programming cable.

To save the program in the PICAXE memory, place the optional single snap on the S-In snap of the PICAXE block and connect the optional 100 Ohm Resistor R1 between S-In and GND (see picture 3).

Place the robot on the floor a safe distance from any obstacles. Then switch the Snap Circuits Slide Switch S1 to on. When you are ready to watch the motor tests, switch on the Snap Circuits 9 volt Battery Block B5 and watch the robot perform the motor tests.
 
Remove these adsRemove these ads by Signing Up