-
Notifications
You must be signed in to change notification settings - Fork 1
/
arduino reads phone code.txt
101 lines (73 loc) · 3.59 KB
/
arduino reads phone code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Thanks to LIANA, with help from NAIM, who produced the prototype for our project's code with some borrowed code from ARDUINO EXAMPLES,
we found her work online @ http://www.instructables.com/id/How-to-turn-an-old-school-rotary-phone-into-an-inp/
LIANA's Instructables Blog provided invaluable tips and advice for how to take apart our rotary phone, how to connect it to Arduino,
and the basic mechanisms and processes at work when converting an old rotary phone into a device like ours
This code needs to be installed on an Arduino device
This code turns the analog signal recieved from an analog input device (in our case a rotary telephone) into a digital signal
This is only half of the code needed to run this project, you will still need to run Processing and have Arduino talk with it in order to run this program fully
Rotary Phone Dial Reader
This sketch reads out the number dialed on a rotary phone dial.
The rotary dial has two signals:
1) turns ON when the wheel is turning
2) pulses a count based on the number dialed.
The results are printed to the serial monitor.
The circuit:
* ON/OFF "switch" wires attached from PIN 12 to GND
* PULSE wires attached from PIN 11 to GND
Since it's readong an analog signal, there's a bit of "bounce" in each pulse.
The code adjusts for that using the "debounce" method. You can adjust the
amount of delay in "debounceDelay" if you get read errors.
Made by LIANA, with help from NAIM, with some borrowed code from ARDUINO EXAMPLES.
2014 Feb 13
*/
#define INITPIN 12
#define NUMPIN 11
int counter; // holds the pulse count for each dial spin
int currentValue = 0;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 5; // the debounce time; increase if the output flickers
void setup(){
//start serial connection
Serial.begin(9600);
// configure the two inputs, and the onboard LED.
pinMode(INITPIN, INPUT_PULLUP);
pinMode(NUMPIN, INPUT_PULLUP);
}
void loop(){
int initRead = digitalRead (INITPIN); // Is the wheel turning or not?
static int lastValue = HIGH; // holds the last read from the pulse pin.
if (initRead == LOW) { // If the wheel is turning....
int newValue = digitalRead (NUMPIN); // check the pulse pin.
if (newValue != lastValue) { // if it's CHANGED from the last read...
lastDebounceTime = millis(); // save its clock cycle; we need to check it.
}
// If enough time has passed (aka, it's not just a "bounce" from the
// analog signal)...
if ((millis() - lastDebounceTime) > debounceDelay) {
// and if the current value is DIFFERENT than the one you just read...
if (currentValue != newValue) {
currentValue = newValue; // make them the same.
if (newValue == 1) { // If you just set it to a 1...
counter++; // it just finished a pulse, so add one to the counter.
}
}
}
lastValue = newValue; // Your new value becomes the old one for comparison.
} else {
// once the dial returns home and switches the initializing pin OFF,
// you can be sure that there will be no more pulses coming.
// "Counter" is the number dialed. You may now use it for whatever you want.
// This is adjusted for the special case of "0" actually being 10 pulses.
if (counter > 0) {
if (counter == 10) {
Serial.println (0);
} else {
Serial.println (counter);
}
}
// After you're done using it, reset counter so it can start again on the
// next dial.
counter = 0;
}
}