Hi all!
I hooked up a 74HCT4051 to my arduino and teensy. My test setup (picture below) works perfectly with my arduino uno.
When I connect it te same way (same pins) to my teensy, it get 'floaters'. There should appear one 0 on my serial terminal but 3 appear.
I followed roughly this page: https://www.pjrc.com/teensy/td_midi.html
I've tried multple 74HCT4051's - all different floaters.
The code:
I hooked up a 74HCT4051 to my arduino and teensy. My test setup (picture below) works perfectly with my arduino uno.
When I connect it te same way (same pins) to my teensy, it get 'floaters'. There should appear one 0 on my serial terminal but 3 appear.
I followed roughly this page: https://www.pjrc.com/teensy/td_midi.html
I've tried multple 74HCT4051's - all different floaters.
The code:
Code:
const int selectPins[3] = {10, 11, 12}; // S0~2, S1~3, S2~4
const int zInput = 9; // Connect common (Z) to A0 (analog input)
void setup()
{
Serial.begin(9600); // Initialize the serial port
// Set up the select pins as outputs:
for (int i=0; i<3; i++)
{
pinMode(selectPins[i], OUTPUT);
digitalWrite(selectPins[i], HIGH);
}
pinMode(zInput, INPUT_PULLUP); // Set up Z as an input
// Print the header:
Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7");
Serial.println("---\t---\t---\t---\t---\t---\t---\t---");
}
void loop()
{
// Loop through all eight pins.
for (byte pin=0; pin<=7; pin++)
{
selectMuxPin(pin); // Select one at a time
int inputValue = digitalRead(zInput); // and read Z
Serial.print(String(inputValue) + "\t");
delay(100);
}
Serial.println();
delay(500);
}
// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectMuxPin(byte pin)
{
for (int i=0; i<3; i++)
{
if (pin & (1<<i))
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}