It works fine on the Arduino IDE, but always returns an error on TinkerCad, where i am required to submit my task. I tried changing the return type of the functions, as always, compiles on the Arduino IDE but not on Tinkercad, it also highlights the #define lines. Below the parts that throw and error.
enum Motions{forward, backward, right, left}; // will be used as direction too, forward: upward,
//backward: downward
Motions direction = right; //assuming the robot is facing left at the starting position
int x = 0, y = 0;
Motions rotate_cw(){
switch(direction){
case forward: return right;
break;
case right: return backward;
break;
case backward: return left;
break;
case left: return forward;
break;
}
}
Motions rotate_ccw(){
switch(direction){
case forward: return left;
break;
case left: return backward;
break;
case backward: return right;
break;
case right: return forward;
break;
}
}
void loop() {
if(!digitalRead(forward_button)){
move(forward);
print_location(forward);
}
else if(!digitalRead(backward_button)){
move(backward);
print_location(backward);
}
else if(!digitalRead(right_button)){
move(right);
direction = rotate_cw();
}
else if(!digitalRead(left_button)){
move(left);
direction = rotate_ccw();
}
}```
New contributor
Mina Salama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.