This is the first version of the mbed program for the Smart Car Seat developed by the Smart Car Seat Team of GaTech Design Expo Spring 2017.
Dependencies: Adafruit_FONA FSR SDFileSystem mbed
Fork of Smart_Car_Seat_v1 by
Team Members
Bryan Bates – OBD/Bluetooth System
Robert Dunkin – Physical Wiring/Power
Jgenisius Harris – Cooling System
Jea Du Kim – Sensor System
Emily Pitts – Smartphone Application
Tyler Woei-A-Sack – GSM Communications
Advisor
Dr. Mick West
Overview
The purpose of this project was to design a child’s safety car seat with Internet of Things capabilities and a cooling system that activates in the case of an emergency. It is comprised of a network of sensors, a wireless notification system, and a cooling system.
How Does It Work
The Smart Car Seat is initially set up using a smartphone application where the user inputs their phone number. The number is saved to an SD card and is read by the GSM module when it sends the text messages. If the infrared thermometers read a critical temperature and the force sensitive resistors detect someone, the cooling system will turn on and a text message will be sent to the phone number on file.
Smart Car Seat Program
Import programSmart_Car_Seat_v1
This is the first version of the mbed program for the Smart Car Seat developed by the Smart Car Seat Team of GaTech Design Expo Spring 2017.
Components
This project involves the usage of the mbed LPC1768.
Force Sensitive Resistors
This project uses 4 Square FSR Interlink 406, two placed on the seat and two placed on the back rest to detect if someone is sitting on the seat.
mbed | FSR | Voltage Divider |
---|---|---|
p20 | FSR Bottom Left | 10K |
p19 | FSR Upper Left | 10K |
p18 | FSR Upper Right | 10K |
p17 | FSR Bottom Right | 10K |
As they are still resistors, the orientation of the pins do not matter, as long as one end goes into VCC and the other leads to a voltage divider and an AnalogIn like shown in the diagram. With a 10K Ohm voltage divider, a raw analog value of 0.5 for each FSR should be enough to distiguish an object of the size of a small child on the sensor.
Any additional information can be found at the Force Sensitive Resistors page.
Import library
Public Member Functions |
|
FSR (PinName Pin, float resistance) | |
Create an
FSR
object.
|
|
float | readRaw () |
Read the raw data.
|
|
float | readFSRResistance () |
Read the resistance of the
FSR
.
|
|
float | readWeight () |
Read the weight in N.
|
MLX90614 IR Thermometers
This project uses two MLX90614 IR Thermometer placed on the back of the headrest to measure the temperature of the child sitting on the seat and the ambient temperature.
mbed | FSR | Pullups | Pulldowns |
---|---|---|---|
gnd | VSS - gnd | ||
Vout | VDD - 3.3V | 0.1uF (to VSS) | |
p27 | SCL - I2C Clock | 10K | |
p28 | SDA - I2C Data | 10K |
At around room temperature, the Thermometers should read approximately 22 C. When reading the temperature from the palm, the sensors should read approximately between 30 and 35 C.
With the MLX90614 and I2C, you can run up to 127 thermometers through the same SCL and SDA connection as long as they have different 7-bit addresses. The default I2C address for the MLX90614 is 0x5A, but it can be changed with this program.
Import programMLX90614 IR_Temp_Sensor (change address)
I have spent so much time looking into how to change the address of a MLX90614 sensor for use of multiple sensors, so I think it might be helpful to somebody.
Any additional information can be found at the MLX90614 I2C IR Thermometer page.
SD Card File System
This project uses the basic SD Card reader that works with the mbed to store all the contact information for the system.
mbed | MicroSD Breakout |
---|---|
p8 (DigitalOut) | CS |
p5 (SPI MOSI) | DI |
Vout | VCC |
p7 (SPI SCLK) | SCK |
GND | GND |
p6 (SPI MISO) | DO |
nc | CD |
Careful
VCC is the 3.3V from Vout. Using the 5V will damage the SD card.
Information
The project uses a simple .txt file to store a 10-digit phone number. Before operations, check if the file is named correctly and in the correct directory based on your code.
Any additional information can be found at the SD Card File System page.
Import librarySDFileSystem
SDFileSystem
GSM Module
This project used the FONA 808 MiniGSM provided from Adafruit to send messages to the contact information stored in the SD Card.
mbed | Adafruit FONA |
---|---|
nc | Bat |
GND | GND |
nc | SPKR+ |
nc | SPKR- |
p12 | Rst |
nc | PS |
GND | Key |
p11 | RI |
p14 (Serial RX) | TX |
p13 (Serial TX) | RX |
nc | NS |
Vout (3.3V) | Vio |
Warning!
Adafruit Fona 800/808 will only work when there's an external battery connected with at least 3.4V. When the battery is at a low level, the MicroUSB charger should be plugged in with the battery. Be careful with low rated batteries as the USB will charge at 4.2V.
Both the 800 and the 808 uses the same protocols, so any additional documentations, information, and project libraries can be found at the Adafruit FONA 800 Project page.
Import library
Data Structures |
|
class | EventListener |
Listener for FONA events.
More...
|
|
Public Member Functions |
|
Adafruit_FONA (PinName tx, PinName rx, PinName rst, PinName ringIndicator) | |
Create instance of the
Adafruit_FONA
.
|
|
bool | begin (int baudrate) |
Built-in Test to see if FONA is connected.
|
|
void | setEventListener ( EventListener *eventListener) |
Set the event listener for incoming calls.
|
|
int | readable (void) |
Check if FONA has anything in its output buffer.
|
|
bool | getADCVoltage (uint16_t *v) |
Get ADC voltage from external pin.
|
|
bool | getBattPercent (uint16_t *p) |
Get battery percentage level.
|
|
bool | getBattVoltage (uint16_t *v) |
Get battery voltage level.
|
|
bool | unlockSIM (char *pin) |
Unlock SIM if needed.
|
|
uint8_t | getSIMCCID (char *ccid) |
Get the SIM chip card interface device (CCID)
|
|
uint8_t | getNetworkStatus (void) |
Get the Network Status of FONA.
|
|
uint8_t | getRSSI (void) |
Get the RSSI of the network signal.
|
|
uint8_t | getIMEI (char *imei) |
Get the International Mobile Station Equipment Identity (IMEI)
|
|
bool | setAudio (uint8_t a) |
Set the Audio Output interface.
|
|
bool | setVolume (uint8_t i) |
Set the Audio Volume.
|
|
uint8_t | getVolume (void) |
Get the Audio Volume.
|
|
bool | tuneFMradio (uint16_t station) |
Tune the FM radio.
|
|
bool | FMradio (bool onoff, uint8_t a=FONA_HEADSETAUDIO) |
FM radio set output.
|
|
bool | setFMVolume (uint8_t i) |
Set the FM Radio Volume.
|
|
int8_t | getFMVolume () |
Get the FM Volume.
|
|
int8_t | getFMSignalLevel (uint16_t station) |
Get the FM signal strength.
|
|
bool | setSMSInterrupt (uint8_t i) |
Set the SMS Interrupt.
|
|
uint8_t | getSMSInterrupt (void) |
Get SMS Interrupt Setting.
|
|
int8_t | getNumSMS (void) |
Set the SMS Interrupt.
|
|
bool | readSMS (uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize) |
Read SMS.
|
|
bool | sendSMS (char *smsaddr, char *smsmsg) |
Send SMS.
|
|
bool | deleteSMS (uint8_t i) |
Delete SMS.
|
|
bool | getSMSSender (uint8_t i, char *sender, int senderlen) |
Send SMS.
|
|
bool | enableNetworkTimeSync (bool onoff) |
Enable FONA to sync time with the cellular network.
|
|
bool | enableNTPTimeSync (bool onoff, const char *ntpserver=0) |
Enable FONA to sync time with the time server.
|
|
bool | getTime (char *buff, uint16_t maxlen) |
Retrieve the current time from the enabled server.
|
|
bool | setPWM (uint16_t period, uint8_t duty=50) |
Control the buzzer capability of the PWM out on the FONA.
|
|
bool | callPhone (char *phonenum) |
Call a phone.
|
|
bool | hangUp (void) |
Hang up a phone call.
|
|
bool | pickUp (void) |
Answer a phone call.
|
|
bool | callerIdNotification (bool enable) |
Enable/disable caller ID.
|
|
bool | incomingCallNumber (char *phonenum) |
Retrieve the incoming call number.
|
Bluetooth Module
This project uses the HC-05 Bluetooth Module to connect with an Android app to update or change contact information stored in the SD Card.
mbed | Bluetooth |
---|---|
p9 (TX) | RX |
p10 (RX) | TX |
GND | GND |
Vout | VCC |
The Bluetooth module simple acts as a wireless Serial connection, so there is no need for additional Libraries other than the Serial.
Any additional information about Serial connections can be found at the Serial page.
Import librarymbed
Cooling System
The Cooling System involves the use of a MOSFET Relay and a combination of 5V Fans, Peltier Plates, and Heatsinks to provide cold air when commanded to.
mbed | MOSFET Relay | Cooling System |
---|---|---|
gnd | JP2-2 - gnd | |
5V | JP2-1 - RAW | |
p16 | JP2-3 - Control | |
JP1-1 | Device (Neg) | |
JP1-2 | Device (Pos) |
Any additional information about Relays can be found here.
main.cpp@0:5a4b2c91de63, 2017-05-03 (annotated)
- Committer:
- jd0205
- Date:
- Wed May 03 21:14:11 2017 +0000
- Revision:
- 0:5a4b2c91de63
- Child:
- 1:a33e55fecf16
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jd0205 | 0:5a4b2c91de63 | 1 | #include "mbed.h" |
jd0205 | 0:5a4b2c91de63 | 2 | #include "FSR.h" |
jd0205 | 0:5a4b2c91de63 | 3 | |
jd0205 | 0:5a4b2c91de63 | 4 | #include <ctype.h> |
jd0205 | 0:5a4b2c91de63 | 5 | #include <string> |
jd0205 | 0:5a4b2c91de63 | 6 | |
jd0205 | 0:5a4b2c91de63 | 7 | #include "SDFileSystem.h" |
jd0205 | 0:5a4b2c91de63 | 8 | #include "Adafruit_FONA.h" |
jd0205 | 0:5a4b2c91de63 | 9 | |
jd0205 | 0:5a4b2c91de63 | 10 | #define FONA_RST p12 |
jd0205 | 0:5a4b2c91de63 | 11 | #define FONA_TX p13 |
jd0205 | 0:5a4b2c91de63 | 12 | #define FONA_RX p14 |
jd0205 | 0:5a4b2c91de63 | 13 | #define FONA_RI p11 |
jd0205 | 0:5a4b2c91de63 | 14 | |
jd0205 | 0:5a4b2c91de63 | 15 | Serial pcSerial(USBTX, USBRX); |
jd0205 | 0:5a4b2c91de63 | 16 | |
jd0205 | 0:5a4b2c91de63 | 17 | DigitalOut led1(LED1); //Fona status - on(connecting), off(disconnecting) |
jd0205 | 0:5a4b2c91de63 | 18 | DigitalOut led2(LED2); |
jd0205 | 0:5a4b2c91de63 | 19 | DigitalOut led3(LED3); //Pressure status - on(child on seat), off(off seat) |
jd0205 | 0:5a4b2c91de63 | 20 | DigitalOut led4(LED4); //Temperature status - on(Too hot), off(not hot) |
jd0205 | 0:5a4b2c91de63 | 21 | |
jd0205 | 0:5a4b2c91de63 | 22 | Adafruit_FONA fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI); //GSM |
jd0205 | 0:5a4b2c91de63 | 23 | |
jd0205 | 0:5a4b2c91de63 | 24 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card reader |
jd0205 | 0:5a4b2c91de63 | 25 | |
jd0205 | 0:5a4b2c91de63 | 26 | DigitalOut CtrlRelay(p16); //Relay Controller |
jd0205 | 0:5a4b2c91de63 | 27 | |
jd0205 | 0:5a4b2c91de63 | 28 | FSR bottomFSR1(p20, 10); // Pin 17-20 is used as the AnalogIn pin and a 10k resistor is used as a voltage divider for the FSR |
jd0205 | 0:5a4b2c91de63 | 29 | FSR topFSR1(p19, 10); |
jd0205 | 0:5a4b2c91de63 | 30 | FSR topFSR2(p18, 10); |
jd0205 | 0:5a4b2c91de63 | 31 | FSR bottomFSR2(p17, 10); |
jd0205 | 0:5a4b2c91de63 | 32 | |
jd0205 | 0:5a4b2c91de63 | 33 | I2C i2c(p28, p27); //I2C commands |
jd0205 | 0:5a4b2c91de63 | 34 | |
jd0205 | 0:5a4b2c91de63 | 35 | Serial bt(p9, p10); //Bluetooth module |
jd0205 | 0:5a4b2c91de63 | 36 | |
jd0205 | 0:5a4b2c91de63 | 37 | float temp, avgTemp; //temperature in degrees C |
jd0205 | 0:5a4b2c91de63 | 38 | const int addr1 = 0xB4; //Default MLX90614 address - 0x5A |
jd0205 | 0:5a4b2c91de63 | 39 | const int addr2 = 0x08; //Changed another MLX90614 address to 0x04 |
jd0205 | 0:5a4b2c91de63 | 40 | char data[3]; |
jd0205 | 0:5a4b2c91de63 | 41 | bool danger; |
jd0205 | 0:5a4b2c91de63 | 42 | int onForce; |
jd0205 | 0:5a4b2c91de63 | 43 | |
jd0205 | 0:5a4b2c91de63 | 44 | float temp1,temp2,temp3,temp4,avgF; |
jd0205 | 0:5a4b2c91de63 | 45 | |
jd0205 | 0:5a4b2c91de63 | 46 | char pnum[22]; |
jd0205 | 0:5a4b2c91de63 | 47 | char message[141]= "Emergency! Your child is still in the Smart Car Seat!"; |
jd0205 | 0:5a4b2c91de63 | 48 | //Message to send to phone and contacts |
jd0205 | 0:5a4b2c91de63 | 49 | |
jd0205 | 0:5a4b2c91de63 | 50 | class FonaEventListener : public Adafruit_FONA::EventListener { |
jd0205 | 0:5a4b2c91de63 | 51 | virtual void onRing() { |
jd0205 | 0:5a4b2c91de63 | 52 | led1 = 1; |
jd0205 | 0:5a4b2c91de63 | 53 | } |
jd0205 | 0:5a4b2c91de63 | 54 | |
jd0205 | 0:5a4b2c91de63 | 55 | virtual void onNoCarrier() { |
jd0205 | 0:5a4b2c91de63 | 56 | led1 = 0; |
jd0205 | 0:5a4b2c91de63 | 57 | } |
jd0205 | 0:5a4b2c91de63 | 58 | }; |
jd0205 | 0:5a4b2c91de63 | 59 | FonaEventListener fonaEventListener; |
jd0205 | 0:5a4b2c91de63 | 60 | //GSM Module initalization |
jd0205 | 0:5a4b2c91de63 | 61 | |
jd0205 | 0:5a4b2c91de63 | 62 | bool onSeat(float fLevel); //Checks if there is a child on the seat |
jd0205 | 0:5a4b2c91de63 | 63 | float readTemp(int addr, char* cmd); //Reads the temperature through the I2/C |
jd0205 | 0:5a4b2c91de63 | 64 | void callback(void); //Changes the stored number on the SD card |
jd0205 | 0:5a4b2c91de63 | 65 | |
jd0205 | 0:5a4b2c91de63 | 66 | int main() { |
jd0205 | 0:5a4b2c91de63 | 67 | pcSerial.baud(9600); //Set the serial baudrate to 9600 |
jd0205 | 0:5a4b2c91de63 | 68 | wait(2); //Wait 2 secs to initialize and settle |
jd0205 | 0:5a4b2c91de63 | 69 | i2c.frequency(50000); //Set the I2C frequency to 50kHz for the MLX90614 |
jd0205 | 0:5a4b2c91de63 | 70 | wait(2); //Wait another 2 secs for initalization |
jd0205 | 0:5a4b2c91de63 | 71 | |
jd0205 | 0:5a4b2c91de63 | 72 | |
jd0205 | 0:5a4b2c91de63 | 73 | char cmd1[1]; |
jd0205 | 0:5a4b2c91de63 | 74 | char cmd2[1]; |
jd0205 | 0:5a4b2c91de63 | 75 | cmd1[0] = 0x07; //Command to read object temperature |
jd0205 | 0:5a4b2c91de63 | 76 | cmd2[0] = 0x06; //Command to read ambient temperature |
jd0205 | 0:5a4b2c91de63 | 77 | |
jd0205 | 0:5a4b2c91de63 | 78 | |
jd0205 | 0:5a4b2c91de63 | 79 | pcSerial.printf("FONA basic test\r\n"); |
jd0205 | 0:5a4b2c91de63 | 80 | pcSerial.printf("Initializing....(May take 3 seconds)\r\n"); |
jd0205 | 0:5a4b2c91de63 | 81 | // See if the FONA is responding |
jd0205 | 0:5a4b2c91de63 | 82 | if (! fona.begin(9600)) { |
jd0205 | 0:5a4b2c91de63 | 83 | pcSerial.printf("Couldn't find FONA\r\n"); |
jd0205 | 0:5a4b2c91de63 | 84 | while (1); |
jd0205 | 0:5a4b2c91de63 | 85 | } |
jd0205 | 0:5a4b2c91de63 | 86 | fona.setEventListener(&fonaEventListener); |
jd0205 | 0:5a4b2c91de63 | 87 | pcSerial.printf("FONA is OK\r\n"); |
jd0205 | 0:5a4b2c91de63 | 88 | |
jd0205 | 0:5a4b2c91de63 | 89 | |
jd0205 | 0:5a4b2c91de63 | 90 | bt.attach(&callback); //Allows the app to change the phone number |
jd0205 | 0:5a4b2c91de63 | 91 | |
jd0205 | 0:5a4b2c91de63 | 92 | |
jd0205 | 0:5a4b2c91de63 | 93 | //Reads the stored phone number |
jd0205 | 0:5a4b2c91de63 | 94 | FILE *fpr = fopen("/sd/mydir/myphone.txt", "r"); |
jd0205 | 0:5a4b2c91de63 | 95 | if(fpr == NULL) { |
jd0205 | 0:5a4b2c91de63 | 96 | error("Could not open file for read\n"); |
jd0205 | 0:5a4b2c91de63 | 97 | } |
jd0205 | 0:5a4b2c91de63 | 98 | fscanf(fpr,"%s", pnum); |
jd0205 | 0:5a4b2c91de63 | 99 | pcSerial.printf("Phone Number: %s\n", pnum); |
jd0205 | 0:5a4b2c91de63 | 100 | fclose(fpr); |
jd0205 | 0:5a4b2c91de63 | 101 | |
jd0205 | 0:5a4b2c91de63 | 102 | |
jd0205 | 0:5a4b2c91de63 | 103 | danger = false; |
jd0205 | 0:5a4b2c91de63 | 104 | |
jd0205 | 0:5a4b2c91de63 | 105 | while (1) { |
jd0205 | 0:5a4b2c91de63 | 106 | if (onSeat(0.2)) //Checks if child is on the seat |
jd0205 | 0:5a4b2c91de63 | 107 | // 0.2 is very low, 0.5 for moderate touch, 0.8 for heavy pressing |
jd0205 | 0:5a4b2c91de63 | 108 | { |
jd0205 | 0:5a4b2c91de63 | 109 | led3 = 1; |
jd0205 | 0:5a4b2c91de63 | 110 | |
jd0205 | 0:5a4b2c91de63 | 111 | temp1 = readTemp(addr1, cmd1); //Read object temperature (C) |
jd0205 | 0:5a4b2c91de63 | 112 | temp2 = readTemp(addr2, cmd1); |
jd0205 | 0:5a4b2c91de63 | 113 | //temp3 = readTemp(addr1, cmd2); //Read ambient temperature (C) |
jd0205 | 0:5a4b2c91de63 | 114 | //temp4 = readTemp(addr2, cmd2); |
jd0205 | 0:5a4b2c91de63 | 115 | |
jd0205 | 0:5a4b2c91de63 | 116 | avgTemp = (temp1+temp2)/2; //Average value |
jd0205 | 0:5a4b2c91de63 | 117 | //avgTemp = (temp3+temp4)/2; |
jd0205 | 0:5a4b2c91de63 | 118 | printf("%5.2f\r\n",avgTemp); |
jd0205 | 0:5a4b2c91de63 | 119 | |
jd0205 | 0:5a4b2c91de63 | 120 | if ( avgTemp > 30) //If value exceed a "bad" temperature |
jd0205 | 0:5a4b2c91de63 | 121 | { |
jd0205 | 0:5a4b2c91de63 | 122 | led4 = 1; |
jd0205 | 0:5a4b2c91de63 | 123 | CtrlRelay = 1; //Turn on cooling system |
jd0205 | 0:5a4b2c91de63 | 124 | danger = true; |
jd0205 | 0:5a4b2c91de63 | 125 | } else if ( avgTemp < 25) //When it falls back down |
jd0205 | 0:5a4b2c91de63 | 126 | { |
jd0205 | 0:5a4b2c91de63 | 127 | led4 = 0; |
jd0205 | 0:5a4b2c91de63 | 128 | CtrlRelay = 0; //Turn off cooling system |
jd0205 | 0:5a4b2c91de63 | 129 | } |
jd0205 | 0:5a4b2c91de63 | 130 | if (danger) { //When child is in "danger" |
jd0205 | 0:5a4b2c91de63 | 131 | fona.sendSMS(pnum, message); //FONA will send message to the contact |
jd0205 | 0:5a4b2c91de63 | 132 | } |
jd0205 | 0:5a4b2c91de63 | 133 | } else { |
jd0205 | 0:5a4b2c91de63 | 134 | led3 = 0; |
jd0205 | 0:5a4b2c91de63 | 135 | led4 = 0; |
jd0205 | 0:5a4b2c91de63 | 136 | CtrlRelay = 0; //When child is no longer on the seat |
jd0205 | 0:5a4b2c91de63 | 137 | danger = false; //The system resets |
jd0205 | 0:5a4b2c91de63 | 138 | } |
jd0205 | 0:5a4b2c91de63 | 139 | wait(1); |
jd0205 | 0:5a4b2c91de63 | 140 | } |
jd0205 | 0:5a4b2c91de63 | 141 | } |
jd0205 | 0:5a4b2c91de63 | 142 | |
jd0205 | 0:5a4b2c91de63 | 143 | float readTemp(int addr, char* cmd) { //read the value from the MLX90614 |
jd0205 | 0:5a4b2c91de63 | 144 | i2c.write(addr, cmd, 1, true); |
jd0205 | 0:5a4b2c91de63 | 145 | i2c.read(addr, data, 3); //Two bytes of data + 1 word of codes |
jd0205 | 0:5a4b2c91de63 | 146 | |
jd0205 | 0:5a4b2c91de63 | 147 | temp = (((float)((data[1]<<8)|data[0]))*0.02) - 273.15; |
jd0205 | 0:5a4b2c91de63 | 148 | return temp; |
jd0205 | 0:5a4b2c91de63 | 149 | } |
jd0205 | 0:5a4b2c91de63 | 150 | |
jd0205 | 0:5a4b2c91de63 | 151 | bool onSeat(float fLevel) { //Detects child by activating enough pressure sensors |
jd0205 | 0:5a4b2c91de63 | 152 | onForce = 0; |
jd0205 | 0:5a4b2c91de63 | 153 | if (bottomFSR1.readRaw() > fLevel) { |
jd0205 | 0:5a4b2c91de63 | 154 | onForce += 1; |
jd0205 | 0:5a4b2c91de63 | 155 | } |
jd0205 | 0:5a4b2c91de63 | 156 | if (bottomFSR2.readRaw() > fLevel) { |
jd0205 | 0:5a4b2c91de63 | 157 | onForce += 1; |
jd0205 | 0:5a4b2c91de63 | 158 | } |
jd0205 | 0:5a4b2c91de63 | 159 | if (topFSR1.readRaw() > fLevel) { |
jd0205 | 0:5a4b2c91de63 | 160 | onForce += 1; |
jd0205 | 0:5a4b2c91de63 | 161 | } |
jd0205 | 0:5a4b2c91de63 | 162 | if (topFSR2.readRaw() > fLevel) { |
jd0205 | 0:5a4b2c91de63 | 163 | onForce += 1; |
jd0205 | 0:5a4b2c91de63 | 164 | } |
jd0205 | 0:5a4b2c91de63 | 165 | return onForce >= 2; |
jd0205 | 0:5a4b2c91de63 | 166 | } |
jd0205 | 0:5a4b2c91de63 | 167 | |
jd0205 | 0:5a4b2c91de63 | 168 | void callback(void) { //Rewrites the phone number saved in the SD card |
jd0205 | 0:5a4b2c91de63 | 169 | bt.gets(pnum,11); |
jd0205 | 0:5a4b2c91de63 | 170 | pcSerial.printf("New number: %s\n", pnum); |
jd0205 | 0:5a4b2c91de63 | 171 | |
jd0205 | 0:5a4b2c91de63 | 172 | FILE *fp = fopen("/sd/mydir/myphone.txt", "w"); |
jd0205 | 0:5a4b2c91de63 | 173 | if(fp == NULL) { |
jd0205 | 0:5a4b2c91de63 | 174 | error("Could not open file for write\n"); |
jd0205 | 0:5a4b2c91de63 | 175 | } |
jd0205 | 0:5a4b2c91de63 | 176 | fprintf(fp, "%s\n", pnum); |
jd0205 | 0:5a4b2c91de63 | 177 | fclose(fp); |
jd0205 | 0:5a4b2c91de63 | 178 | } |