;----------------------------------------------------- ; Nick Pennella ; Frank Fernandes ; 91.548 Lab 5 ; ; HandyCricket code to receive the distance to a target ; using a logochip with a Devantech sonar attached. ; the cricket will then move the sonar until it is approx. ; 7 inches from the nearest object in front of it ;------------------------------------------------------- global [ dist ] to workpl ;----------------------------------------- ;send the command to send the sonar ping ;----------------------------------------- bsend $180 ;----------------------------------------- ;receive the distance from the logochip ;----------------------------------------- setdist bsr 1 ;---------------------------------------------- ; if the distance is > 7(inches) move forward ; else if the distance is = 7(inches) stop ; else (the distance < 7(inches) move backward ;---------------------------------------------- ifelse dist > 7 [ thisway onfor 1] [ ifelse dist = 7 [off] [thatway onfor 1] ] ;------------------------------------------------- ;turn on the motor for whatever the length is on ;the return side ;------------------------------------------------- workpl end