然後用Linkit one做成行動電話
我想留點關於這撥號盤的note,所以先來講一下運作方式
首先有三條線,其中一個地線,其他兩個分別是撥號開始與號碼數
當使用者開始轉的時候,撥號開始這條線會接地,而使用者轉完,開始倒轉的時候
每過一格,號碼數的那條線會有一個脈衝出來,轉完之後撥號開始這條就恢復斷路
畫成圖的話是這樣:
要注意的是,畢竟這是一個純機械的裝置,訊號一定會有彈跳的現象發生,所以程式的部分一定要做Debounce.
另外就是撥號盤沒有掛電話的按鈕,所以另外再做一個上去.
然後就沒啥問題了,Linkit one 的GSM example寫得很清楚,用LGSM的library很快
#define dial_pin 6
#define count_pin 7
#define hang_pin 2
#define DEBOUNCE_TIME 50
#include <LGSM.h>
String remoteNumber = "";
char charbuffer[20];
uint32_t first_digit = 0;
void setup() {
Serial.begin(115200);
Serial.println("Started");
pinMode(dial_pin,INPUT_PULLUP);
pinMode(count_pin,INPUT_PULLUP);
pinMode(hang_pin,INPUT_PULLUP);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
}
int readDigit(){
bool catched = 0;
int count = 0;
uint32_t lastmillis;
bool diaing = 1;
while(diaing){
if(digitalRead(count_pin)==1 && catched==0 && millis()-lastmillis>DEBOUNCE_TIME && digitalRead(dial_pin)==0){
catched = 1;
count ++;
lastmillis = millis();
}
if(digitalRead(count_pin)==0){
catched = 0;
}
if(digitalRead(dial_pin)==1){
delay(5);
if(digitalRead(dial_pin)==1){
diaing = 0;
}
}
}
count = count%10;
return count;
}
void loop() {
if(digitalRead(dial_pin)==0){
digitalWrite(13,LOW);
uint32_t last_digit = millis();
int digit_count=0;
while(millis()-last_digit<3000){//digit_count<10 &&
if(digitalRead(dial_pin)==0){
delay(10);
last_digit = millis();
int count = readDigit();
Serial.print("Number:");Serial.println(count);
digit_count++;
remoteNumber+=String(count);
}
}
Serial.print("Phone Number:");Serial.println(remoteNumber);
if(digit_count==10){
Serial.print("Calling to : ");
Serial.println(remoteNumber);
Serial.println();
digitalWrite(13,HIGH);
remoteNumber.toCharArray(charbuffer, 20);
if(LVoiceCall.voiceCall(charbuffer))
{
Serial.println("Call Established. Enter line to end");
// Wait for some input from the line
while(digitalRead(hang_pin) == 1);
// And hang up
LVoiceCall.hangCall();
}
Serial.println("Call Finished");
}
remoteNumber= "";
}
}