Lambert kavamahanga / Mbed 2 deprecated smart_watch_final_Project

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lambert2021
Date:
Mon Jul 12 13:10:05 2021 +0000
Parent:
3:91e5fdf68f0c
Commit message:
the final project of Smart_watch

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jul 11 20:54:26 2021 +0000
+++ b/main.cpp	Mon Jul 12 13:10:05 2021 +0000
@@ -2,77 +2,53 @@
 #include "C12832.h"
 #include "Sht31.h"
 #include <string>
-#include "Timer.h"
+#include "time.h"
 
-Timer timer;
-Serial device (p9,p10);
 C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11);
-Sht31 theo(I2C_SDA, I2C_SCL);
-DigitalOut led(p13);
-DigitalOut bed(p12);
-DigitalOut wed(p14);
-InterruptIn  btn(p15);
+Sht31 Sht31(I2C_SDA, I2C_SCL);
+DigitalOut led(p5);
+DigitalOut bed(p6);
+DigitalOut wed(p7);
+Serial device (p9,p10);
+InterruptIn  btn(p10);
 InterruptIn  swt(p11);
 
-int direction=0;
-bool forwards=true;
-int current=0;
-int mode=0;
-int btnState=1;
-int butnDuration = 0;
- int j;
- int k;
+time_t startTime,startReading,  stopTime,stopReading;
+Timeout t;
+Ticker topicTicker,durationTime,resetted, backagain,  k;
+int i=0, direction=0, pushDuration, current=0, state=0, readingDuration;
  
-time_t butnTimerStart;
-time_t butnTimerStop;
 string str1 = " OUR SERVICE ";
-string str2 = " HMS Clinic ";
+string str2 = " HMS CLINIC";
 string str3= " HMS COMPANY \n Client line:+250788312890";
-string topics[]={"OUR SERVICE ", 
-"1.Body Temperature",
-"2. Pulse Rate", 
-"3.Respiration Rate OR \n Rate of Breathing",
-"4. Blood pressure ",
-"5.Press swich for more info",
-};
-string content[]={
-"01.HMS is Smart watch clinic",
-"02.our clinic work 24h",
-"03.we have profectional,doctors,Nurce ", 
-"22.we provide advice,for food, Training Sport",
-"33.This Excellent clinic service",
-"44.it was inverted with Master's students",
-"55.From University of Rwanda in IOT"
-};
+string topics[]={"OUR SERVICE\n1.Body Temperature", "2. Pulse Rate", "3.Respiration Rate OR \n Rate of Breathing",
+"4. Blood pressure", "5.Press swich for more info"};
+
+string content[]={ "1A.this's Smartwatch clinic", "2A.our clinic work 24h","3A.we've provide training Sport\nwe profectional,doctors", 
+"4A.Our Excellent service \nB. was inverted in UR-ACEIOT", "5A.HMS COMPANY \nB.Client line:+250788312890" };
+
 void display(string sms){
     lcd.cls(); // change dane here
-    lcd.locate(2,5);
+    lcd.locate(3,2);
     lcd.printf(sms.c_str());
 }
-void displaycontent(){
-    mode=1;
-    display(content[current]);
-    wait_ms(1000);
+ 
+void welcomeMsg(){
+    display(str2);
 }
-void whiteled(){
-    wed=1;
-    wait_ms(500);
-    wed=0;
-    wait_ms(500);
+void whiteled(){ wed=!wed;
 }
-void scrol(){
-  int i;
-        float temp = theo.readTemperature();
+void scrolState1(){ 
+        float temp = Sht31.readTemperature();
         time_t seconds = time(NULL);
         char buffer[32];
         strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
         lcd.locate(5, 20); // get cursor to position x=3px and y=5px
         whiteled();
         wait(3);
-        lcd.cls(); 
         lcd.set_auto_up(0);
         lcd.setmode(XOR);
-    for (i = 0; i <5; i++) { // scrolling text
+    for (i = -12; i <12; i++) { // scrolling text
         lcd.locate(5, i);
         lcd.printf("Local Time: %s",buffer);
         lcd.locate(5, i + 12);
@@ -86,83 +62,93 @@
          i = i + 1;
        }  }
 
-void function(){
-   j=0;
-    while(j<6 && mode==0){
-         whiteled();
-    display(topics[j]);
-    current=j;
-     wait_ms(2000);
-    j++;
-    }}
-
-void function2(){
-    k=5;
-    while(k>=0 && mode==0){
-         whiteled();
-    display(topics[k]);
-    current=k;
-     wait_ms(2000);
-    k--;
-    }}
-   
-void changedirection(){
-   wait_ms(3000);
-  direction=0;
-  bed=1;
-  if(direction==0){
-      bed=led;
-      led=!bed;
+void forwards(){ lcd.cls();
+   display(topics[i]);
+   current=i;
+   i+=1;
+   if(i>4){
+       i=0;
+   }
+}
+void backwards(){
+  display(topics[i]);
+  current=i;
+  i-=1;
+  if(i<0){
+      i=4;
   }
-  if(forwards){
-      forwards=!forwards;
-      function();
-       display(str3);
-      
-  }else{
-      forwards=!forwards;
-      function2();
-       display(str3);
-  } }
-
-void StartButtonTimer(){
-     time_t seconds = time(NULL);
-        char buffer[32];
-        strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
-    printf("Button Timer start \n");
-    butnTimerStart = strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
-   //butnTimerStop=stoptime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
-    printf("Button timer start: %d \n",butnTimerStart);
-    wait(0.5);
-    butnDuration =  butnTimerStart;
-     printf("Duration Button: %d \n", butnDuration); 
-      if(btnState==1 && butnDuration>=10) {
-        lcd.cls();
-        lcd.locate(0,0);
-        lcd.printf("Reset to factory ....");
-        wait(10);
-        display(str2);
-        function();
-      }else{
-   changedirection();
-} }
-
-void mode1(){
-    mode=0;
-    display(str3);
+}
+void scrolState2(){
+     if(direction==0){
+        i=0;
+        bed=!led;
+         bed=1; led=0;
+         topicTicker.attach(callback(&forwards),2.0f);
+     } else{ lcd.cls(); 
+         i=4;
+         led=!bed;
+         led=1; bed=0;
+         topicTicker.attach(callback(& backwards),2.0f);
+     }
+ }
+ 
+  void fallBtn() {state = 0;
+ }
+ void mode1(){
+    k.attach(callback(& whiteled),1.0f);
+    lcd.cls();
+     scrolState1();
+     t.attach(callback(&scrolState2), 3.0f);
+ }
+  
+void riseSwt(){
+    time(&startReading);
+     display(content[current]);
+    topicTicker.detach();
 }
-void released(){
-    direction=1;
+void fallSwt(){
+    topicTicker.detach();
+    time(&stopReading);
+    readingDuration=stopReading-startReading;
+    printf("Reading time is:%d \n",readingDuration);
+    if(readingDuration>5){
+        printf("message sent,Item Id is:%d \n",current+1);
+    }
+   scrolState2();    //......................................
 }
+void countDuration(){
+     time(&stopTime);
+         pushDuration=stopTime-startTime;
+            if(pushDuration>5){
+            display("Reset to resetting..");
+            durationTime.detach();
+            topicTicker.detach();
+            resetted.attach(callback(&welcomeMsg),10.0f);
+            direction=!direction;
+            backagain.attach(callback(&mode1),5.0f);
+            lcd.cls();
+            }
+        else if(pushDuration>3 && state==0 ){
+            lcd.cls();
+            display("try again..");
+            wait_ms(1000);
+            state =0;
+            direction=!direction;
+            scrolState2();
+         }
+ }
+ void riseBtn(){
+     time(&startTime);
+     durationTime.attach(callback(&countDuration),0.5f);
+ }
+ 
 int main() {
-    lcd.locate(5,5);
-    display(str2);
-    wait_ms(5000);
-    scrol();
-    btn.fall(callback(&released));
-    btn.rise(callback(&StartButtonTimer));
-    swt.rise(callback(&displaycontent));
-    swt.fall(callback(&mode1));
-    function();
-   display(str3);
+    lcd.cls(); 
+    lcd.set_auto_up(0);
+    welcomeMsg();
+    t.attach(callback(&mode1),5.0f);
+     btn.rise(callback(&riseBtn));
+     btn.fall(callback(&fallBtn));
+     swt.rise(callback(&riseSwt));
+   swt.fall(callback(&fallSwt));
 }
\ No newline at end of file