displays services offered by facilities offering civilian services with short summaries
Dependencies: mbed Sht31 C12832
Revision 5:9b8f87a5a415, committed 2021-01-28
- Comitter:
- ogore
- Date:
- Thu Jan 28 19:09:05 2021 +0000
- Parent:
- 4:b6d479319713
- Commit message:
- jan 2th
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b6d479319713 -r 9b8f87a5a415 main.cpp --- a/main.cpp Sat Jan 23 19:44:03 2021 +0000 +++ b/main.cpp Thu Jan 28 19:09:05 2021 +0000 @@ -1,34 +1,28 @@ - -#include "mbed.h" // Include the library of Mbed -#include "C12832.h" // Include the library of the specific LCD +#include "mbed.h" +#include "C12832.h" #include "Sht31.h" - DigitalOut blueled(p17, 0); // Initializing the yellow light OFF DigitalOut redled(p15, 0); // Initializing the red light OFF DigitalOut whiteled(p19, 0); // Initializing the red light OFF C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11); // create an instance of LCD +Sht31 sht31(I2C_SDA, I2C_SCL); DigitalIn switchmode(p24); InterruptIn button(p20); int i=0; -int difference=0; -int endtime; -int starttime; int k=0; int maxtopics=5; int d=1; +Timer t; +time_t rise_seconds; +time_t fall_seconds; +int duration; //initialize topics, summaries and welcome message -const char *myArray[5][2] = { { "ID", "ASSIGNING OF IDENTIFICATION CARDS TO CITIZENS1" }, { "VISA", "PROVISIONING OF VISA TO FOREIGNERS" }, +const char *myArray[5][2] = { { "ID", "ASSIGNING OF IDENTIFICATION CARDS TO CITIZENS" }, { "VISA", "PROVISIONING OF VISA TO FOREIGNERS" }, {"PASSPORT"," PASSPORT ASSIGNMENT TO APPLICANTS"},{ "BIRTH CERTIFICATE","APPLICATION OF BIRTH REGISTRATION"}, {"DRIVING LICENSES","APPLICATION AND PROVISIONING OF DRIVING LINCENCE"}}; char welcome_message[]="Center for Government Services"; -//function for white led blinking every second - void blink(){ - whiteled=1; - wait(1); - whiteled=0; - wait(1); - } + //function for displaying message static void display(const char *message) { lcd.cls(); // Clear LCD @@ -36,36 +30,36 @@ lcd.printf(message); // Write text into LCD buffer lcd.copy_to_lcd(); } -void buttonpress() - { - difference=0; - set_time(1256729737); - time_t seconds = time(NULL); - starttime = (unsigned int)seconds; - printf(" %d",starttime); - while(button==1 && difference<=3) - { - wait(1); - time_t seconds2 = time(NULL); - endtime = (unsigned int)seconds2; - printf(" %d",endtime); - difference=endtime-starttime; - } - difference=(difference*difference)/difference; - if(difference>3) +void fallISR() { + t.start(); + fall_seconds = time(NULL); + } +void riseISR() +{ + t.stop(); + rise_seconds = time(NULL); + duration = rise_seconds-fall_seconds; + //printf("\nthe duration is %d",duration); + if(duration>3) { d=d*-1; } - printf("\nthe difference is %d",difference); - } - void buttonrelease() - { -if(difference<=3) + i=i+d; +} + //function to display topic and summary*/ +void display_message(const char *topic,const char *summary, int i) { - k=0; - i=i+d; + + display(topic); + wait(1); + display(summary); } -if(d<0) + //function for mode two +void Reading() +{ + while(switchmode) + { + if(d<0) { redled=1; blueled=0; @@ -75,45 +69,17 @@ blueled=1; redled=0; } - } - - //function to display topic and summary*/ -void display_message(const char *topic,const char *summary, int i) -{ - - display(topic); - wait(1); - display(summary); - //for loop helps read how long a summary is open using a k value - -} + k=k+1; - //function for mode two -void Reading() -{ - - set_time(1); - button.rise(&buttonpress); - button.fall(&buttonrelease); - printf("entered mode two\n"); - wait(2); - -while(switchmode) -{ - k=k+2; - //call dispay of topic that will display according to value of i - //value of i is determined by myDuration - - if(i==0 || i>4) + if(i==0 || i>4) { //in ascending order if i goes above 4 display myArray[0][0] //if i>4 make i =0 i=0; } - -else if(i==4 || i<0 ) -//in descending order if i goes below zero display myArray[4][0] -//if i<0 make i=4 + else if(i==4 || i<0 ) + //in descending order if i goes below zero display myArray[4][0] + //if i<0 make i=4 { i=4; } @@ -121,46 +87,45 @@ if(k>4) { printf("\n topic ID is=%d and reading duration is %d seconds",i,k); + k=0; } wait(1); -} -} - -void looping() -{ - - blink();//white led blinks every second - time_t seconds = time(NULL); + } + !switchmode; - //float temp = sht31.readTemperature(); //read temperature - lcd.locate(5, 5); // get cursor to position x=5px and y=5px - // lcd.printf("Current Temperature: %.2fC",temp);//display temp - lcd.locate(5, 5); // get cursor to position x=5px and y=5px - lcd.printf("Current Time in seconds is: %u",(unsigned int)seconds); //display time - wait(3); -while(i<maxtopics) -{ +} +void looping() + { while(!switchmode) { - if(i==0 || i>4) - { - //in ascending order if i goes above 4 display myArray[0][0] - //if i>4 make i =0 - i=0; + i=0; + time_t seconds = time(NULL); + float temp = sht31.readTemperature(); //read temperature + lcd.locate(5, 5); // get cursor to position x=5px and y=5px + lcd.printf("Current Temperature: %.2fC",temp);//display temp + lcd.locate(5, 5); // get cursor to position x=5px and y=5px + lcd.printf("Current Time in seconds is: %d",(unsigned int)seconds); //display time + //wait(3); + while(i<maxtopics) + { + whiteled=1; + //with the value of i, when you enter mode two you see summary of the topic displayed when you entered mode two + display(myArray[i][0]); + whiteled=0; + i++; + wait(2); + } + Reading(); + wait(1); + } + } - //with the value of i, when you enter mode two you see summary of the topic displayed when you entered mode two - display(myArray[i][0]); - i++; - wait(2); - } - Reading(); -wait(1); -} -} + int main() { -display(welcome_message);//show welcome message - -looping(); + set_time(1256729737); + button.fall(&fallISR); + button.rise(&riseISR); + display(welcome_message);//show welcome message + looping(); } -