displays services offered by facilities offering civilian services with short summaries
Dependencies: mbed Sht31 C12832
main.cpp@5:9b8f87a5a415, 2021-01-28 (annotated)
- Committer:
- ogore
- Date:
- Thu Jan 28 19:09:05 2021 +0000
- Revision:
- 5:9b8f87a5a415
- Parent:
- 4:b6d479319713
jan 2th
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ogore | 5:9b8f87a5a415 | 1 | #include "mbed.h" |
| ogore | 5:9b8f87a5a415 | 2 | #include "C12832.h" |
| ogore | 3:e35c945dd091 | 3 | #include "Sht31.h" |
| ogore | 4:b6d479319713 | 4 | |
| ogore | 0:2ed38e8fcbc8 | 5 | DigitalOut blueled(p17, 0); // Initializing the yellow light OFF |
| ogore | 0:2ed38e8fcbc8 | 6 | DigitalOut redled(p15, 0); // Initializing the red light OFF |
| ogore | 0:2ed38e8fcbc8 | 7 | DigitalOut whiteled(p19, 0); // Initializing the red light OFF |
| ogore | 0:2ed38e8fcbc8 | 8 | C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11); // create an instance of LCD |
| ogore | 5:9b8f87a5a415 | 9 | Sht31 sht31(I2C_SDA, I2C_SCL); |
| ogore | 4:b6d479319713 | 10 | DigitalIn switchmode(p24); |
| ogore | 0:2ed38e8fcbc8 | 11 | InterruptIn button(p20); |
| ogore | 0:2ed38e8fcbc8 | 12 | int i=0; |
| ogore | 0:2ed38e8fcbc8 | 13 | int k=0; |
| ogore | 4:b6d479319713 | 14 | int maxtopics=5; |
| ogore | 4:b6d479319713 | 15 | int d=1; |
| ogore | 5:9b8f87a5a415 | 16 | Timer t; |
| ogore | 5:9b8f87a5a415 | 17 | time_t rise_seconds; |
| ogore | 5:9b8f87a5a415 | 18 | time_t fall_seconds; |
| ogore | 5:9b8f87a5a415 | 19 | int duration; |
| ogore | 0:2ed38e8fcbc8 | 20 | //initialize topics, summaries and welcome message |
| ogore | 5:9b8f87a5a415 | 21 | const char *myArray[5][2] = { { "ID", "ASSIGNING OF IDENTIFICATION CARDS TO CITIZENS" }, { "VISA", "PROVISIONING OF VISA TO FOREIGNERS" }, |
| ogore | 3:e35c945dd091 | 22 | {"PASSPORT"," PASSPORT ASSIGNMENT TO APPLICANTS"},{ "BIRTH CERTIFICATE","APPLICATION OF BIRTH REGISTRATION"}, |
| ogore | 3:e35c945dd091 | 23 | {"DRIVING LICENSES","APPLICATION AND PROVISIONING OF DRIVING LINCENCE"}}; |
| ogore | 3:e35c945dd091 | 24 | char welcome_message[]="Center for Government Services"; |
| ogore | 5:9b8f87a5a415 | 25 | |
| ogore | 0:2ed38e8fcbc8 | 26 | //function for displaying message |
| ogore | 3:e35c945dd091 | 27 | static void display(const char *message) { |
| ogore | 0:2ed38e8fcbc8 | 28 | lcd.cls(); // Clear LCD |
| ogore | 0:2ed38e8fcbc8 | 29 | lcd.locate(10, 5); // get cursor to position x=3px and y=5px |
| ogore | 0:2ed38e8fcbc8 | 30 | lcd.printf(message); // Write text into LCD buffer |
| ogore | 0:2ed38e8fcbc8 | 31 | lcd.copy_to_lcd(); |
| ogore | 0:2ed38e8fcbc8 | 32 | } |
| ogore | 5:9b8f87a5a415 | 33 | void fallISR() { |
| ogore | 5:9b8f87a5a415 | 34 | t.start(); |
| ogore | 5:9b8f87a5a415 | 35 | fall_seconds = time(NULL); |
| ogore | 5:9b8f87a5a415 | 36 | } |
| ogore | 5:9b8f87a5a415 | 37 | void riseISR() |
| ogore | 5:9b8f87a5a415 | 38 | { |
| ogore | 5:9b8f87a5a415 | 39 | t.stop(); |
| ogore | 5:9b8f87a5a415 | 40 | rise_seconds = time(NULL); |
| ogore | 5:9b8f87a5a415 | 41 | duration = rise_seconds-fall_seconds; |
| ogore | 5:9b8f87a5a415 | 42 | //printf("\nthe duration is %d",duration); |
| ogore | 5:9b8f87a5a415 | 43 | if(duration>3) |
| ogore | 4:b6d479319713 | 44 | { |
| ogore | 4:b6d479319713 | 45 | d=d*-1; |
| ogore | 4:b6d479319713 | 46 | } |
| ogore | 5:9b8f87a5a415 | 47 | i=i+d; |
| ogore | 5:9b8f87a5a415 | 48 | } |
| ogore | 5:9b8f87a5a415 | 49 | //function to display topic and summary*/ |
| ogore | 5:9b8f87a5a415 | 50 | void display_message(const char *topic,const char *summary, int i) |
| ogore | 4:b6d479319713 | 51 | { |
| ogore | 5:9b8f87a5a415 | 52 | |
| ogore | 5:9b8f87a5a415 | 53 | display(topic); |
| ogore | 5:9b8f87a5a415 | 54 | wait(1); |
| ogore | 5:9b8f87a5a415 | 55 | display(summary); |
| ogore | 4:b6d479319713 | 56 | } |
| ogore | 5:9b8f87a5a415 | 57 | //function for mode two |
| ogore | 5:9b8f87a5a415 | 58 | void Reading() |
| ogore | 5:9b8f87a5a415 | 59 | { |
| ogore | 5:9b8f87a5a415 | 60 | while(switchmode) |
| ogore | 5:9b8f87a5a415 | 61 | { |
| ogore | 5:9b8f87a5a415 | 62 | if(d<0) |
| ogore | 4:b6d479319713 | 63 | { |
| ogore | 4:b6d479319713 | 64 | redled=1; |
| ogore | 4:b6d479319713 | 65 | blueled=0; |
| ogore | 4:b6d479319713 | 66 | } |
| ogore | 4:b6d479319713 | 67 | else |
| ogore | 4:b6d479319713 | 68 | { |
| ogore | 4:b6d479319713 | 69 | blueled=1; |
| ogore | 3:e35c945dd091 | 70 | redled=0; |
| ogore | 4:b6d479319713 | 71 | } |
| ogore | 5:9b8f87a5a415 | 72 | k=k+1; |
| ogore | 4:b6d479319713 | 73 | |
| ogore | 5:9b8f87a5a415 | 74 | if(i==0 || i>4) |
| ogore | 0:2ed38e8fcbc8 | 75 | { |
| ogore | 3:e35c945dd091 | 76 | //in ascending order if i goes above 4 display myArray[0][0] |
| ogore | 0:2ed38e8fcbc8 | 77 | //if i>4 make i =0 |
| ogore | 0:2ed38e8fcbc8 | 78 | i=0; |
| ogore | 0:2ed38e8fcbc8 | 79 | } |
| ogore | 5:9b8f87a5a415 | 80 | else if(i==4 || i<0 ) |
| ogore | 5:9b8f87a5a415 | 81 | //in descending order if i goes below zero display myArray[4][0] |
| ogore | 5:9b8f87a5a415 | 82 | //if i<0 make i=4 |
| ogore | 0:2ed38e8fcbc8 | 83 | { |
| ogore | 0:2ed38e8fcbc8 | 84 | i=4; |
| ogore | 0:2ed38e8fcbc8 | 85 | } |
| ogore | 3:e35c945dd091 | 86 | display_message(myArray[i][0],myArray[i][1],i); |
| ogore | 3:e35c945dd091 | 87 | if(k>4) |
| ogore | 3:e35c945dd091 | 88 | { |
| ogore | 3:e35c945dd091 | 89 | printf("\n topic ID is=%d and reading duration is %d seconds",i,k); |
| ogore | 5:9b8f87a5a415 | 90 | k=0; |
| ogore | 3:e35c945dd091 | 91 | } |
| ogore | 3:e35c945dd091 | 92 | wait(1); |
| ogore | 5:9b8f87a5a415 | 93 | } |
| ogore | 5:9b8f87a5a415 | 94 | !switchmode; |
| ogore | 3:e35c945dd091 | 95 | |
| ogore | 5:9b8f87a5a415 | 96 | } |
| ogore | 5:9b8f87a5a415 | 97 | void looping() |
| ogore | 5:9b8f87a5a415 | 98 | { |
| ogore | 4:b6d479319713 | 99 | while(!switchmode) |
| ogore | 3:e35c945dd091 | 100 | { |
| ogore | 5:9b8f87a5a415 | 101 | i=0; |
| ogore | 5:9b8f87a5a415 | 102 | time_t seconds = time(NULL); |
| ogore | 5:9b8f87a5a415 | 103 | float temp = sht31.readTemperature(); //read temperature |
| ogore | 5:9b8f87a5a415 | 104 | lcd.locate(5, 5); // get cursor to position x=5px and y=5px |
| ogore | 5:9b8f87a5a415 | 105 | lcd.printf("Current Temperature: %.2fC",temp);//display temp |
| ogore | 5:9b8f87a5a415 | 106 | lcd.locate(5, 5); // get cursor to position x=5px and y=5px |
| ogore | 5:9b8f87a5a415 | 107 | lcd.printf("Current Time in seconds is: %d",(unsigned int)seconds); //display time |
| ogore | 5:9b8f87a5a415 | 108 | //wait(3); |
| ogore | 5:9b8f87a5a415 | 109 | while(i<maxtopics) |
| ogore | 5:9b8f87a5a415 | 110 | { |
| ogore | 5:9b8f87a5a415 | 111 | whiteled=1; |
| ogore | 5:9b8f87a5a415 | 112 | //with the value of i, when you enter mode two you see summary of the topic displayed when you entered mode two |
| ogore | 5:9b8f87a5a415 | 113 | display(myArray[i][0]); |
| ogore | 5:9b8f87a5a415 | 114 | whiteled=0; |
| ogore | 5:9b8f87a5a415 | 115 | i++; |
| ogore | 5:9b8f87a5a415 | 116 | wait(2); |
| ogore | 5:9b8f87a5a415 | 117 | } |
| ogore | 5:9b8f87a5a415 | 118 | Reading(); |
| ogore | 5:9b8f87a5a415 | 119 | wait(1); |
| ogore | 5:9b8f87a5a415 | 120 | } |
| ogore | 5:9b8f87a5a415 | 121 | |
| ogore | 4:b6d479319713 | 122 | } |
| ogore | 5:9b8f87a5a415 | 123 | |
| ogore | 3:e35c945dd091 | 124 | int main() |
| ogore | 4:b6d479319713 | 125 | { |
| ogore | 5:9b8f87a5a415 | 126 | set_time(1256729737); |
| ogore | 5:9b8f87a5a415 | 127 | button.fall(&fallISR); |
| ogore | 5:9b8f87a5a415 | 128 | button.rise(&riseISR); |
| ogore | 5:9b8f87a5a415 | 129 | display(welcome_message);//show welcome message |
| ogore | 5:9b8f87a5a415 | 130 | looping(); |
| ogore | 0:2ed38e8fcbc8 | 131 | } |
