While in loop I'm consistently getting "0" from millis().
Here's my sketch:
volatile bool pinChanged = false;
volatile uint32_t pinLog[64];
volatile uint8_t pinLogPos = 0; // where next write should go
void pinCB() {
pinChanged = true;
}
void setup() {
SerialUSB.begin(9600);
while (! SerialUSB) {} // wait for serial monitor to attach
SerialUSB.println("------------- BOOTED");
SerialUSB.println(millis());
pinMode(13, OUTPUT);
pinMode(9, INPUT_PULLDOWN);
attachInterrupt(9, pinCB, CHANGE);
}
void loop() {
if (pinChanged) {
pinChanged = false;
pinLog[pinLogPos] = millis();
pinLogPos++;
digitalWrite(13, digitalRead(9));
if (pinLogPos > 8) {
for (uint8_t i = 0; i < pinLogPos; i++) {
SerialUSB.print(pinLog[pinLogPos]);
SerialUSB.print(" ");
}
SerialUSB.println("");
pinLogPos = 0;
}
}
}
This is what I see after attaching the serial monitor and bringing pin 9 high about 4 times:
------------- BOOTED
15170
0 0 0 0 0 0 0 0 0
What might I be doing wrong?