Flatpack Walker with Sensor
As 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// 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); } } |
Write a Reply or Comment