PaulS:
With 4 motors, pins 3, 5, 6, and 11 are used. You can't then use pin 3 as an interrupt pin, too.
so how I dont use pin 3 as an interrupt?
and is this what you meant by changing the coder to a volatile?
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ);
AF_DCMotor motor2(2, MOTOR12_64KHZ);
AF_DCMotor motor3(3, MOTOR12_1KHZ);
AF_DCMotor motor4(4, MOTOR12_1KHZ);
const int pingPin = 19;
#define LEFT 0
#define RIGHT 1
volatile long coder[2] = {
0,0};
int lastSpeed[2] = {
0,0};
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
motor1.setSpeed(200); // Set the speed for the motors (255 is the maximum)
motor2.setSpeed(200);
motor3.setSpeed(200);
motor4.setSpeed(200);
attachInterrupt(LEFT, LwheelSpeed, CHANGE); //init the interrupt mode for the digital pin 2
attachInterrupt(RIGHT, RwheelSpeed, CHANGE); //init the interrupt mode for the digital pin 3
}