Parsing final number with a rotary dial

Hi there. I'm currently working on a project to dial a mobile number with a rotary dial from an old telephone. I'm using a GSM 900 shield with an arduino uno/nano

Up until now I am able to dial a phone number using AT commands on the gsm shield, and read the dial on the rotary dial. But I wanna parse the number to the gsm shield.

Right now, the code used to read the dial is as follows:

int needToPrint = 0;
int count;
int in = 2;
int lastState = LOW;
int trueState = LOW;
long lastStateChangeTime = 0;
int cleared = 0;

// constants

int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 10;

void setup()
pinMode(in, INPUT);

void loop()
int reading = digitalRead(in);

if ((millis() - lastStateChangeTime) > dialHasFinishedRotatingAfterMs) {
// the dial isn't being dialed, or has just finished being dialed.
if (needToPrint) {
// if it's only just finished being dialed, we need to send the number down the serial
// line and reset the count. We mod the count by 10 because '0' will send 10 pulses.
Serial.print(count % 10, DEC);
needToPrint = 0;
count = 0;
cleared = 0;

if (reading != lastState) {
lastStateChangeTime = millis();
if ((millis() - lastStateChangeTime) > debounceDelay) {
// debounce - this happens once it's stablized
if (reading != trueState) {
// this means that the switch has either just gone from closed->open or vice versa.
trueState = reading;
if (trueState == HIGH) {
// increment the count of pulses if it's gone high.
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
lastState = reading;

This code is from (i think)

What this code does is to read every dialed number and print it on the serial connection. What I would need is to store each digit into a variable and when the variable has let's say 10 digits, it would parse the number to the GSM shield.

I'm stuck in this phase. Any ideas?

Thank you

A quote-tag isn't a code tag. Can you please edit you post to have code tags. See How to use the forum.

Next up, what have YOU tried to change? Coding is not about copy pasting, it's about understanding what it does.

I've modified the tags so that It would display code instead of quote. I haven't tried to change anything, I just need advice on how to store the number into a variable and then parse it

First step, press CTRL+T. Makes it a lot easier to see what to edit.

And next, instead of printing it to serial, try to store it in an array (and remember which digit you saved last).

Hardest part, when do you want to send it out? After some time? Or after x digits? etc.

Thank you

After some defined number of digits, let’s say 10

After the 10 digit threshold has been reached it should send the number to the gsm shield using at commands, like ATDxxxxxxxxxx where xxx is the number.

Alright, the I would start to try to implement that ;) If you're stuck we'll go from there. We are here to help, not to write the code for you ;)

ATDxxxxxxxxxx where xxx is the number.

Sorry. A phone "number" is not really a number. It's a string. That string happens to consists of digits, but that does not make it a number.

It is not at all clear what, exactly, that code is doing/counting. If it is counting pulses from the rotary phone dial, then every time needToPrint is non-zero (why the hell didn't they use a boolean with true or false?), count % 10 is the digit that you need to convert to a character (by adding '0' to the value) to produce a value to store in the string to be sent later. Increment the array index after adding the character, and add a NULL.

When the index gets to be the correct value (10?), you can then send the "number" using the ATD command.