Dial Telephone Display

Mar 20, 2013 by     Comments Off    Posted under: Roads & Rails Blog

We have added another display here at Roads and Rails. It is one not intimately connected to the railroads, but one that many people will enjoy, particularly children who have grown up in the wireless phone world.

In the course of refurbishing our building I came upon the 1970s era phone control box, filled with Ma Bell components. I managed to harvest 10 relays, mounted on plastic-coated metal circuit boards, and two of these are now in use controlling automatic stops and motion controlled displays on our train layout. Numerous useful connectors and terminal blocks were also extracted.

Also removed was this 10-position relay-incremented switch. It has 2 relays, one which advances the position of the switch, one which resets it back to position 1. Asked by our founder to turn this into a display for our visitors, I brought on the Arduino to do the job. I have used the Arduino before to run animations here at the museum, and decided this time to also purchase the Seeed Studio Relay Shield to speed up development. (Last time I did an Arduino project I built a board to hold 8 relays, 4 DPDT and 4 SPST.)

While this was not its original purpose, we decided to control the switch using a rotary dialer. It has been long enough now that our younger visitors have never operated a rotary dialer.

The user dials a number, which displays on the 7-segment LED and then advances to that position on the switch.

Here’s the code:

// 7 outputs to LED for 7-segment single digit display

int led1 = 6;

int led2 = 7;

int led3 = 8;

int led4 = 9;

int led5 = 10;

int led6 = 11;

int led7 = 12;

int val = 0;

int Clicks = 0;

int Clicks_Display = 0;

int WaitSeconds = 0;

int WaitMilliSeconds = 0;

// relays for move forward/set to zero

int relay1_Increment = 2;

int relay2_Reset =3;

// inputs for rotary dialer

int input1 = 4; // click-click-click

int input2 = 5;

const int MilliSecondDelay = 20;

const int RelayMSDelay = 100;

// set number of incrementer switch

void IncrementSwitch(int parNumberInc) {

digitalWrite(relay2_Reset, HIGH); // turn the relay ON(HIGH is the voltage level)

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

digitalWrite(relay2_Reset, LOW); // turn the relay off (LOW is the voltage level)

delay(RelayMSDelay);

digitalWrite(relay2_Reset, HIGH); // turn the relay ON(HIGH is the voltage level)

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

delay(RelayMSDelay);

digitalWrite(relay2_Reset, LOW); // turn the relay off (LOW is the voltage level)

delay(RelayMSDelay);

for (int thisN = 0; thisN < parNumberInc; thisN++) {

digitalWrite(relay1_Increment, HIGH); // turn the relay ON (HIGH is the voltage level)

delay(RelayMSDelay);

digitalWrite(relay1_Increment, LOW); // turn the relay OFF (LOWis the voltage level)

delay(RelayMSDelay);

}

}

void blankALL(){

// all LEDs off - clear

digitalWrite(led1, LOW); // turn the led off (HIGH is the voltage level)

digitalWrite(led2, LOW); // turn the led off (HIGH is the voltage level)

digitalWrite(led3, LOW); // turn the led off (HIGH is the voltage level)

digitalWrite(led4, LOW); // turn the led off (HIGH is the voltage level)

digitalWrite(led5, LOW); // turn the led off (HIGH is the voltage level)

digitalWrite(led6, LOW); // turn the led off (HIGH is the voltage level)

digitalWrite(led7, LOW); // turn the led off (HIGH is the voltage level)

}

void SetNumber(int parNumber) {

// pass in number, display goes to 7-segment LEDs

int passedNumber;

passedNumber = parNumber;

blankALL; // CLEAR the display

if (passedNumber == 0)

{

digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(led2, LOW); // turn the LED off (HIGH is the voltage level)

digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(led5, HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(led6, HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(led7, HIGH); // turn the LED on (HIGH is the voltage level)

return;

}

if (passedNumber == 1)

{

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

digitalWrite(led5, LOW);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 2)

{

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, LOW);

return;

}

if (passedNumber == 3)

{

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 4)

{

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

digitalWrite(led5, LOW);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 5)

{

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, LOW);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 6)

{

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, LOW);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 7)

{

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 8)

{

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

return;

}

if (passedNumber == 9)

{

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

return;

}

}

// the setup routine runs once when you press reset:

void setup() {

// initialize the digital pin as an output.

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT);

pinMode(led7, OUTPUT);

pinMode(relay1_Increment, OUTPUT);

pinMode(relay2_Reset, OUTPUT);

}

// the loop routine runs over and over again forever:

void loop() {

val = digitalRead(input1); // read input value and store it

// check if there was a transition

// HIGH = click off

while(val == HIGH){

delay(MilliSecondDelay);

WaitMilliSeconds = (WaitMilliSeconds + MilliSecondDelay);

WaitSeconds = (WaitMilliSeconds / 1000);

if (WaitSeconds > .7){

blankALL; // CLEAR the display

Clicks_Display = Clicks;

if (Clicks > 0){

if (Clicks >9){

Clicks =10;

Clicks_Display=0;

}

SetNumber(Clicks_Display);

IncrementSwitch(Clicks);

WaitMilliSeconds = 0;

}

Clicks = 0 ;

}

val = digitalRead(input1); // read input value and store it

}

WaitMilliSeconds = 0;

// LOW = click on

while(val == LOW){

delay(MilliSecondDelay);

val = digitalRead(input1); // read input value and store it

}

Clicks++;

//if (Clicks > 10) {

// Clicks = 0;

//}

}

Roads & Rails Photo Gallery

dsc9745 sam_5755 sam_5965 sam_4992