Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

0
Back to an old project with a rotary dial
Post Body

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;
}

Author
Account Strength
70%
Account Age
3 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,989
Link Karma
1,529
Comment Karma
3,395
Profile updated: 6 days ago
Posts updated: 5 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 months ago