Let's Make Robots!

My first picaxe code

* UPDATED: CODE                          *

Hello! I have 2 years exprience in programming before i doned this.
Now i show this to you because i want to know does it work.
Sensor thingy is my own maked i tell more later.
I debugged the code and it worked. It uses Tri-state motor controlling, check nuumio's tip about it!



'Obstacle avoider with sound

symbol sensor = 4 'sensor pin

symbol turn = 1200 'how much to turn

symbol speaker = 2 'speaker pin

symbol motorR = 1 'right motors pin

symbol motorL = 0 'left motors pin

symbol light = b1 


tune speaker, 4,($40,$42,$80,$44,$46,$04,$04,$04) 'play starting tune



'start motors

high motorR

high motorL

readadc sensor,light 'reads sensor

if light < 100 then goto main

'if light high = detects object 



low motorR

low motorL

'motors low

tune speaker, 3,($00,$02,$00,$02,$00) 

dirs = %00000011

'go backwards and play sound

pause 1000 '1 second

high motorL 'then turn to right

pause turn '1,2 seconds

goto main 'go back to main



There it was,hope it works!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You seem to only have 2 pins going to your motor driver. This will not work unless you are using some kind of extra chip somewhere. What motor driver are you using and how do you have it connected?

Your main loop is not a loop --there is no "goto main" and thus, the code is going to do the main routine only once, then continue on to the avoid loop no matter what. The "dirs = %00000000" should not be in the middle of the code.

What happened when you ran this on your chip?

Tri state motor controlling

The other problems still exist. Did this compile? What happened when you ran it on your chip?

I forgot that "else goto main" And i fix it today

Instead of:

if light > 100 then goto avoid

'if light high = detects object 

else goto main


you could just put:

if light <=100 then goto main

and do away with the else statement. If light > 100 it will naturally progress to your avoid subroutine. Just a thought.

Okay i didnt know that is better way.