unsigned long now;
unsigned int counter;
/* reserved for two-in-one version
const byte ledPins[numLeds] = {2, 3, 4, 5};
const byte buttonPins[numLeds] = {7, 8, 9, 10};
*/
const byte muxOutput = 12; // *input* for COM CD4067 output
# define NT 16 // up to... 16
# define RATE 177
void setup() {
Serial.begin(115200);
Serial.println("hi Mom!");
pinMode(13, OUTPUT);
pinMode(A5, INPUT_PULLUP);
DDRC |= 0xf; // A0 .. A3 outputs
pinMode(muxOutput, INPUT_PULLUP); // probably use a real resistor
}
void loop() {
// poor man's logic probe
digitalWrite(13, digitalRead(A5));
static unsigned long lastTime;
now = millis();
// loop rate - full processor attention here
// and throttled
if (now - lastTime < RATE) return;
lastTime = now;
// once per RATE milliseconds past here
Serial.print(counter), counter++;
Serial.print(" ");
Serial.print(inReader(), BIN);
Serial.println("");
}
unsigned int inReader()
{
unsigned int result = 0;
for (byte ii = 0; ii < NT; ii++) {
PORTC &= 0xf0;
PORTC |= ii;
//delay(200);
//Serial.println(digitalRead(muxOutput));
result <<= 1;
if (digitalRead(muxOutput) == HIGH) result |= 1;
}
return result;
}