This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Between reading, looking at others' work and asking for help... I'm hoping to take this very simply application to the next step.
I am currently able to capture each number as I dial them with an old rotary phone dial. Each value is printed to serial and, when #5 is dialed, an LED is lit until a new number is dialed.
What I don't know how to do is to have it listen for a combination of numbers and take an action. Let's say I want to dial 34 and light a light but not have it light for just 3 or 4. In fact, I'd really like to be able to register a set of numbers, like a phone directory, for different actions but am trying to take a baby steps iterative approach.
I'm not trying to make it overly complex so I can learn along the way. Thank you if you have any help or feedback. Most of this is based on an Arduino rotary dial tutorial.
int needToPrint = 0;
int count;
int dialPin = 2;
int lastState = LOW;
int trueState = LOW;
long lastStateChangeTime = 0;
int cleared = 0;
int ledPin = 12; // LED pin for indication
// Constants
const int dialHasFinishedRotatingAfterMs = 100;
const int debounceDelay = 20;
void setup() {
Serial.begin(9600);
pinMode(dialPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int reading = digitalRead(dialPin);
if ((millis() - lastStateChangeTime) > dialHasFinishedRotatingAfterMs) {
if (needToPrint) {
if (count >= 1 && count <= 10) {
Serial.print("Number ");
Serial.println(count);
}
// Check if the detected number is 5
if (count == 5) {
digitalWrite(ledPin, HIGH); // Turn on the LED on pin 12
} else {
digitalWrite(ledPin, LOW); // Turn off the LED on pin 12 for other numbers
}
needToPrint = 0;
count = 0;
cleared = 0;
}
}
if (reading != lastState) {
lastStateChangeTime = millis();
}
if ((millis() - lastStateChangeTime) > debounceDelay) {
if (reading != trueState) {
trueState = reading;
if (trueState == HIGH) {
count ;
needToPrint = 1;
}
}
}
lastState = reading;
}
Subreddit
Post Details
- Posted
- 10 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/arduino/com...