So I’m trying to make a remote controlled car. It will consist of a raspberry pi connected via serial to the arduino. You control it by VNC into the raspberry pi and then sending the commands to arduino. This is the code I have for recognizing commands and acting on the ones that affect the servo. I am using the servo to turn the wheels to change directions, however the servo doesn’t turn a uniform distance when a add 45 to its position. Here’s the code:
#include <Servo.h>
Servo myservo;
int servoPin = 3;
int potVal = 500;
void setup() {
myservo.attach(servoPin);
Serial.begin(115200);
Serial.println();
}
void loop(){
if (Serial.available()) {
String data = Serial.readString();
data.trim();
if (data == "Hello!!") {
Serial.println ("Hi, I'm ready!");
}
if (data == "Left") {
potVal = potVal - 45;
Serial.println (potVal);
}
if (data == "Right") {
potVal = potVal + 45;
Serial.println (potVal);
}
if (data == "TakePic") {
Serial.println ("Here's your picture!");
}
if (data == "IncSpeed") {
Serial.println ("Increasing Speed!");
}
if (data == "DecSpeed") {
Serial.println ("Decreasing Speed!");
}
// potVal = map(potVal, 0, 1023, 0, 45);
myservo.write(potVal);
}
}