picking up phone dial data

I'm merging these two sets of code

http://wiki.epalsite.com/index.php?title=SIM900_Quad-Band_GPRS_shield_with_Micro_SD_card_slot#Example1-Make_a_phone_call

to get code that will let me use a dial for the GSM shield. See any booboos?

 /*Note:This code is used for Arduino 1.0 or later*/
#include <SoftwareSerial.h>
 
SoftwareSerial  Sim900Serial(2, 3);



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

int numquota;
int numarray[10];

// constants

int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 10;



 
void setup()
{
  Sim900Serial.begin(115200);               // the GPRS baud rate  
  delay(2000);
  Sim900Serial.println("AT+IPR=19200");     // Set the baud rate
  delay(500);
  Sim900Serial.begin(19200);               // the GPRS baud rate   
  delay(1000); 


Serial.begin(9600);                // rotary addition
pinMode(in, INPUT);
}
void loop()
{
//rotary addition
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.
numarray[numquota]= count % 10
needToPrint = 0;
count = 0;
cleared = 0;
numquota++;
}
}

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.
count++;
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
}
}
}
lastState = reading;

//rotary addition






if (trueState == HIGH && numquota == 10 ) {
	Sim900Serial.println("ATD",numarray[0],numarray[1],numarray[2],numarray[3],numarray[4],numarray[5],numarray[6],numarray[7],numarray[8],numarray[9],numarray[10],";");//'*'instead the phone number you want to dial
  while(1);
numquota = 0;
}
}

    while(1);Do you want the program to stay in this infinite loop ?

Your code would be easier to read if it was Auto Formatted and had superfluous blank lines removed, so there may be booboos that have gone unnoticed.

How about getting it to "read" the dial tones for the rotary phone first, and just print it for you to read ? Then, once you have done that, feed it to the cellphone device. Solve one problem at a time.

Aite, I reworked the code a bit. To get the full number I simply multiply the digit up with a 10^x exponent based on the place it is in ie xxx-x2xx is 2 x 10^2 and add it to callednum. I then send called num through sim900serial via 3 println statements. Anything wrong with the approach or code?

 /*Note:This code is used for Arduino 1.0 or later*/
#include <SoftwareSerial.h>
 
SoftwareSerial  Sim900Serial(2, 3);



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

int numquota = 10;//keeps track of the digit we are entering 
int callednum;//number to call

// constants

int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 10;



 
void setup()
{
  Sim900Serial.begin(115200);               // the GPRS baud rate  
  delay(2000);
  Sim900Serial.println("AT+IPR=19200");     // Set the baud rate
  delay(500);
  Sim900Serial.begin(19200);               // the GPRS baud rate   
  delay(1000); 

  // rotary addition
pinMode(in, INPUT);
}
void loop()
{
//rotary addition
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.
//take number and multiply it into its position ie 2nd to last digit multipled by 10^1 to XXYX
callednum += (count % 10) * pow(10,numquota);
needToPrint = 0;
count = 0;
cleared = 0;
numquota--;//decrement the digit we are multiply for ie 100s to 10s place
}
}

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.
count++;
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
}
}
}
lastState = reading;

//rotary addition


if (numquota == -1 ) {//once the last digit has been reached and multipled by 10^0
	Sim900Serial.println("ATD");
		Sim900Serial.println(callednum);//send number to call
		Sim900Serial.println(";");
  //while(1);
numquota = 10;//resets back to multipy for first digit
}
}

I ran this edited code that reads in the number through strings and it doesn't seem to be working. The two separate pieces of code work just fine.

 /*Note:This code is used for Arduino 1.0 or later*/
#include <SoftwareSerial.h>

 
SoftwareSerial  Sim900Serial(2, 3);



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

int numquota = 0;//keeps track of the digit we are entering 
String callednum= "ATD";//number to call

// constants

int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 10;



 
void setup()
{
  Sim900Serial.begin(115200);               // the GPRS baud rate  
  delay(2000);
  Sim900Serial.println("AT+IPR=19200");     // Set the baud rate
  delay(500);
  Sim900Serial.begin(19200);               // the GPRS baud rate   
  delay(1000); 

  // rotary addition
pinMode(in, INPUT);
}
void loop()
{
  
//rotary addition
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.
//take number and multiply it into its position ie 2nd to last digit multipled by 10^1 to XXYX
callednum +=(count % 10);
needToPrint = 0;
count = 0;
cleared = 0;
numquota++;//decrement the digit we are multiply for ie 100s to 10s place
}
}

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.
count++;
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
}
}
}
lastState = reading;

//rotary addition




if (numquota == 11 ) {//once the last digit has been reached and multipled by 10^0
callednum += ";";
		Sim900Serial.println(callednum);//send number to call
  while(1);
numquota = 0;//resets back to multipy for first digit
callednum = "ATD";
}

}

alright the issue seems to have been resolved with a little tweaking with how the number was read in. Maybe it didn't like appending an int to a string?

/*Note:This code is used for Arduino 1.0 or later*/
#include <SoftwareSerial.h>

 
SoftwareSerial  Sim900Serial(2, 3);



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

int numquota = 0;//keeps track of the digit we are entering 
String callednum= "ATD";//number to call
int transferreddigit;
String transferredstring;

// constants

int dialHasFinishedRotatingAfterMs = 100;
int debounceDelay = 10;



 
void setup()
{
  Sim900Serial.begin(115200);               // the GPRS baud rate  
  delay(2000);
  Sim900Serial.println("AT+IPR=19200");     // Set the baud rate
  delay(500);
  Sim900Serial.begin(19200);               // the GPRS baud rate   
  delay(1000); 

  // rotary addition
pinMode(in, INPUT);
}
void loop()
{
//rotary addition
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.
//take number and multiply it into its position ie 2nd to last digit multipled by 10^1 to XXYX
transferreddigit = (count % 10);
transferredstring = String(transferreddigit);
callednum += transferredstring  ;
needToPrint = 0;
count = 0;
cleared = 0;
numquota++;//decrement the digit we are multiply for ie 100s to 10s place
}
}

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.
count++;
needToPrint = 1; // we'll need to print this number (once the dial has finished rotating)
}
}
}
lastState = reading;

//rotary addition


if (numquota == 11 ) {//once the last digit has been reached and multipled by 10^0
callednum += ";";
		Sim900Serial.println(callednum);//send number to call
  while(1);
numquota = 0;//resets back to multipy for first digit
callednum = "ATD";
}
}