Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ATParser TSL2561 mbed
Revision 4:ea91348c1e16, committed 2018-04-24
- Comitter:
- youngs2
- Date:
- Tue Apr 24 14:44:13 2018 +0000
- Parent:
- 3:9d465264c741
- Commit message:
- initial
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Apr 18 14:23:52 2018 +0000
+++ b/main.cpp Tue Apr 24 14:44:13 2018 +0000
@@ -8,18 +8,47 @@
BufferedSerial device(PA_9, PA_10); // tx, rx
DigitalOut myled(LED1);
TSL2561 lightsensor(PB_7,PB_6);
+LowPowerTicker flipper;
+DigitalOut Teddy(D8);
+ATParser at = ATParser(device, "\n\r", 256, 2000, false);
-int main()
+int i =0;
+char *day[5];
+
+
+void sendit()
+{
+ float lightnum = lightsensor.lux();
+ pc.printf("light = %.5f\n\r", lightnum);
+ day[i] = new char[8];
+ sprintf(day[i], "%f", lightnum);
+ i++;
+ if (i == 5)
+ {
+ Teddy = 1;
+ int j;
+ for(j = 0; j < 5; j++)
+ {
+ if(at.send("AT+SEND=\"%s\"", day[j]) && 1)
+ {
+ pc.printf("success\n\r");
+ }
+ else
+ pc.printf("iserox\n\r");
+ }
+ Teddy = 0;
+ i = 0;
+ for(j=0; j < 5; j++)
+ {
+ free(day[j]);
+ }
+ }
+}
+
+void connect()
{
- pc.baud(115200);
- device.baud(115200);
- pc.printf("Hola\n\r");
- ATParser at = ATParser(device, "\n\r", 256, 2000, false);
if(at.send("AT") && at.recv("\n\r"))
- {
pc.printf("Bueno#1\n\r");
- myled = !myled;
- }
else
pc.printf("Nope#1\n\r");
if(at.send("AT+NI=1,MTCDT-19400691") && 1)
@@ -37,50 +66,20 @@
if(at.send("AT+JOIN")&& 1)
pc.printf("Bueno #5\n\r");
else
- pc.printf("Nope #5\n\r");
-
- char devID[24];
- if(at.send("AT+DI") && at.recv("%s\r\n\r\nOK", &devID))
- pc.printf("Bueno#6\n\r");
- else
- pc.printf("Nope #6\n\r");
-
- int i = 0;
- char *day[24];
+ pc.printf("Nope #5\n\r");
+}
+
-
+int main()
+{
+ pc.baud(115200);
+ device.baud(115200);
+ pc.printf("Hola\n\r");
+ Teddy = 0;
+ connect();
+ flipper.attach(&sendit, 10);
while(1)
{
- float lightnum = lightsensor.lux();
- pc.printf("light = %.5f\n\r", lightnum);
- //char light = malloc(10);
- //light = new char [8];
- day[i] = new char[8];
- int n;
- n = sprintf(day[i], "%.5f", lightnum);
- //pc.printf("String transfer worked: %s\n\r", day[i]);
- i++;
- if (i == 24)
- {
- int j;
- for(j = 0; j < 24; j++)
- {
- if(at.send("AT+SEND=\"%s\"", day[j]) && 1)
- {
- //pc.printf("%s\n\r", day[j]);
- pc.printf("success\n\r");
- //wait(.1);
- }
- else
- pc.printf("iserox\n\r");
- }
- i = 0;
- for(j=0; j < 24; j++)
- {
- free(day[j]);
- }
-
- }
- wait(3600);
+ wait(420);
}
}