#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int dialPin = 2; // Pin connected to DIAL on the rotary dialer
const int pulsePin = 3; // Pin connected to PULSE on the rotary dialer
int currentDigit = 0;
bool dialing = false;
bool dialFinished = false;
String dialedNumber = "";
void setup() {
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.display();
// Initialize dialer pins as input
pinMode(dialPin, INPUT_PULLUP);
pinMode(pulsePin, INPUT_PULLUP);
Serial.begin(9600); // For debugging purposes
Serial.println("Hello! Welcome to the unofficial Dialer project.");
Serial.println("Check diagram.json to see the Part ID of the Dialer.");
Serial.println("Check the description for other informations.");
}
void loop() {
// Check if the dialer is in use
if (digitalRead(dialPin) == LOW) {
if (!dialing) {
dialing = true;
currentDigit = 0; // Reset digit count
}
}
// Count the pulses while dialing
if (dialing) {
if (digitalRead(pulsePin) == LOW) {
delay(10); // Debounce delay
while (digitalRead(pulsePin) == LOW); // Wait for pulse end
currentDigit++;
delay(10); // Debounce delay
}
// If dial pin goes high, dialing is finished
if (digitalRead(dialPin) == HIGH) {
dialFinished = true;
dialing = false;
}
}
// Print the dialed number when finished
if (dialFinished) {
int digit = currentDigit % 10;
dialedNumber += String(digit);
display.clearDisplay();
display.setCursor(0, 0);
display.print(dialedNumber);
display.display();
dialFinished = false;
}
}
/*
Serial.println("Hello! Welcome to the unofficial Dialer project.");
Serial.println("Check diagram.json to see the Part ID of the Dialer.");
Serial.println("Check the description for other informations.");
*/