Code Balise
Code Balise
h>
#include <Keypad.h>
#include <SPI.h>
#include <LiquidCrystal_I2C.h>
#include <TinyGPS++.h>
#include <TinyGPSPlus.h>
String Num_Prec;
char key;
byte i, j;
boolean remote, ctrl, val, def, appel, loc, envoi_SMS, etat_VBR, com;
byte call;
char keys[ROWS][COLS] = {
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
#define VIB 13
TinyGPSPlus Gps;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void receive_data_GPS() {
if (Serial.available() > 0) {
if (Gps.encode(Serial.read())) {
if (Gps.location.isValid()) {
loc = 1;
Latitude = Gps.location.lat();
Longitude = Gps.location.lng();
Vitesse = Gps.speed.value();
} else {
loc = 0;
void sendSMS() {
if (envoi_SMS == 1) {
gsm.println("AT+CMGF=1");
delay(50);
delay(50);
lcd.setCursor(2, 0);
lcd.print("Sending...");
lcd.setCursor(4, 1);
lcd.print(Num_Pass);
Num_Prec = Num_Pass;
gsm.print("INFO BALISE\n");
gsm.print("Location: ");
if (loc == 1) {
} else {
gsm.print("No available");
delay(50);
gsm.write(26);
delay(2000);
envoi_SMS = 0;
call = 4;
void setup() {
Serial.begin(9600);
gsm.begin(9600);
delay(100);
pinMode(VIB, OUTPUT);
gsm.println("AT+CMGF=1");
delay(500);
gsm.println("AT+CNMI=1,2,0,0,0");
delay(500);
lcd.init();
lcd.backlight();
lcd.clear();
delay(100);
digitalWrite(VIB, LOW);
i = 0;
remote = 0;
ctrl = 0;
val = 0;
call = 0;
def = 0;
appel = 0;
envoi_SMS = 0;
com = 1;
void loop() {
receive_data_GPS();
if (key != NO_KEY) {
switch (call) {
case 0:
if (key == 'C') {
com = !com;
if (key != 'D') {
if (key == 'A') {
if (i >= 0) {
i--;
if (i > 15) i = 0;
Num_Pass[i] = 0;
lcd.setCursor(i + 4, 1);
lcd.print(' ');
} else {
if (key == 'B') {
if (Num_Prec == 0) {
lcd.setCursor(4, 1);
lcd.print("No data.");
delay(1000);
call = 4;
i = 0;
j = 0;
} else {
Num_Pass[i] = Num_Prec[i];
delay(100);
lcd.setCursor(i + 4, 1);
lcd.print(Num_Pass[i]);
j = i;
} else {
if (key != 'C') {
lcd.setCursor(i + 4, 1);
lcd.print(key);
Num_Pass[i] = key;
i++;
j = i;
} else {
i = 0;
j = 0;
lcd.clear();
if (com == 1) {
tA = millis();
Num_Prec = Num_Pass;
while (call == 0) {
while (gsm.available()) {
Serial.println(rep);
if (rep.indexOf("OK") != -1) {
call = 3;
def = 0;
lcd.clear();
lcd.setCursor(1, 0);
delay(1000);
call = 4;
def = 0;
lcd.clear();
lcd.setCursor(0, 0);
delay(1000);
call = 4;
} else {
envoi_SMS = 1;
sendSMS();
break;
case 1:
if (key == 'D') {
gsm.println("ATH");
call = 4;
appel = 0;
gsm.println("ATA");
call = 4;
appel = 1;
break;
case 2:
if (key == 'D') {
gsm.println("ATH");
call = 4;
appel = 0;
break;
case 3:
if (key == 'D') {
gsm.println("ATH");
call = 4;
appel = 0;
break;
switch (call) {
case 0:
lcd.setCursor(0, 0);
lcd.print("A");
} else {
lcd.print("M");
if (gsm.available() > 0) {
//Serial.println(rep);
if (rep0.indexOf("RING") != -1) {
lcd.clear();
call = 1;
break;
case 1:
lcd.setCursor(0, 0);
if (gsm.available() > 0) {
//Serial.println(rep);
if (appel == 0) {
call = 4;
lcd.clear();
} else {
call = 2;
lcd.clear();
appel = 0;
}
break;
case 2:
lcd.setCursor(0, 0);
if (gsm.available() > 0) {
//Serial.println(rep);
if (appel == 0) {
call = 4;
lcd.clear();
break;
case 3:
lcd.setCursor(2, 0);
lcd.print("Calling...");
lcd.setCursor(4, 1);
lcd.print(Num_Pass);
if (gsm.available() > 0) {
//memset(Num_Pass, 0, sizeof(Num_Pass));
if (appel == 0) {
call = 4;
break;
case 4:
lcd.clear();
memset(Num_Pass, 0, sizeof(Num_Pass));
call = 0;
break;