mjs513
Senior Member+
Ok all I am stumped. I picked up a pack of the Dagu Encoders (Hall Effect Sensor). Its has an input voltage range of 3-24v. So I hooked up Gnd to Gnd, Power to 3.3v and Signal to pin 2. Ok so far so good. I threw together a quick and dirty sketch:
Loaded it on a T4.1 and nothing - interrupt never fired, always got 0 readings. Oh hooked up an LA to pin 2 and it read high even when rotating the wheel over the sensor. So I pulled out an Arduino Uno and ran same sketch and it worked so what am I missing in setting up the interrupt or if that's ok what else could it be.
Code:
const int enc_l_pin = 2;
volatile unsigned long enc_l = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(enc_l_pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(enc_l_pin), countLeft, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long num_ticks_l;
enc_l = 0;
unsigned long enc_l_prev = enc_l;
while ( (enc_l < 20)) {
Serial.println(enc_l);
}
}
void countLeft() {
enc_l++;
}