diff options
Diffstat (limited to 'sketch_mar5a/sketch_mar5a.ino')
-rw-r--r-- | sketch_mar5a/sketch_mar5a.ino | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sketch_mar5a/sketch_mar5a.ino b/sketch_mar5a/sketch_mar5a.ino new file mode 100644 index 0000000..11de40e --- /dev/null +++ b/sketch_mar5a/sketch_mar5a.ino @@ -0,0 +1,46 @@ +// This pin is used to read data from the shift register (4021). +const uint8_t PISO_DATA_PIN = 5; + +// This pin should be connected to the clock pin used to advance output in the shift regitster (4021). +const uint8_t PISO_CLOCK_PIN = 4; + +// This pin should be connected to the data out of the flip-flop (4013). +const uint8_t DATA_READY_PIN = 3; + +// This pin is used to reset the state of the rotary dial board. +// It should be connected to the reset pin of the flip-flop (4013) and counter (4520). +const uint8_t RESET_PIN = 2; + +void setup() { + Serial.begin(9600); + pinMode(PISO_DATA_PIN, INPUT); + pinMode(PISO_CLOCK_PIN, OUTPUT); + pinMode(DATA_READY_PIN, INPUT); + pinMode(RESET_PIN, OUTPUT); +} + +void loop() { + if (digitalRead(DATA_READY_PIN)) { + Serial.println("Data ready from rotary dial circuit!!"); + + digitalWrite(PISO_CLOCK_PIN, LOW); + uint8_t data = 0; + for (int i = 0; i < 8; ++i) { + int bit = digitalRead(PISO_DATA_PIN); + data = (data << 1) | bit; + + digitalWrite(PISO_CLOCK_PIN, HIGH); + digitalWrite(PISO_CLOCK_PIN, LOW); + } + + //uint8_t data = shiftIn(PISO_DATA_PIN, PISO_CLOCK_PIN, MSBFIRST); + Serial.print("Number: "); + Serial.print(data, DEC); + Serial.print(", "); + Serial.println(data, BIN); + + digitalWrite(RESET_PIN, LOW); + digitalWrite(RESET_PIN, HIGH); + digitalWrite(RESET_PIN, LOW); + } +} |