#define PWM_A_PIN 5
#define PWM_B_PIN 10
#define IN_A_PIN 6
#define IN_B_PIN 9
#define R_BASE 100
#define L_BASE 50
void setup(){
Serial.begin(9600);
line.begin(true);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
void loop(){
turn('l', constrain(L_BASE + speedUpdate, -L_BASE, L_BASE));
turn('r', constrain(R_BASE - speedUpdate, -R_BASE, R_BASE));
}
void turn(char direction, int16_t speed){
// Serial.println(String(direction)+" "+String(speed));
bool speedNegative = (speed < 0);
if (direction == 'l'){
analogWrite(PWM_A_PIN, speedNegative*255 + speed);
digitalWrite(IN_A_PIN, speedNegative);
} else
if (direction == 'r'){
analogWrite(PWM_B_PIN, speedNegative*255 + speed);
digitalWrite(IN_B_PIN, speedNegative);
}
}