Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
#define RIGHT_ENC_PIN 2#define LEFT_ENC_PIN 3volatile unsigned int rightEncoder = 0;volatile unsigned int leftEncoder = 0;void setup() { pinMode(RIGHT_ENC_PIN, INPUT); pinMode(LEFT_ENC_PIN, INPUT); attachInterrupt(0, doEncoderRight, RISING); // encoder pin on interrupt 0 - pin 2 attachInterrupt(1, doEncoderLeft, RISING); // encoder pin on interrupt 1 - pin 3 // digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor// pinMode(encoder0PinB, INPUT); // digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor Serial.begin (9600); Serial.println("start"); // a personal quirk} void loop(){// do some stuff here - the joy of interrupts is that they take care of themselves//Serial.println("Hello"); Serial.print(rightEncoder, DEC); Serial.print(","); Serial.println(leftEncoder, DEC);}void doEncoderRight(){ rightEncoder++;}void doEncoderLeft(){ leftEncoder++;}