// https://forum.arduino.cc/t/converting-2-digit-multiplexed-7-segment-led-signal-to-128-x-64-oled-using-arduino-nano/1129222
// https://wokwi.com/projects/365887839415838721
// https://docs.arduino.cc/hacking/software/PortManipulation
// https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
const byte ledPin = 7;
const byte interruptPin = 2;
volatile byte state = LOW;
unsigned char iGlag;
void setup() {
Serial.begin(115200);
Serial.println("breakfast oscilloscope v0.0\n");
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
DDRB &= 0b11100000; // inputs 8 to 12
PORTB |= 0b00011111; // weak pullup
}
// watch for either edge
// wait a bit and grab 8 - 12 inputs
// when you've seen both edges, print a report about them
// reset and repeat
// In this simulation, bouncing on the switch has been turned off!
// we do not expcet bouncing on the observed signals
unsigned char edgesSeen;
unsigned char portOnEdge[2]; // 0 - rising edge, 1 - falling edge
void loop() {
digitalWrite(ledPin, state);
if (iGlag) {
unsigned char onPortB = PINB;
iGlag = 0; // clear the flag
delayMicroseconds(15); // why not?
if (digitalRead(interruptPin)) {
portOnEdge[0] = PINB & 0b00011111;
}
else {
portOnEdge[1] = PINB & 0b00011111;
}
edgesSeen++;
}
if (edgesSeen >= 2) {
Serial.print("segments after clock rises ");
Serial.println(portOnEdge[0], BIN);
Serial.print("segments after clock fallls ");
Serial.println(portOnEdge[1], BIN);
Serial.println();
edgesSeen = 0;
}
}
void blink() {
state = !state;
iGlag = 1; // set the flag
}