Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Sht31 C12832
main.cpp@4:b6d479319713, 2021-01-23 (annotated)
- Committer:
- ogore
- Date:
- Sat Jan 23 19:44:03 2021 +0000
- Revision:
- 4:b6d479319713
- Parent:
- 3:e35c945dd091
- Child:
- 5:9b8f87a5a415
revison on sunday 23rd
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ogore | 3:e35c945dd091 | 1 | |
| ogore | 0:2ed38e8fcbc8 | 2 | #include "mbed.h" // Include the library of Mbed |
| ogore | 0:2ed38e8fcbc8 | 3 | #include "C12832.h" // Include the library of the specific LCD |
| ogore | 3:e35c945dd091 | 4 | #include "Sht31.h" |
| ogore | 4:b6d479319713 | 5 | |
| ogore | 4:b6d479319713 | 6 | |
| ogore | 0:2ed38e8fcbc8 | 7 | DigitalOut blueled(p17, 0); // Initializing the yellow light OFF |
| ogore | 0:2ed38e8fcbc8 | 8 | DigitalOut redled(p15, 0); // Initializing the red light OFF |
| ogore | 0:2ed38e8fcbc8 | 9 | DigitalOut whiteled(p19, 0); // Initializing the red light OFF |
| ogore | 0:2ed38e8fcbc8 | 10 | C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11); // create an instance of LCD |
| ogore | 4:b6d479319713 | 11 | DigitalIn switchmode(p24); |
| ogore | 0:2ed38e8fcbc8 | 12 | InterruptIn button(p20); |
| ogore | 0:2ed38e8fcbc8 | 13 | int i=0; |
| ogore | 3:e35c945dd091 | 14 | int difference=0; |
| ogore | 3:e35c945dd091 | 15 | int endtime; |
| ogore | 3:e35c945dd091 | 16 | int starttime; |
| ogore | 0:2ed38e8fcbc8 | 17 | int k=0; |
| ogore | 4:b6d479319713 | 18 | int maxtopics=5; |
| ogore | 4:b6d479319713 | 19 | int d=1; |
| ogore | 0:2ed38e8fcbc8 | 20 | //initialize topics, summaries and welcome message |
| ogore | 3:e35c945dd091 | 21 | const char *myArray[5][2] = { { "ID", "ASSIGNING OF IDENTIFICATION CARDS TO CITIZENS1" }, { "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 | 0:2ed38e8fcbc8 | 25 | //function for white led blinking every second |
| ogore | 0:2ed38e8fcbc8 | 26 | void blink(){ |
| ogore | 0:2ed38e8fcbc8 | 27 | whiteled=1; |
| ogore | 0:2ed38e8fcbc8 | 28 | wait(1); |
| ogore | 0:2ed38e8fcbc8 | 29 | whiteled=0; |
| ogore | 0:2ed38e8fcbc8 | 30 | wait(1); |
| ogore | 0:2ed38e8fcbc8 | 31 | } |
| ogore | 0:2ed38e8fcbc8 | 32 | //function for displaying message |
| ogore | 3:e35c945dd091 | 33 | static void display(const char *message) { |
| ogore | 0:2ed38e8fcbc8 | 34 | lcd.cls(); // Clear LCD |
| ogore | 0:2ed38e8fcbc8 | 35 | lcd.locate(10, 5); // get cursor to position x=3px and y=5px |
| ogore | 0:2ed38e8fcbc8 | 36 | lcd.printf(message); // Write text into LCD buffer |
| ogore | 0:2ed38e8fcbc8 | 37 | lcd.copy_to_lcd(); |
| ogore | 0:2ed38e8fcbc8 | 38 | } |
| ogore | 3:e35c945dd091 | 39 | void buttonpress() |
| ogore | 0:2ed38e8fcbc8 | 40 | { |
| ogore | 4:b6d479319713 | 41 | difference=0; |
| ogore | 3:e35c945dd091 | 42 | set_time(1256729737); |
| ogore | 3:e35c945dd091 | 43 | time_t seconds = time(NULL); |
| ogore | 3:e35c945dd091 | 44 | starttime = (unsigned int)seconds; |
| ogore | 3:e35c945dd091 | 45 | printf(" %d",starttime); |
| ogore | 3:e35c945dd091 | 46 | while(button==1 && difference<=3) |
| ogore | 3:e35c945dd091 | 47 | { |
| ogore | 3:e35c945dd091 | 48 | wait(1); |
| ogore | 3:e35c945dd091 | 49 | time_t seconds2 = time(NULL); |
| ogore | 3:e35c945dd091 | 50 | endtime = (unsigned int)seconds2; |
| ogore | 3:e35c945dd091 | 51 | printf(" %d",endtime); |
| ogore | 3:e35c945dd091 | 52 | difference=endtime-starttime; |
| ogore | 3:e35c945dd091 | 53 | } |
| ogore | 3:e35c945dd091 | 54 | difference=(difference*difference)/difference; |
| ogore | 4:b6d479319713 | 55 | if(difference>3) |
| ogore | 4:b6d479319713 | 56 | { |
| ogore | 4:b6d479319713 | 57 | d=d*-1; |
| ogore | 4:b6d479319713 | 58 | } |
| ogore | 4:b6d479319713 | 59 | printf("\nthe difference is %d",difference); |
| ogore | 0:2ed38e8fcbc8 | 60 | } |
| ogore | 3:e35c945dd091 | 61 | void buttonrelease() |
| ogore | 3:e35c945dd091 | 62 | { |
| ogore | 4:b6d479319713 | 63 | if(difference<=3) |
| ogore | 4:b6d479319713 | 64 | { |
| ogore | 4:b6d479319713 | 65 | k=0; |
| ogore | 4:b6d479319713 | 66 | i=i+d; |
| ogore | 4:b6d479319713 | 67 | } |
| ogore | 4:b6d479319713 | 68 | if(d<0) |
| ogore | 4:b6d479319713 | 69 | { |
| ogore | 4:b6d479319713 | 70 | redled=1; |
| ogore | 4:b6d479319713 | 71 | blueled=0; |
| ogore | 4:b6d479319713 | 72 | } |
| ogore | 4:b6d479319713 | 73 | else |
| ogore | 4:b6d479319713 | 74 | { |
| ogore | 4:b6d479319713 | 75 | blueled=1; |
| ogore | 3:e35c945dd091 | 76 | redled=0; |
| ogore | 4:b6d479319713 | 77 | } |
| ogore | 4:b6d479319713 | 78 | } |
| ogore | 3:e35c945dd091 | 79 | |
| ogore | 3:e35c945dd091 | 80 | //function to display topic and summary*/ |
| ogore | 3:e35c945dd091 | 81 | void display_message(const char *topic,const char *summary, int i) |
| ogore | 0:2ed38e8fcbc8 | 82 | { |
| ogore | 4:b6d479319713 | 83 | |
| ogore | 0:2ed38e8fcbc8 | 84 | display(topic); |
| ogore | 0:2ed38e8fcbc8 | 85 | wait(1); |
| ogore | 0:2ed38e8fcbc8 | 86 | display(summary); |
| ogore | 0:2ed38e8fcbc8 | 87 | //for loop helps read how long a summary is open using a k value |
| ogore | 4:b6d479319713 | 88 | |
| ogore | 4:b6d479319713 | 89 | } |
| ogore | 4:b6d479319713 | 90 | |
| ogore | 4:b6d479319713 | 91 | //function for mode two |
| ogore | 3:e35c945dd091 | 92 | void Reading() |
| ogore | 3:e35c945dd091 | 93 | { |
| ogore | 4:b6d479319713 | 94 | |
| ogore | 3:e35c945dd091 | 95 | set_time(1); |
| ogore | 3:e35c945dd091 | 96 | button.rise(&buttonpress); |
| ogore | 3:e35c945dd091 | 97 | button.fall(&buttonrelease); |
| ogore | 3:e35c945dd091 | 98 | printf("entered mode two\n"); |
| ogore | 3:e35c945dd091 | 99 | wait(2); |
| ogore | 4:b6d479319713 | 100 | |
| ogore | 4:b6d479319713 | 101 | while(switchmode) |
| ogore | 4:b6d479319713 | 102 | { |
| ogore | 4:b6d479319713 | 103 | k=k+2; |
| ogore | 3:e35c945dd091 | 104 | //call dispay of topic that will display according to value of i |
| ogore | 3:e35c945dd091 | 105 | //value of i is determined by myDuration |
| ogore | 4:b6d479319713 | 106 | |
| ogore | 0:2ed38e8fcbc8 | 107 | if(i==0 || i>4) |
| ogore | 0:2ed38e8fcbc8 | 108 | { |
| ogore | 3:e35c945dd091 | 109 | //in ascending order if i goes above 4 display myArray[0][0] |
| ogore | 0:2ed38e8fcbc8 | 110 | //if i>4 make i =0 |
| ogore | 0:2ed38e8fcbc8 | 111 | i=0; |
| ogore | 0:2ed38e8fcbc8 | 112 | } |
| ogore | 3:e35c945dd091 | 113 | |
| ogore | 0:2ed38e8fcbc8 | 114 | else if(i==4 || i<0 ) |
| ogore | 3:e35c945dd091 | 115 | //in descending order if i goes below zero display myArray[4][0] |
| ogore | 0:2ed38e8fcbc8 | 116 | //if i<0 make i=4 |
| ogore | 0:2ed38e8fcbc8 | 117 | { |
| ogore | 0:2ed38e8fcbc8 | 118 | i=4; |
| ogore | 0:2ed38e8fcbc8 | 119 | } |
| ogore | 3:e35c945dd091 | 120 | display_message(myArray[i][0],myArray[i][1],i); |
| ogore | 3:e35c945dd091 | 121 | if(k>4) |
| ogore | 3:e35c945dd091 | 122 | { |
| ogore | 3:e35c945dd091 | 123 | printf("\n topic ID is=%d and reading duration is %d seconds",i,k); |
| ogore | 3:e35c945dd091 | 124 | } |
| ogore | 3:e35c945dd091 | 125 | wait(1); |
| ogore | 4:b6d479319713 | 126 | } |
| ogore | 4:b6d479319713 | 127 | } |
| ogore | 0:2ed38e8fcbc8 | 128 | |
| ogore | 3:e35c945dd091 | 129 | void looping() |
| ogore | 0:2ed38e8fcbc8 | 130 | { |
| ogore | 4:b6d479319713 | 131 | |
| ogore | 0:2ed38e8fcbc8 | 132 | blink();//white led blinks every second |
| ogore | 0:2ed38e8fcbc8 | 133 | time_t seconds = time(NULL); |
| ogore | 3:e35c945dd091 | 134 | |
| ogore | 4:b6d479319713 | 135 | //float temp = sht31.readTemperature(); //read temperature |
| ogore | 0:2ed38e8fcbc8 | 136 | lcd.locate(5, 5); // get cursor to position x=5px and y=5px |
| ogore | 3:e35c945dd091 | 137 | // lcd.printf("Current Temperature: %.2fC",temp);//display temp |
| ogore | 0:2ed38e8fcbc8 | 138 | lcd.locate(5, 5); // get cursor to position x=5px and y=5px |
| ogore | 0:2ed38e8fcbc8 | 139 | lcd.printf("Current Time in seconds is: %u",(unsigned int)seconds); //display time |
| ogore | 0:2ed38e8fcbc8 | 140 | wait(3); |
| ogore | 4:b6d479319713 | 141 | while(i<maxtopics) |
| ogore | 4:b6d479319713 | 142 | { |
| ogore | 4:b6d479319713 | 143 | while(!switchmode) |
| ogore | 3:e35c945dd091 | 144 | { |
| ogore | 4:b6d479319713 | 145 | if(i==0 || i>4) |
| ogore | 4:b6d479319713 | 146 | { |
| ogore | 4:b6d479319713 | 147 | //in ascending order if i goes above 4 display myArray[0][0] |
| ogore | 4:b6d479319713 | 148 | //if i>4 make i =0 |
| ogore | 4:b6d479319713 | 149 | i=0; |
| ogore | 4:b6d479319713 | 150 | } |
| ogore | 3:e35c945dd091 | 151 | //with the value of i, when you enter mode two you see summary of the topic displayed when you entered mode two |
| ogore | 3:e35c945dd091 | 152 | display(myArray[i][0]); |
| ogore | 3:e35c945dd091 | 153 | i++; |
| ogore | 4:b6d479319713 | 154 | wait(2); |
| ogore | 4:b6d479319713 | 155 | } |
| ogore | 4:b6d479319713 | 156 | Reading(); |
| ogore | 4:b6d479319713 | 157 | wait(1); |
| ogore | 4:b6d479319713 | 158 | } |
| ogore | 0:2ed38e8fcbc8 | 159 | } |
| ogore | 3:e35c945dd091 | 160 | int main() |
| ogore | 4:b6d479319713 | 161 | { |
| ogore | 3:e35c945dd091 | 162 | display(welcome_message);//show welcome message |
| ogore | 4:b6d479319713 | 163 | |
| ogore | 4:b6d479319713 | 164 | looping(); |
| ogore | 0:2ed38e8fcbc8 | 165 | } |
| ogore | 0:2ed38e8fcbc8 | 166 |
