Project Шайба
https://petrovs.info/post/2023-01-12-shaiba/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
2 years ago
|
/* Project Shaiba (c) 2023 Blagovest Petrov <blagovest@petrovs.info>
|
||
|
* https://petrovs.info/post/2023-01-12-shaiba/
|
||
|
* Used https://www.instructables.com/Interface-a-rotary-phone-dial-to-an-Arduino/ for a reference.
|
||
|
* Hardware:
|
||
|
* OLIMEXINO-85-ASM ( https://www.olimex.com/Products/Duino/AVR/OLIMEXINO-85-ASM/open-source-hardware )
|
||
|
* Old rotary dialer from auction.
|
||
|
* A lot of insulating tape :)
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include "DigiKeyboard.h"
|
||
|
|
||
|
#define IMPULSE_PIN 2
|
||
|
//Those values may be different for different encoders!
|
||
|
#define TIME_TO_FINISH 100
|
||
|
#define DEBOUNCE_DELAY 10
|
||
|
|
||
|
int needToPrint = 0;
|
||
|
int count;
|
||
|
int lastState = LOW;
|
||
|
int trueState = LOW;
|
||
|
unsigned long lastStateChangeTime = 0;
|
||
|
int cleared = 0;
|
||
|
|
||
|
void setup() {
|
||
|
pinMode(IMPULSE_PIN, INPUT);
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
int reading = digitalRead(IMPULSE_PIN);
|
||
|
|
||
|
if ((millis() - lastStateChangeTime) > TIME_TO_FINISH) {
|
||
|
// the dial isn't being dialed, or has just finished being dialed.
|
||
|
if (needToPrint) {
|
||
|
// if it's only just finished being dialed, we need to send the number down the serial
|
||
|
// line and reset the count. We mod the count by 10 because '0' will send 10 pulses.
|
||
|
if (count > 10) { count = 1; }
|
||
|
DigiKeyboard.print(count - 1);
|
||
|
needToPrint = 0;
|
||
|
count = 0;
|
||
|
cleared = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (reading != lastState) {
|
||
|
lastStateChangeTime = millis();
|
||
|
}
|
||
|
if ((millis() - lastStateChangeTime) > DEBOUNCE_DELAY) {
|
||
|
if (reading != trueState) {
|
||
|
|
||
|
trueState = reading;
|
||
|
if (trueState == HIGH) {
|
||
|
// increment the count of pulses if it's gone high.
|
||
|
count++;
|
||
|
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
lastState = reading;
|
||
|
}
|