Stap 5: Programmering arduino
Afbeelding van mijn volledige phonoduino (telefoon + arduino) setup is hierboven gegeven. DTMF-input wordt niet gegeven aan de arduino nu. We zullen zien dat dit later van dit project. Laten we nu enkele code schrijven om te geven het leven van de phonoduino. Code voor automatische roeping voor een gegeven nummer is gekoppeld.
int key0 = 16; int key1 = 6; int key2 = 12; int key3 = 9; int key4 = 5; int kry5 = 15; int key6 = 10; int key7 = 14; int key8 = 13; int key9 = 18; int keyStar = 17; int keyOk = 11; int keyClear = 3; int keyDown = 4; int keyUp = 8; int keyOff = 2; int keyHash = 19; int pressTime = 100; int pressDelay = 300; int holdTime = 1000; int value[16] = {16,6,12,9,5,15,10,14,13,18,17,11,3,4,8,2}; void setup() { // initialize the digital pin as an output. for(int i=2; i<20; i++) pinMode(i, OUTPUT); holdClear(); unlockPhone(); delay(2000); holdClear(); delay(1000); // call 0123456789 pressDigit(0); pressDigit(1); pressDigit(2); pressDigit(3); pressDigit(4); pressDigit(5); pressDigit(6); pressDigit(7); pressDigit(8); pressDigit(9); delay(100); pressOk(); delay(5000); } // the loop routine runs over and over again forever: void loop() { } void pressDigit(int digit){ digitalWrite(value[digit], HIGH); // press digit from 0 to 9 delay(pressTime); digitalWrite(value[digit],LOW); delay(pressDelay); } void pressOk(){ digitalWrite(keyOk, HIGH); // press ok delay(pressTime); digitalWrite(keyOk,LOW); delay(pressDelay); } void pressClear(){ digitalWrite(keyClear, HIGH); // press clear delay(pressTime); digitalWrite(keyClear,LOW); delay(pressDelay); } void pressStar(){ digitalWrite(keyStar, HIGH); // press star delay(pressTime); digitalWrite(keyStar,LOW); delay(pressDelay); } void pressUp(){ digitalWrite(keyUp, HIGH); // press up delay(pressTime); digitalWrite(keyUp,LOW); delay(pressDelay); } void pressDown(){ digitalWrite(keyDown, HIGH); // press down delay(pressTime); digitalWrite(keyDown,LOW); delay(pressDelay); } void pressHash(){ digitalWrite(keyHash, HIGH); // press hash delay(pressTime); digitalWrite(keyHash,LOW); delay(pressDelay); } void pressOff(){ digitalWrite(keyOff, HIGH); // press off delay(pressTime); digitalWrite(keyOff,LOW); delay(pressDelay); } void holdOff(){ digitalWrite(keyOff, HIGH); // hold off delay(holdTime); digitalWrite(keyOff,LOW); delay(pressDelay); } void holdClear(){ digitalWrite(keyClear, HIGH); // press clear delay(holdTime); digitalWrite(keyClear,LOW); delay(pressDelay); } void unlockPhone(){ pressOk(); pressStar(); }
Wilt u een telefoonnummer van seriële monitor?
Code voor het bellen van seriële monitor is ook bevestigd. Uitsluitend type telefoonnummer in terminal eindigt bij een coma (,) en druk op invoeren. Phonoduino zal direct het nummer. Coma geeft u enkel volledige typen nummer en wilt bellen. Als u wilt wissen van een willekeurig getal ten onrechte enter getypte enkel type puntkomma (;) en druk op. Typ uw nummer.
Bericht wilt verzenden van seriële monitor?
Typen bericht van mobiele telefoon is saai en tijdrovend. Het zal gemakkelijk sms van het toetsenbord typt en bespaart veel tijd. Een monster arduino schets wordt gegeven aan verzonden sms van seriële monitor. Gewoon het programma uploaden naar je arduino seriële monitor openen, typt u uw bericht, typt u colon(:), typenummer, typ mobiele nummer of elke gewenste verzonden uw sms en druk op enter toets. Uw phonoduino zal het bericht verzonden naar uw gewenste nummer.
Voorbeeld: Hallo, ik ben van phonoduino.:123456789 *
Het bovenstaande commando zal naar het nummer "123456789" verzonden "Hallo, ik ben van phonoduino."
<code> int pressTime = 100; int pressDelay = 300; int holdTime = 1000; int typeTime = 100; int typeDelay = 400; int value[16] = {16,6,12,9,5,15,10,14,13,18,17,11,3,4,8,2}; char number[12]; char massegeChar[160]; int count = 0; int numCount = 0; int charDelay = 300; int numberState = 0; void setup() { // initialize the digital pin as an output. for(int i=2; i<20; i++) pinMode(i, OUTPUT); Serial.begin(9600); holdClear(); } // the loop routine runs over and over again forever: void loop() { while (Serial.available()>0){ char character = Serial.read(); if(character == '*'){ sentSMS(); count = 0; numCount = 0; numberState = 0; } if(character == ':'){ numberState = 1; numCount = 0; //delay(10); } if(numberState == 1){ number[numCount] = character; numCount++; } if(numberState == 0){ massegeChar[count] = character; count++; } if(character == '#'){ count = 0; numberState = 0; } } } void pressDigit(int digit){ digitalWrite(value[digit], HIGH); // press digit from 0 to 9 delay(pressTime); digitalWrite(value[digit],LOW); delay(pressDelay); } void pressOk(){ digitalWrite(keyOk, HIGH); // press ok delay(pressTime); digitalWrite(keyOk,LOW); delay(pressDelay); } void pressClear(){ digitalWrite(keyClear, HIGH); // press clear delay(pressTime); digitalWrite(keyClear,LOW); delay(pressDelay); } void pressStar(){ digitalWrite(keyStar, HIGH); // press star delay(pressTime); digitalWrite(keyStar,LOW); delay(pressDelay); } void pressUp(){ digitalWrite(keyUp, HIGH); // press up delay(pressTime); digitalWrite(keyUp,LOW); delay(pressDelay); } void pressDown(){ digitalWrite(keyDown, HIGH); // press down delay(pressTime); digitalWrite(keyDown,LOW); delay(pressDelay); } void pressHash(){ digitalWrite(keyHash, HIGH); // press hash delay(pressTime); digitalWrite(keyHash,LOW); delay(pressDelay); } void pressOff(){ digitalWrite(keyOff, HIGH); // press off delay(pressTime); digitalWrite(keyOff,LOW); delay(pressDelay); } void holdOff(){ digitalWrite(keyOff, HIGH); // hold off delay(holdTime); digitalWrite(keyOff,LOW); delay(pressDelay); } void holdClear(){ digitalWrite(keyClear, HIGH); // press clear delay(holdTime); digitalWrite(keyClear,LOW); delay(pressDelay); } void typeA(){ digitalWrite(key2, HIGH); delay(typeTime); digitalWrite(key2, LOW); delay(typeDelay); } void typeB(){ typeA(); typeA(); } void typeC(){ typeA(); typeA(); typeA(); } void typeD(){ digitalWrite(key3, HIGH); delay(typeTime); digitalWrite(key3, LOW); delay(typeDelay); } void typeE(){ typeD(); typeD(); } void typeF(){ typeD(); typeD(); typeD(); } void typeG(){ digitalWrite(key4, HIGH); delay(typeTime); digitalWrite(key4, LOW); delay(typeDelay); } void typeH(){ typeG(); typeG(); } void typeI(){ typeG(); typeG(); typeG(); } void typeJ(){ digitalWrite(key5, HIGH); delay(typeTime); digitalWrite(key5, LOW); delay(typeDelay); } void typeK(){ typeJ(); typeJ(); } void typeL(){ typeJ(); typeJ(); typeJ(); } void typeM(){ digitalWrite(key6, HIGH); delay(typeTime); digitalWrite(key6, LOW); delay(typeDelay); } void typeN(){ typeM(); typeM(); } void typeO(){ typeM(); typeM(); typeM(); } void typeP(){ digitalWrite(key7, HIGH); delay(typeTime); digitalWrite(key7, LOW); delay(typeDelay); } void typeQ(){ typeP(); typeP(); } void typeR(){ typeP(); typeP(); typeP(); } void typeS(){ typeP(); typeP(); typeP(); typeP(); } void typeT(){ digitalWrite(key8, HIGH); delay(typeTime); digitalWrite(key8, LOW); delay(typeDelay); } void typeU(){ typeT(); typeT(); typeT(); } void typeV(){ typeT(); typeT(); typeT(); } void typeW(){ digitalWrite(key9, HIGH); delay(typeTime); digitalWrite(key9, LOW); delay(typeDelay); } void typeX(){ typeW(); typeW(); } void typeY(){ typeW(); typeW(); typeW(); } void typeZ(){ typeW(); typeW(); typeW(); typeW(); } void space(){ digitalWrite(key0, HIGH); delay(typeTime); digitalWrite(key0, LOW); delay(typeDelay); } void sentSMS(){ holdClear(); holdClear(); pressOk(); pressOk(); pressOk(); for(int i = 0; i< 160; i++){ switch(massegeChar[i]){ case 'A': case 'a': typeA(); delay(charDelay); break; case 'B': case 'b': typeB(); delay(charDelay); break; case 'C': case 'c': typeC(); delay(charDelay); break; case 'D': case 'd': typeD(); delay(charDelay); break; case 'E': case 'e': typeE(); delay(charDelay); break; case 'F': case 'f': typeF(); delay(charDelay); break; case 'G': case 'g': typeG(); delay(charDelay); break; case 'H': case 'h': typeH(); delay(charDelay); break; case 'I': case 'i': typeI(); delay(charDelay); break; case 'J': case 'j': typeJ(); delay(charDelay); break; case 'K': case 'k': typeK(); delay(charDelay); break; case 'L': case 'l': typeL(); delay(charDelay); break; case 'M': case 'm': typeM(); delay(charDelay); break; case 'N': case 'n': typeN(); delay(charDelay); break; case 'O': case 'o': typeO(); delay(charDelay); break; case 'P': case 'p': typeP(); delay(charDelay); break; case 'Q': case 'q': typeQ(); delay(charDelay); break; case 'R': case 'r': typeR(); delay(charDelay); break; case 'S': case 's': typeS(); delay(charDelay); break; case 'T': case 't': typeT(); delay(charDelay); break; case 'U': case 'u': typeU(); delay(charDelay); break; case 'V': case 'v': typeV(); delay(charDelay); break; case 'W': case 'w': typeW(); delay(charDelay); break; case 'X': case 'x': typeX(); delay(charDelay); break; case 'Y': case 'y': typeY(); delay(charDelay); break; case 'Z': case 'z': typeZ(); delay(charDelay); break; case ' ': space(); break; } delay(300); } pressOk(); pressOk(); callNumber(); } void callNumber(){ for(int i=1; i<12; i++){ pressDigit(number[i]-'0'); // number[i] - '0' is for converting character into intiger } pressOk(); holdClear(); holdClear(); }
Ik zal een efficiëntere arduino schets later gepubliceerd.