Umurerwa Marie Adeline / Mbed 2 deprecated Groupe8

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*5G SOLUTIONS LTD PROJECT
00002 GROUP 8 MEMBERS:
00003 TUYISHIMIRE Joseph         220019455     tuyishimirejo1992@gmail.com
00004 DUSHIME Jean Claude        22100862      engdushime@gmail.com
00005 NTIRANTA Jean Claude       221000136     nclause022@gmail.com 
00006 HIRWA Vestine              221002491     gilhirwa22@gmail.com
00007 UMURERWA Marie Adeline     220020230     rerwad26@gmail.com */
00008  
00009  
00010 #include "mbed.h"
00011 #include "C12832.h"
00012 #include "Sht31.h"
00013 #include <string>
00014 #include "time.h"
00015  
00016 C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11);
00017 Sht31 sh31(I2C_SDA, I2C_SCL);
00018 Serial device (p9,p10);
00019  
00020 DigitalOut ledled(p6);
00021 DigitalOut blueled(p9);
00022 DigitalOut whiteled(p5);
00023 InterruptIn  button(p14);
00024 InterruptIn  switchbtn(p15);
00025  
00026  
00027 Timeout x;
00028 Ticker w;
00029 Ticker titleTicker;
00030 Ticker durationTime;
00031 Ticker reset;
00032 Ticker backagain;
00033 
00034 int i;
00035 int direction=0;
00036 int situation=0;
00037 int status=0;
00038 int y=0;
00039 int pressDuration;
00040 int readingDuration;
00041  
00042  
00043  time_t startTime;
00044  time_t stopTime;
00045  time_t startReading;
00046  time_t stopReading;
00047 
00048 
00049 string val1 = "Welcome to 5G Solutions Ltd";
00050 string titles[]={"1.Smart glasses for blind people",
00051 "2.Smart Tv","3.Smart Phones",
00052 "4.Smart fridges",
00053 "5.Smart Cameras "
00054 };
00055 string content[]={"11.For kids and old people",
00056 "22.Samsung,sony and Hisense","33.Tecno,samsung,sony and AT&T",
00057 "44.Hisense,Super General and Samsung",
00058 "55.Canon,Nikon and Sony "};
00059 
00060 void display(string sms){
00061     lcd.cls(); // clear screen
00062     lcd.locate(0,0);
00063     lcd.printf(sms.c_str());
00064 } 
00065  
00066 void displaymsg(){
00067     display(val1);
00068 }
00069 void printState1(){
00070        
00071         float temp = sh31.readTemperature();
00072         time_t seconds = time(NULL);
00073         char buffer[32];
00074         strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
00075         lcd.locate(5, 20); // get cursor to position x=3px and y=5px
00076         wait(3);
00077         lcd.cls(); 
00078      lcd.set_auto_up(0);
00079     lcd.setmode(XOR);
00080     for (i = -20; i <5; i++) { // scrolling text
00081         lcd.locate(5, i);
00082         lcd.printf("Local Time: %s",buffer);
00083         lcd.locate(5, i + 12);
00084         lcd.printf("Temperature: %.2f C", temp);
00085         lcd.copy_to_lcd();
00086         lcd.locate(5, i);
00087         wait(0.2);
00088         lcd.printf("Local Time: %s",buffer);
00089         lcd.locate(5, i + 12);
00090         lcd.printf("Temperature: %.2f C", temp);
00091         lcd.cls();
00092          i = i + 1;
00093  
00094 }
00095 }
00096  
00097  void whiteledblinking()
00098 {
00099     whiteled=!whiteled;
00100 }
00101 void nexttitle(){
00102    display(titles[y]);
00103          situation=y;
00104    y+=1;
00105    if(y>4){
00106        y=0;
00107    
00108 }
00109 }
00110 void previoustitle(){
00111   display(titles[y]);
00112   situation=y;
00113   y-=1;
00114   if(y<0){
00115       y=4;
00116   }
00117 }
00118 void printState2(){
00119     printf("direction %d \n",direction);
00120      if(direction==0){
00121          y=0;
00122           blueled=1;
00123     ledled=0;
00124          titleTicker.attach(callback(&nexttitle),2.0f);
00125      }
00126      else{
00127          y=4;
00128   ledled=1;
00129    blueled=0;
00130          titleTicker.attach(callback(& previoustitle),2.0f);
00131      }
00132  }
00133  
00134   void restbutton(){
00135      status = 0;
00136      durationTime.detach();
00137  
00138  }
00139  
00140  void restswitch(){
00141     titleTicker.detach();
00142     time(&stopReading);
00143     readingDuration=stopReading-startReading;
00144     printf("Reading duration is:%d \n",readingDuration);
00145     if(readingDuration>5){
00146         printf("message sent,current topic Id is:%d \n",situation+1);
00147     }
00148     printState2();    
00149 }
00150  void mode1(){
00151     w.attach(callback(& whiteledblinking),1.0f);
00152      printState1();
00153      x.attach(callback(&printState2),3.0f);
00154     
00155  }
00156   
00157 void rissingswitch(){
00158     time(&startReading);
00159      display(content[situation]);
00160     titleTicker.detach();
00161     
00162     
00163 }
00164 
00165 void countDuration(){
00166      time(&stopTime);
00167          pressDuration=stopTime-startTime;
00168          printf("elapsed time is:%d \n",pressDuration);
00169             if(pressDuration>5){
00170             display("Reset to factory......\n");
00171             durationTime.detach();
00172              titleTicker.detach();
00173             reset.attach(callback(&displaymsg),10.0f);
00174              direction=!direction;
00175             backagain.attach(callback(&mode1),15.0f);
00176             
00177             }
00178         else if(pressDuration>=3 && status==0 ){
00179              status=1;
00180              printf("direction changed %d \n",direction);
00181              direction=!direction;
00182              printState2();
00183              
00184          }
00185  }
00186  void rissingbutton(){
00187      time(&startTime);
00188      durationTime.attach(callback(&countDuration),0.5f);
00189  
00190  }
00191 int main() {
00192     displaymsg();
00193     x.attach(callback(&mode1),5.0f);
00194      button.rise(callback(&rissingbutton));
00195      button.fall(callback(&restbutton));
00196      switchbtn.rise(callback(&rissingswitch));
00197    switchbtn.fall(callback(&restswitch));
00198 }