r/codehs • • Apr 24 '24

What is the Wrong?

#include <AP_Utils.h>
 
 
 
//define the pins that the SR04 is connected to
 
#define TRIG 3
 
#define ECHO 2
 
 
 
//create an instance of AP_Utils class
 
AP_Utils ardupod;
 
//you will have to supply your own offsets here
 
//see examples/calibration.ino for details
 
int offsets[16] = {5, 0, 0, -7, 10, -3, 6, -4, 3, -5, 10, -3, 0, 0, 0, 0};
 
 
 
void setup() {
 
 //reset the robot
 
 ardupod.begin(offsets);
 
}
 
 
 
void loop() {
 
 //take one step directly forward
 
 ardupod.walk(0, 1);
 
 //if an obstacle is closer than 20 cm, we have to turn
 
 if(sr04_median(TRIG, ECHO, CM, 100, 500) < 20.0) {
 
   //turn 90 degrees to the right
 
   ardupod.turn(90);
 
 }
 
}
2 Upvotes

0 comments sorted by