#define ENTERSETUP 0
#define INSETUP 1
#define CONNECTED 2
int ledPin = 3;
int buttonPin = 2;
int inByte;
int state = 0;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
blink(2);
}
void loop(){
switch(state){
case ENTERSETUP:
delay(1100);
Serial.print("+++");
delay(1100);
inByte = 0;
while (inByte != '\r'){
if (Serial.available()){
inByte = Serial.read();
}
}
state = INSETUP;
break;
case INSETUP:
Serial.print("ATRE\r");
inByte = 0;
while (inByte != '\r'){
if (Serial.available()){
inByte = Serial.read();
}
}
Serial.print("ATDL0,MY1\r");
inByte = 0;
while (inByte != '\r'){
if (Serial.available()){
inByte = Serial.read();
}
}
Serial.print("ATIDCACA\r");
inByte = 0;
while (inByte != '\r'){
if (Serial.available()){
inByte = Serial.read();
}
}
Serial.print("ATCN\r");
inByte = 0;
while (inByte != '\r'){
if (Serial.available()){
inByte = Serial.read();
}
}
state = CONNECTED;
break;
case CONNECTED:
if (digitalRead(buttonPin) == HIGH){
Serial.print("0");
delay(500);
}
break;
}
if (Serial.available()) {
inByte = Serial.read();
if (inByte == '1') {
blink(3);
}
}
}
void blink(int howManyTimes) { //thanks Tom Igoe
int i;
for (i=0; i< howManyTimes; i++) {
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
}
}