Flatpack Walker with Sensor
Sunday, August 22nd, 2010As presented for the first time on FAB6, using a Sharp gp2y0a02 sensor the flatpack-walker just got a little bit smarter. As long as the distance sensor is triggered, the robot walks backwards.
The code is still pretty simple:
// avoid obstacles using Sharp G2P sensor on Analog 0
#include <Servo.h>
Servo frontservo,backservo;
char walkpattern[] = {60,100,100,100,100,60,60,60};
void setup(){
frontservo.attach(9);
backservo.attach(10);
}
void loop(){
for(int n=0;n<4;n++){
if(analogRead(0)>500){
frontservo.write(walkpattern[2*n]);
backservo.write(walkpattern[(2*n)+1]);
}
else{
backservo.write(walkpattern[2*n]);
frontservo.write(walkpattern[(2*n)+1]);
}
delay(200);
}
}












