AdmiralCrunch
Well-known member
Hi
I have asked a while ago about how to mux encoders. someone pointed me to this solution
https://forum.pjrc.com/threads/5100...o-expander-16x?p=175635&viewfull=1#post175635
..which worked perfectly as I can remember.
I had to pause my for a while and now I got back to work.. but this solution reads me
0
1
or
0
-1
.. when muxing a encoder through two 4051s.
(when I connect the encoder directcly to the teensy, everything works well)
this is my code now:
can someone see the problem, why I only get 0,1,0,-1 ?
I have asked a while ago about how to mux encoders. someone pointed me to this solution
https://forum.pjrc.com/threads/5100...o-expander-16x?p=175635&viewfull=1#post175635
..which worked perfectly as I can remember.
I had to pause my for a while and now I got back to work.. but this solution reads me
0
1
or
0
-1
.. when muxing a encoder through two 4051s.
(when I connect the encoder directcly to the teensy, everything works well)
this is my code now:
Code:
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
#define inhibit 29
#define A 30
#define B 31
#define C 32
#define encodersA 8
#define encodersB 9
Encoder myEnc[8] = {
Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB),
Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB), Encoder(encodersA, encodersB)
};
long position[8] = {
-999, -999, -999, -999, -999, -999, -999, -999
};
uint8_t encIncNum[8] = {
0, 1, 2, 3, 4, 5, 6, 7
};
void setup() {
// put your setup code here, to run once:
pinMode(inhibit, OUTPUT);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
Serial.begin(9600);
while ( !Serial && (millis() < 4000) ) {
Serial.println("LOADING SERIAL PORT ...");
}
}
uint8_t i = 0;
void loop() {
readInputs(i);
i++;
if(i >= 0) { // only one encoder connected so far, all other 4051-inputs wired to GND
i = 0;
}
}
void selectAddress(uint8_t a) {
digitalWrite(inhibit, HIGH);
digitalWrite(A, a & 0x1);
digitalWrite(B, (a >> 1) & 0x1);
digitalWrite(C, (a >> 2) & 0x1);
digitalWrite(inhibit, LOW);
}
void readEnc(uint8_t enc) {
long newPos = myEnc[enc].read();
if (newPos != position[enc]) {
position[enc] = newPos;
Serial.println(position[enc]);
myEnc[enc].write(0);
}
}
void readInputs(uint8_t i) {
selectAddress(i);
delayMicroseconds(50);
readEnc(i);
}
can someone see the problem, why I only get 0,1,0,-1 ?