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: SDFileSystem mbed
Fork of PES4_Programme by
source/main.cpp@59:1867088695f3, 2018-04-05 (annotated)
- Committer:
- aeschsim
- Date:
- Thu Apr 05 13:45:45 2018 +0000
- Revision:
- 59:1867088695f3
- Parent:
- 58:cda5298c9b7f
- Child:
- 60:7554e4272b3b
implemented demo RGB LED FADING TOOL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cittecla | 3:94026b29e994 | 1 | #include "main.h" |
aeschsim | 59:1867088695f3 | 2 | #define FADESPEED 5 |
aeschsim | 59:1867088695f3 | 3 | #define DEMOTIME 5 |
itslinear | 17:bbafd216e059 | 4 | |
cittecla | 52:701d0c2f47d7 | 5 | int state = 44; |
cittecla | 41:f054a83f9556 | 6 | int oldState; |
cittecla | 2:72886e996098 | 7 | |
cittecla | 2:72886e996098 | 8 | Serial pc(USBTX, USBRX); // tx, rx |
aeschsim | 40:b5e533e1e033 | 9 | |
aeschsim | 59:1867088695f3 | 10 | DigitalIn lichtschranke(PC_5); |
aeschsim | 59:1867088695f3 | 11 | |
aeschsim | 40:b5e533e1e033 | 12 | /* PWM Test Tool */ |
aeschsim | 40:b5e533e1e033 | 13 | int channel; |
aeschsim | 40:b5e533e1e033 | 14 | int dutyCycle; |
cittecla | 55:bdab541f434d | 15 | int day; |
cittecla | 55:bdab541f434d | 16 | int moment; |
cittecla | 55:bdab541f434d | 17 | s_user user[2]; |
cittecla | 2:72886e996098 | 18 | |
aeschsim | 59:1867088695f3 | 19 | /* Demo Tool */ |
aeschsim | 59:1867088695f3 | 20 | uint32_t color = 0; |
aeschsim | 59:1867088695f3 | 21 | int colorTime = 0; |
aeschsim | 59:1867088695f3 | 22 | int r,b,g; |
aeschsim | 59:1867088695f3 | 23 | |
cittecla | 2:72886e996098 | 24 | int main() |
cittecla | 2:72886e996098 | 25 | { |
cittecla | 2:72886e996098 | 26 | pc.baud(460800); |
cittecla | 2:72886e996098 | 27 | printf("start...\r\n"); |
cittecla | 2:72886e996098 | 28 | |
aeschsim | 34:9d6dd3a12641 | 29 | while(1) { |
cittecla | 41:f054a83f9556 | 30 | if(state != oldState) { |
cittecla | 58:cda5298c9b7f | 31 | printf("\r\nstate: %d\r\n",state); |
cittecla | 41:f054a83f9556 | 32 | oldState = state; |
aeschsim | 34:9d6dd3a12641 | 33 | } |
aeschsim | 34:9d6dd3a12641 | 34 | switch (state) { |
aeschsim | 34:9d6dd3a12641 | 35 | case 0: |
aeschsim | 34:9d6dd3a12641 | 36 | printf("Hello World"); |
aeschsim | 40:b5e533e1e033 | 37 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 38 | break; |
aeschsim | 34:9d6dd3a12641 | 39 | case 1: |
aeschsim | 34:9d6dd3a12641 | 40 | break; |
aeschsim | 34:9d6dd3a12641 | 41 | case 2: |
aeschsim | 34:9d6dd3a12641 | 42 | break; |
aeschsim | 34:9d6dd3a12641 | 43 | case 3: |
aeschsim | 34:9d6dd3a12641 | 44 | break; |
cittecla | 2:72886e996098 | 45 | |
aeschsim | 34:9d6dd3a12641 | 46 | case 10: |
aeschsim | 34:9d6dd3a12641 | 47 | break; |
aeschsim | 34:9d6dd3a12641 | 48 | case 11: |
aeschsim | 34:9d6dd3a12641 | 49 | break; |
cittecla | 2:72886e996098 | 50 | |
aeschsim | 34:9d6dd3a12641 | 51 | case 15: |
aeschsim | 34:9d6dd3a12641 | 52 | break; |
aeschsim | 34:9d6dd3a12641 | 53 | case 16: |
aeschsim | 34:9d6dd3a12641 | 54 | break; |
aeschsim | 34:9d6dd3a12641 | 55 | case 17: |
aeschsim | 34:9d6dd3a12641 | 56 | break; |
aeschsim | 34:9d6dd3a12641 | 57 | |
aeschsim | 34:9d6dd3a12641 | 58 | case 25: |
aeschsim | 34:9d6dd3a12641 | 59 | break; |
aeschsim | 34:9d6dd3a12641 | 60 | case 26: |
aeschsim | 34:9d6dd3a12641 | 61 | break; |
aeschsim | 34:9d6dd3a12641 | 62 | case 27: |
aeschsim | 34:9d6dd3a12641 | 63 | break; |
aeschsim | 34:9d6dd3a12641 | 64 | case 28: |
aeschsim | 34:9d6dd3a12641 | 65 | break; |
cittecla | 2:72886e996098 | 66 | |
cittecla | 2:72886e996098 | 67 | |
aeschsim | 34:9d6dd3a12641 | 68 | case 35: |
aeschsim | 34:9d6dd3a12641 | 69 | break; |
aeschsim | 34:9d6dd3a12641 | 70 | case 36: |
aeschsim | 34:9d6dd3a12641 | 71 | break; |
aeschsim | 34:9d6dd3a12641 | 72 | case 37: |
aeschsim | 34:9d6dd3a12641 | 73 | break; |
aeschsim | 34:9d6dd3a12641 | 74 | case 38: |
aeschsim | 34:9d6dd3a12641 | 75 | break; |
aeschsim | 27:bf0577ecfa6e | 76 | |
aeschsim | 40:b5e533e1e033 | 77 | /**************************************************************/ |
aeschsim | 40:b5e533e1e033 | 78 | /* Test Zone */ |
cittecla | 53:1c61cadbcb35 | 79 | |
cittecla | 52:701d0c2f47d7 | 80 | /* init PWM board */ |
cittecla | 52:701d0c2f47d7 | 81 | case 44: |
cittecla | 55:bdab541f434d | 82 | printf("Init PWM\r\n"); |
cittecla | 53:1c61cadbcb35 | 83 | initPWM(50); |
cittecla | 53:1c61cadbcb35 | 84 | enableOutput(); |
cittecla | 52:701d0c2f47d7 | 85 | state = 47; |
cittecla | 52:701d0c2f47d7 | 86 | break; |
aeschsim | 40:b5e533e1e033 | 87 | |
aeschsim | 40:b5e533e1e033 | 88 | /* Time test tool: set Time */ |
aeschsim | 34:9d6dd3a12641 | 89 | case 45: |
aeschsim | 34:9d6dd3a12641 | 90 | s_time time; |
aeschsim | 34:9d6dd3a12641 | 91 | time.second = 30; |
aeschsim | 34:9d6dd3a12641 | 92 | time.minute = 53; |
aeschsim | 34:9d6dd3a12641 | 93 | time.hour = 12; |
aeschsim | 34:9d6dd3a12641 | 94 | time.day = 27; |
aeschsim | 34:9d6dd3a12641 | 95 | time.weekday = 2; |
aeschsim | 34:9d6dd3a12641 | 96 | time.month = 3; |
aeschsim | 34:9d6dd3a12641 | 97 | time.year = 18; |
cittecla | 55:bdab541f434d | 98 | printf("set now time\r\n"); |
aeschsim | 34:9d6dd3a12641 | 99 | setTime(&time); |
cittecla | 55:bdab541f434d | 100 | printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday); |
aeschsim | 40:b5e533e1e033 | 101 | state = 47; |
cittecla | 55:bdab541f434d | 102 | printf("change state to: %d\r\n",state); |
aeschsim | 34:9d6dd3a12641 | 103 | break; |
aeschsim | 40:b5e533e1e033 | 104 | |
aeschsim | 40:b5e533e1e033 | 105 | /* Time test tool: get Time */ |
aeschsim | 34:9d6dd3a12641 | 106 | case 46: |
aeschsim | 34:9d6dd3a12641 | 107 | wait(5); |
aeschsim | 34:9d6dd3a12641 | 108 | time = getTime(); |
cittecla | 55:bdab541f434d | 109 | printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday); |
aeschsim | 40:b5e533e1e033 | 110 | state = 47; |
aeschsim | 40:b5e533e1e033 | 111 | break; |
aeschsim | 40:b5e533e1e033 | 112 | |
aeschsim | 40:b5e533e1e033 | 113 | /* Console State Switch */ |
aeschsim | 40:b5e533e1e033 | 114 | case 47: |
cittecla | 55:bdab541f434d | 115 | printf("\n\rState Switch: Enter next State: \n\r"); |
cittecla | 55:bdab541f434d | 116 | printf("45\tset Time\n\r46\tread Time\n\r47\tState Switch\n\r48\tServo Board Test Tool\n\r49\tenable servo output\n\r50\tdisable servo output\n\r51\ttest SD Card\n\r52\tread medication\n\r53\tMedication display test tool\n\r"); |
aeschsim | 40:b5e533e1e033 | 117 | pc.scanf("%d", &state); |
cittecla | 55:bdab541f434d | 118 | printf("Switch to State %d\n\r",state); |
aeschsim | 40:b5e533e1e033 | 119 | fflush(stdin); |
aeschsim | 34:9d6dd3a12641 | 120 | break; |
aeschsim | 40:b5e533e1e033 | 121 | |
aeschsim | 40:b5e533e1e033 | 122 | /* Servo-Board Test Tool */ |
aeschsim | 34:9d6dd3a12641 | 123 | case 48: |
cittecla | 55:bdab541f434d | 124 | printf("\n\r\n\rServo-Board Test Tool\n\rEnter Channel Number and then Duty Cycle\n\r"); |
cittecla | 55:bdab541f434d | 125 | printf("for exit, enter Channel > 15\n\r"); |
aeschsim | 40:b5e533e1e033 | 126 | channel = 0; |
aeschsim | 40:b5e533e1e033 | 127 | while (channel < 16) { |
cittecla | 55:bdab541f434d | 128 | printf("Channel Number: "); |
aeschsim | 40:b5e533e1e033 | 129 | pc.scanf("%d", &channel); |
cittecla | 55:bdab541f434d | 130 | printf("\r\nchannel: %d\n\rDuty Cycle 0..4095: ",channel); |
aeschsim | 40:b5e533e1e033 | 131 | pc.scanf("%d", &dutyCycle); |
cittecla | 55:bdab541f434d | 132 | printf("\n\r%d\n\r",dutyCycle); |
aeschsim | 46:cdc24a24e4e3 | 133 | setPWM((char)channel, (int)dutyCycle); |
aeschsim | 40:b5e533e1e033 | 134 | fflush(stdin); |
aeschsim | 40:b5e533e1e033 | 135 | } |
cittecla | 55:bdab541f434d | 136 | printf("leave Servo-Board Test Tool\n\r"); |
aeschsim | 40:b5e533e1e033 | 137 | state = 47; |
aeschsim | 40:b5e533e1e033 | 138 | break; |
aeschsim | 40:b5e533e1e033 | 139 | |
aeschsim | 40:b5e533e1e033 | 140 | case 49: |
cittecla | 42:ba59ed6a2a06 | 141 | enableOutput(); |
cittecla | 55:bdab541f434d | 142 | printf("Servo output enabled\r\n\n"); |
aeschsim | 40:b5e533e1e033 | 143 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 144 | break; |
cittecla | 2:72886e996098 | 145 | |
aeschsim | 34:9d6dd3a12641 | 146 | case 50: |
cittecla | 42:ba59ed6a2a06 | 147 | disableOutput(); |
cittecla | 55:bdab541f434d | 148 | printf("Servo output disabled\r\n\n"); |
aeschsim | 40:b5e533e1e033 | 149 | state = 47; |
aeschsim | 40:b5e533e1e033 | 150 | break; |
cittecla | 53:1c61cadbcb35 | 151 | |
cittecla | 42:ba59ed6a2a06 | 152 | case 51: |
cittecla | 52:701d0c2f47d7 | 153 | testSd(); |
cittecla | 55:bdab541f434d | 154 | printf("\rSD Card test finished\r\n\n"); |
cittecla | 55:bdab541f434d | 155 | state = 47; |
cittecla | 55:bdab541f434d | 156 | break; |
cittecla | 58:cda5298c9b7f | 157 | |
cittecla | 58:cda5298c9b7f | 158 | |
cittecla | 55:bdab541f434d | 159 | case 52: |
cittecla | 56:218601547d13 | 160 | user[1] = readMedication(1); |
cittecla | 56:218601547d13 | 161 | if(user[1].valid) { |
cittecla | 56:218601547d13 | 162 | printf("\rread successful\r\n\n"); |
cittecla | 55:bdab541f434d | 163 | } else { |
cittecla | 55:bdab541f434d | 164 | printf("\rread failed\r\n\n"); |
cittecla | 55:bdab541f434d | 165 | } |
cittecla | 42:ba59ed6a2a06 | 166 | state = 47; |
cittecla | 53:1c61cadbcb35 | 167 | break; |
cittecla | 55:bdab541f434d | 168 | |
cittecla | 55:bdab541f434d | 169 | case 53: |
cittecla | 56:218601547d13 | 170 | if(user[1].valid == false) { |
cittecla | 57:79fed71031da | 171 | printf("\r\nNo valid data in struct, try to run case 52\r\n\n"); |
cittecla | 55:bdab541f434d | 172 | } else { |
cittecla | 55:bdab541f434d | 173 | printf("\r\nMedication display test tool:\r\n"); |
cittecla | 55:bdab541f434d | 174 | printf("Enter Day (0..6) and Moment (0..4)\r\nTo exit enter Day > 6:\r\n"); |
cittecla | 55:bdab541f434d | 175 | day = 0; |
cittecla | 55:bdab541f434d | 176 | while (day < 7) { |
cittecla | 55:bdab541f434d | 177 | printf("\r\nDay Number: "); |
cittecla | 55:bdab541f434d | 178 | pc.scanf("%d", &day); |
cittecla | 55:bdab541f434d | 179 | if(day < 7) { |
cittecla | 55:bdab541f434d | 180 | printf("\r\nDay: %d\n\rMoment 0..3: ",day); |
cittecla | 55:bdab541f434d | 181 | pc.scanf("%d", &moment); |
cittecla | 55:bdab541f434d | 182 | printf("\r\nMedication for weekday %d Moment %d is ",day,moment); |
cittecla | 55:bdab541f434d | 183 | for(int i=0; i<6; i++) { |
cittecla | 56:218601547d13 | 184 | printf("%d", user[1].medication.day[day].moment[moment].medContainer.container[i]); |
cittecla | 55:bdab541f434d | 185 | } |
cittecla | 58:cda5298c9b7f | 186 | printf("\r\nThe alarm clock is set for %02d:%02d",user[1].medication.day[day].moment[moment].time.hour,user[1].medication.day[day].moment[moment].time.minute); |
cittecla | 55:bdab541f434d | 187 | } |
cittecla | 55:bdab541f434d | 188 | printf("\r\n"); |
cittecla | 55:bdab541f434d | 189 | fflush(stdin); |
cittecla | 55:bdab541f434d | 190 | } |
cittecla | 55:bdab541f434d | 191 | printf("exit Tool\n\r"); |
cittecla | 55:bdab541f434d | 192 | } |
cittecla | 56:218601547d13 | 193 | state = 47; |
cittecla | 56:218601547d13 | 194 | break; |
cittecla | 58:cda5298c9b7f | 195 | case 54: |
cittecla | 58:cda5298c9b7f | 196 | writeMedication(0,user[1]); |
cittecla | 58:cda5298c9b7f | 197 | state = 47; |
cittecla | 58:cda5298c9b7f | 198 | break; |
aeschsim | 59:1867088695f3 | 199 | case 55: |
aeschsim | 59:1867088695f3 | 200 | /* Demo Tool */ |
aeschsim | 59:1867088695f3 | 201 | color = 0x0055AA; |
aeschsim | 59:1867088695f3 | 202 | while(colorTime < DEMOTIME) { |
aeschsim | 59:1867088695f3 | 203 | for(r = 0; r <= 255;r++){ |
aeschsim | 59:1867088695f3 | 204 | color &= 0x00FFFF; |
aeschsim | 59:1867088695f3 | 205 | color &= (r<<4); |
aeschsim | 59:1867088695f3 | 206 | wait_ms(FADESPEED); |
aeschsim | 59:1867088695f3 | 207 | } |
aeschsim | 59:1867088695f3 | 208 | for(b = 255; b >= 0; b--){ |
aeschsim | 59:1867088695f3 | 209 | color &= 0xFFFF00; |
aeschsim | 59:1867088695f3 | 210 | color &= b; |
aeschsim | 59:1867088695f3 | 211 | wait_ms(FADESPEED); |
aeschsim | 59:1867088695f3 | 212 | } |
aeschsim | 59:1867088695f3 | 213 | for(g = 0; g <= 255; g++){ |
aeschsim | 59:1867088695f3 | 214 | color &= 0xFF00FF; |
aeschsim | 59:1867088695f3 | 215 | color &= (g<<2); |
aeschsim | 59:1867088695f3 | 216 | wait_ms(FADESPEED); |
aeschsim | 59:1867088695f3 | 217 | } |
aeschsim | 59:1867088695f3 | 218 | for(r = 255; r > 0; r--) { |
aeschsim | 59:1867088695f3 | 219 | color &= 0x00FFFF; |
aeschsim | 59:1867088695f3 | 220 | color &= (r<<4); |
aeschsim | 59:1867088695f3 | 221 | wait_ms(FADESPEED); |
aeschsim | 59:1867088695f3 | 222 | } |
aeschsim | 59:1867088695f3 | 223 | for(b = 0; b <= 255; b++) { |
aeschsim | 59:1867088695f3 | 224 | color &= 0xFFFF00; |
aeschsim | 59:1867088695f3 | 225 | color &= b; |
aeschsim | 59:1867088695f3 | 226 | wait_ms(FADESPEED); |
aeschsim | 59:1867088695f3 | 227 | } |
aeschsim | 59:1867088695f3 | 228 | for (g = 255; g > 0; g--) { |
aeschsim | 59:1867088695f3 | 229 | color &= 0xFF00FF; |
aeschsim | 59:1867088695f3 | 230 | color &= (g<<2); |
aeschsim | 59:1867088695f3 | 231 | wait_ms(FADESPEED); |
aeschsim | 59:1867088695f3 | 232 | } |
aeschsim | 59:1867088695f3 | 233 | colorTime++; |
aeschsim | 59:1867088695f3 | 234 | } |
aeschsim | 59:1867088695f3 | 235 | |
aeschsim | 59:1867088695f3 | 236 | break; |
aeschsim | 40:b5e533e1e033 | 237 | default: |
aeschsim | 40:b5e533e1e033 | 238 | state = 47; /* Go to State Switch */ |
aeschsim | 34:9d6dd3a12641 | 239 | break; |
aeschsim | 34:9d6dd3a12641 | 240 | } |
cittecla | 2:72886e996098 | 241 | } |
cittecla | 55:bdab541f434d | 242 | printf("exit while 1 loop"); |
cittecla | 2:72886e996098 | 243 | } |