/*
*
* https://docs.arduino.cc/language-reference/
* https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay/
*
*
*/
// Include the library code:
#include <LiquidCrystal.h>
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
#define INDIALPIN 3
#define PULSEPIN 2
boolean inDialPinLastState;
boolean pulsPinLastState;
byte counter = 0;
byte holdOff = 0; // countdown
// constants won't change. Used here to set a pin number:
const int ledPin = LED_BUILTIN; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 500; // interval at which to blink (milliseconds)
void setup() {
Serial.begin(115200);
Serial.println("System started");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// set the fixed text
lcd.setCursor(0, 0);
pinMode(INDIALPIN, INPUT_PULLUP);
pinMode(PULSEPIN, INPUT_PULLUP);
inDialPinLastState = digitalRead(INDIALPIN);
pulsPinLastState = digitalRead(PULSEPIN);
}
/*
* The dial has two wires
* DIAL : -----___________________________---------
* PULSE: -------__---__---__---__---__------------
*
* The Telephone loops the line so get a time from PULSE
* The user pick up the handset,
* so the phone goes off goes OFF_HOOK
* As it dials set holdOff and decrement on a timer tick
* after the dialing has stopped holdOff gets to 1 , emit count.
*
* DIAL : -----___________________________---------
* PULSE : -------__---__---__---__---__------------
* holdOff : -------__________________________----------
*/
void loop() {
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the difference
// between the current time and last time you blinked the LED is bigger than
// the interval at which you want to blink the LED.
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
// digitalWrite(ledPin, ledState);
if ( holdOff > 0 ){
holdOff += -1;
if ( holdOff == 1 ){
Serial.println("timeout:");
Serial.println(counter);
//lcd.print("_");
lcd.print(counter);
}
}
}
boolean inDialPinState = digitalRead(INDIALPIN);
boolean pulsPinState = digitalRead(PULSEPIN);
if (inDialPinState != inDialPinLastState) {
if (!inDialPinState) {
Serial.println("Start of dial");
counter = 0;
} else {
Serial.println("End of dial");
Serial.print("Dialed Digit - ");
Serial.println(counter);
if (counter) {
counter = counter % 10;
//lcd.print(counter);
}
} //end if
inDialPinLastState = inDialPinState;
} //end if
if (pulsPinLastState != pulsPinState) {
holdOff = 3;
if (!pulsPinLastState) {
counter++;
} // end if
Serial.println("pulsPinState - " + String(pulsPinState));
pulsPinLastState = pulsPinState;
}
}