I am working on a project to convert a 1960's rotor telephone to a gsm phone. The first part of the project has me counting switches. My code currently counts the number of pulses, looks for another switch that activates when the rotor has finished turning, and returns the count value to the serial terminal.
This works fine (and is located at the very bottom). However, I would like to take these count values and load them into an array so I can send the full 10 digit number as an array over to my gsm shield (second if statement form the bottom). I have tried every way I know how but the return seems to always be the first count value assigned to all 10 array locations. Any help would be appreciated.
// 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 = 0; // current state of the button
int lastButtonState = 1; // 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];
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) == 1){
Serial.println("on");
}else{
Serial.println("off");
}
Serial.print("Current state of Dialer is ");
if(digitalRead(4) == 1){
Serial.println("dialing");
}else{
Serial.println("base");
}
}
void loop() {
// 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 == HIGH) {
// 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;
}
}