![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proejct2
main.cpp
- Committer:
- Jamesan
- Date:
- 2020-05-04
- Revision:
- 10:781cd74506e9
- Parent:
- 9:73600707c93b
File content as of revision 10:781cd74506e9:
#include "mbed.h" #include <stdio.h> #include <string.h> #include "Servo.h" Serial pc(USBTX,USBRX); //Bluetooth module declaration Serial blue(PTC17, PTC16); //Led declaration DigitalOut Redl(LED1); DigitalOut Bluel(LED3); DigitalOut Greenl(LED2); Servo myservo(D3); char k; char a; int c =0; char ser = 'L'; int main() { pc.baud(9600); Greenl = 1; //FRDM LED initially OFF Bluel = 1; //FRDM LED initially OFF Redl = 0; //FRDM LED initially OFF k = 'T'; pc.printf("\n\r Door locked"); pc.printf("\n\r Lights off"); while(1) { myservo.write(0.5); //motor stays off if(blue.readable()> 0) { c = blue.getc(); pc.printf("\n\rbluetooth"); pc.printf("\n\r %ld",c); k = 'T'; } if (k == 'T') { if (c == 1) { pc.printf("\n\rDoor unlocked"); pc.printf("\n\rKitchen light switched on"); pc.printf("\n\rLiving room light switched on"); Greenl = 0; Bluel = 0; if (ser == 'L') { myservo.write(0.6); wait(0.3); myservo.write(0.5); ser = 'U'; } Redl = 1; k = 'F'; } else if (c == 2) { pc.printf("\n\rDoor locked"); pc.printf("\n\rKitchen light switched on"); pc.printf("\n\rLiving room light switched on"); Greenl = 0; Bluel = 0; if (ser == 'U') { myservo.write(0.4); wait(0.3); myservo.write(0.5); ser = 'L'; } Redl = 1; k = 'F'; } else if (c == 3) { pc.printf("\n\rDoor unlocked"); pc.printf("\n\rKitchen light switched on"); pc.printf("\n\rLiving room light switched off"); Greenl = 1; Bluel = 0; pc.printf("\n\r %ld",ser); if (ser == 'L') { myservo.write(0.6); wait(0.3); myservo.write(0.5); ser = 'U'; } Redl = 1; k = 'F'; } else if (c == 4) { pc.printf("\n\rDoor unlocked"); pc.printf("\n\rKitchen light switched off"); pc.printf("\n\rLiving room light switched on"); Greenl = 0; Bluel = 1; if (ser == 'L') { myservo.write(0.6); wait(0.3); myservo.write(0.5); ser = 'U'; } Redl = 1; k = 'F'; } else if (c == 5) { pc.printf("\n\rDoor locked"); pc.printf("\n\rKitchen light switched on"); pc.printf("\n\rLiving room light switched off"); Greenl = 1; Bluel = 0; if (ser == 'U') { myservo.write(0.4); wait(0.3); myservo.write(0.5); ser = 'L'; } Redl = 1; k = 'F'; } else if (c == 6) { pc.printf("\n\rDoor unlocked"); pc.printf("\n\rKitchen light switched off"); pc.printf("\n\rLiving room light switched off"); Greenl = 1; Bluel = 1; if (ser == 'U') { myservo.write(0.4); wait(0.3); myservo.write(0.5); ser = 'L'; } Redl = 1; k = 'F'; } else if (c == 7) { pc.printf("\n\rDoor locked"); pc.printf("\n\rKitchen light switched off"); pc.printf("\n\rLiving room light switched on"); Greenl = 0; Bluel = 1; if (ser == 'U') { myservo.write(0.4); wait(0.3); myservo.write(0.5); ser = 'L'; } Redl = 1; k = 'F'; } else if (c == 8) { pc.printf("\n\rDoor locked"); pc.printf("\n\rKitchen light switched off"); pc.printf("\n\rLiving room light switched off"); Greenl = 1; Bluel = 1; if (ser == 'U') { myservo.write(0.4); wait(0.3); myservo.write(0.5); ser = 'L'; } Redl = 1; k = 'F'; } } } }