So I am tryin to feed my fona800 a string that contains the phone number I want to dial. I am obtaining the numbers through a count of a rotary dial. Inputs come in and are stored in an array. I convert the array values into a single long number and then use sprintf to convert them to a string so I can feed my fona. However, the value of the string it returns is only 5 digits long and I don’t know why.
The attached screenprint of the serial shows 1 dialed ten times and the resulting sprintf output. Any help is appreciated.
#include "Adafruit_FONA.h"
#include "stdint.h"
#include "stdio.h"
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// this constant won't change:
const int buttonPin = 2; // the pin that the rotary number switch is attached to
const int diallingPin = 4; // pin that the rotor start/finish is attached to
// Variables that will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 1; // current state of the button
int lastButtonState = 0; // previous state of the button
int phoneNumber[9]; // sets array for phone number
int dialing = 0; // sets state of dialing on/off
int dialState; // place to store dial state
int numberString; // keep track of the numbers dialer
int number = 0;
int array [10];
uint32_t k = 0;
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initializes dialling pin as an input;
pinMode(diallingPin, INPUT);
// initialize serial communication:
Serial.begin(9600);
Serial.println("Setup is initialized");
Serial.print("Current state of Dial Connector is ");
if(digitalRead(2) == 0){
Serial.println("on");
}else{
Serial.println("off");
}
Serial.print("Current state of Dialer is ");
if(digitalRead(4) == 0){
Serial.println("dialing");
}else{
Serial.println("base");
}
}
void loop() {
if (buttonPushCounter > 0 && digitalRead(4) == 1) {
if(buttonPushCounter == 10) {
buttonPushCounter = 0;
}
array[number] = buttonPushCounter;
number = number + 1;
buttonPushCounter = 0;
if(number == 10){
for(int place = 0; place < 10; place++){
Serial.println(array[place]);
k = (10 * k) + array[place];
//convert int phone number to string so it will work with fona.callPhone
if (k > 1000000000){
char str[10];
sprintf(str, "%d", k);
// fona.callPhone(str);
Serial.println(str);
}
}
}
}else{
// read the pushbutton input pin:
buttonState = digitalRead(2);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {
// if the current state is HIGH then the button
// went from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
//if the current state is LOW then the button
// went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
}
//if(buttonPushCounter > 0 && digitalRead(4) != 1){
// for(number = 0; number <= 9; number++){
// array[number] = buttonPushCounter;
// Serial.println(array[number]);
}
// if(buttonPushCounter > 0 && digitalRead(4) != 1){
// Serial.print(buttonPushCounter);
// buttonPushCounter = 0;