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.
main.cpp@5:5195884584d6, 2017-12-10 (annotated)
- Committer:
- gjgsd
- Date:
- Sun Dec 10 16:11:32 2017 +0000
- Revision:
- 5:5195884584d6
- Parent:
- 4:d4aeacb47955
minor fixes
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bcostm | 0:5701b41769fd | 1 | #include "mbed.h" |
| bcostm | 0:5701b41769fd | 2 | |
| gjgsd | 4:d4aeacb47955 | 3 | |
| gjgsd | 4:d4aeacb47955 | 4 | void print_help() //help message |
| gjgsd | 5:5195884584d6 | 5 | { |
| gjgsd | 4:d4aeacb47955 | 6 | printf("***********************************************************\r\n"); |
| gjgsd | 4:d4aeacb47955 | 7 | printf("* LEDON:x - set time for LED to be ON *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 8 | printf("* - x - time in seconds (range 1-1000) *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 9 | printf("* LEDOFF - turn LED off *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 10 | printf("* LEDSTATE - print current LED state *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 11 | printf("* BRIGHTSET:x - set LED brightnes *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 12 | printf("* x - range 0-7 (0 - low, 7 - high) *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 13 | printf("* BRIGHTGET - get LED brightnes *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 14 | printf("* BUTTONGET - get user button monitorring state *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 15 | printf("* BUTTONSTATE - get user button state *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 16 | printf("* BUTTONENABLE - enable button monitorring *\r\n"); |
| gjgsd | 5:5195884584d6 | 17 | printf("* BUTTONDISABLE - disable button monitorring *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 18 | printf("* HELP - print available list of commands *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 19 | printf("***********************************************************\r\n"); |
| bcostm | 0:5701b41769fd | 20 | } |
| bcostm | 0:5701b41769fd | 21 | |
| gjgsd | 4:d4aeacb47955 | 22 | void print_welcome() //welcome message |
| gjgsd | 4:d4aeacb47955 | 23 | { |
| gjgsd | 4:d4aeacb47955 | 24 | printf("\r\n"); |
| gjgsd | 4:d4aeacb47955 | 25 | printf("***********************************************************\r\n"); |
| gjgsd | 4:d4aeacb47955 | 26 | printf("* *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 27 | printf("* WELCOME! *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 28 | printf("* *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 29 | printf("* To turn LED on for X seconds type: *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 30 | printf("* LEDON:x where [x] is specified period of seconds *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 31 | printf("* x range 1-1000 *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 32 | printf("* *\r\n"); |
| gjgsd | 4:d4aeacb47955 | 33 | printf("***********************************************************\r\n"); |
| gjgsd | 4:d4aeacb47955 | 34 | } |
| gjgsd | 4:d4aeacb47955 | 35 | |
| gjgsd | 4:d4aeacb47955 | 36 | void print_fc_off() //fault code message when LED is off |
| gjgsd | 4:d4aeacb47955 | 37 | { |
| gjgsd | 5:5195884584d6 | 38 | printf("WRONG INPUT\r\n"); |
| gjgsd | 4:d4aeacb47955 | 39 | printf(" To turn LED on type: \r\n"); |
| gjgsd | 4:d4aeacb47955 | 40 | printf(" LEDON:x where [x] is specified period of seconds \r\n"); |
| gjgsd | 4:d4aeacb47955 | 41 | printf(" x range 1-1000 \r\n"); |
| gjgsd | 4:d4aeacb47955 | 42 | } |
| gjgsd | 4:d4aeacb47955 | 43 | |
| gjgsd | 4:d4aeacb47955 | 44 | void print_fc_on() //fault code message when LED is on |
| gjgsd | 4:d4aeacb47955 | 45 | { |
| gjgsd | 5:5195884584d6 | 46 | printf("WRONG INPUT\r\n"); |
| gjgsd | 4:d4aeacb47955 | 47 | printf(" To see available list of commands type HELP\r\n"); |
| gjgsd | 4:d4aeacb47955 | 48 | } |
| gjgsd | 4:d4aeacb47955 | 49 | |
| gjgsd | 4:d4aeacb47955 | 50 | //const |
| gjgsd | 4:d4aeacb47955 | 51 | int const LED_ON = 1; |
| gjgsd | 4:d4aeacb47955 | 52 | int const BRIGHT = 2; |
| gjgsd | 4:d4aeacb47955 | 53 | int const ON = 1; |
| gjgsd | 4:d4aeacb47955 | 54 | int const OFF = 0; |
| gjgsd | 4:d4aeacb47955 | 55 | int const B_ON = 0; |
| gjgsd | 4:d4aeacb47955 | 56 | int const B_OFF = 1; |
| gjgsd | 4:d4aeacb47955 | 57 | |
| gjgsd | 4:d4aeacb47955 | 58 | //threads |
| gjgsd | 4:d4aeacb47955 | 59 | Thread lamp_thread; |
| gjgsd | 4:d4aeacb47955 | 60 | Thread timer_thread; |
| gjgsd | 4:d4aeacb47955 | 61 | |
| gjgsd | 4:d4aeacb47955 | 62 | //variables |
| gjgsd | 3:dd96529b7ae9 | 63 | int print = 1; |
| gjgsd | 3:dd96529b7ae9 | 64 | char input [64]; |
| gjgsd | 4:d4aeacb47955 | 65 | int lamp_bright = 4; |
| gjgsd | 4:d4aeacb47955 | 66 | bool lamp_state = false; |
| gjgsd | 4:d4aeacb47955 | 67 | int lamp_time; |
| gjgsd | 4:d4aeacb47955 | 68 | int state = OFF; |
| gjgsd | 4:d4aeacb47955 | 69 | int b_state = OFF; |
| gjgsd | 4:d4aeacb47955 | 70 | int b_push = B_OFF; |
| bcostm | 2:35f13b7f3659 | 71 | |
| gjgsd | 4:d4aeacb47955 | 72 | //interfaces |
| gjgsd | 4:d4aeacb47955 | 73 | DigitalIn button(PC_13); |
| gjgsd | 4:d4aeacb47955 | 74 | DigitalOut led2(LED1); |
| gjgsd | 3:dd96529b7ae9 | 75 | PwmOut led1(D11); |
| bcostm | 0:5701b41769fd | 76 | |
| gjgsd | 4:d4aeacb47955 | 77 | //pow |
| gjgsd | 4:d4aeacb47955 | 78 | int power(int x, int n) { |
| gjgsd | 4:d4aeacb47955 | 79 | if(n == 0) return 1; |
| gjgsd | 4:d4aeacb47955 | 80 | return x * power(x, n - 1); |
| gjgsd | 4:d4aeacb47955 | 81 | } |
| gjgsd | 4:d4aeacb47955 | 82 | |
| gjgsd | 4:d4aeacb47955 | 83 | // parse string and calculate input integer data |
| gjgsd | 4:d4aeacb47955 | 84 | int strtoint(char instring[64], int slogan) |
| bcostm | 0:5701b41769fd | 85 | { |
| gjgsd | 4:d4aeacb47955 | 86 | int str_len = strlen(instring); |
| gjgsd | 4:d4aeacb47955 | 87 | int result = 0; |
| gjgsd | 4:d4aeacb47955 | 88 | switch (slogan){ |
| gjgsd | 4:d4aeacb47955 | 89 | case LED_ON: // "LEDON:" |
| gjgsd | 4:d4aeacb47955 | 90 | if (str_len > 10) return -2; // too long time |
| gjgsd | 4:d4aeacb47955 | 91 | for(int i = 6; i < str_len; i++) |
| gjgsd | 4:d4aeacb47955 | 92 | { |
| gjgsd | 4:d4aeacb47955 | 93 | if(instring[i] > 47 && instring[i] < 58) // if input is digit |
| gjgsd | 4:d4aeacb47955 | 94 | { |
| gjgsd | 4:d4aeacb47955 | 95 | result = (result * 10) + instring[i] - 48; |
| gjgsd | 3:dd96529b7ae9 | 96 | } |
| gjgsd | 4:d4aeacb47955 | 97 | else // not a digit |
| gjgsd | 4:d4aeacb47955 | 98 | { |
| gjgsd | 4:d4aeacb47955 | 99 | result = -1; |
| gjgsd | 4:d4aeacb47955 | 100 | break; |
| gjgsd | 4:d4aeacb47955 | 101 | } |
| gjgsd | 4:d4aeacb47955 | 102 | } |
| gjgsd | 4:d4aeacb47955 | 103 | if (result > 1000) result = -2; |
| gjgsd | 4:d4aeacb47955 | 104 | break; |
| gjgsd | 4:d4aeacb47955 | 105 | |
| gjgsd | 4:d4aeacb47955 | 106 | case BRIGHT: //BRIGHTSET: |
| gjgsd | 4:d4aeacb47955 | 107 | if (str_len > 11) return -2; // too long time |
| gjgsd | 4:d4aeacb47955 | 108 | if(instring[10] > 55) return -2; // too long time |
| gjgsd | 4:d4aeacb47955 | 109 | if(instring[10] > 47 && instring[10] < 58) // if input is digit |
| gjgsd | 4:d4aeacb47955 | 110 | result = instring[10] - 48; |
| gjgsd | 4:d4aeacb47955 | 111 | else // not a digit |
| gjgsd | 4:d4aeacb47955 | 112 | result = -1; |
| gjgsd | 4:d4aeacb47955 | 113 | break; |
| gjgsd | 4:d4aeacb47955 | 114 | default: |
| gjgsd | 4:d4aeacb47955 | 115 | break; |
| gjgsd | 4:d4aeacb47955 | 116 | } |
| gjgsd | 4:d4aeacb47955 | 117 | return result; |
| gjgsd | 4:d4aeacb47955 | 118 | } |
| gjgsd | 4:d4aeacb47955 | 119 | |
| gjgsd | 4:d4aeacb47955 | 120 | //translate to CAPS |
| gjgsd | 4:d4aeacb47955 | 121 | void caps() |
| gjgsd | 4:d4aeacb47955 | 122 | { |
| gjgsd | 4:d4aeacb47955 | 123 | for(int i = 0; i < 63; i++) |
| gjgsd | 4:d4aeacb47955 | 124 | { |
| gjgsd | 4:d4aeacb47955 | 125 | if(input[i] > 96 && input[i] < 123) |
| gjgsd | 4:d4aeacb47955 | 126 | input[i] = input[i] - 32; |
| gjgsd | 4:d4aeacb47955 | 127 | } |
| gjgsd | 4:d4aeacb47955 | 128 | printf("\r\n<%s\r\n",input); |
| gjgsd | 4:d4aeacb47955 | 129 | } |
| gjgsd | 4:d4aeacb47955 | 130 | |
| gjgsd | 4:d4aeacb47955 | 131 | //thread lamp, while led is off |
| gjgsd | 4:d4aeacb47955 | 132 | void led_off() |
| gjgsd | 4:d4aeacb47955 | 133 | { |
| gjgsd | 4:d4aeacb47955 | 134 | if (!strncmp (input,"LEDON:",6)) |
| gjgsd | 4:d4aeacb47955 | 135 | { |
| gjgsd | 4:d4aeacb47955 | 136 | lamp_time = strtoint(input, LED_ON); |
| gjgsd | 4:d4aeacb47955 | 137 | switch (lamp_time){ |
| gjgsd | 4:d4aeacb47955 | 138 | case 0: |
| gjgsd | 4:d4aeacb47955 | 139 | case -2: // wrong time time |
| gjgsd | 4:d4aeacb47955 | 140 | printf("WRONG TIME IS SPECIFIED. RANGE IS 1-1000\r\n"); |
| gjgsd | 4:d4aeacb47955 | 141 | break; |
| gjgsd | 4:d4aeacb47955 | 142 | case -1: |
| gjgsd | 4:d4aeacb47955 | 143 | printf("PLEASE USE DIGITS FOR TIME SPECIFICATION.\r\n"); |
| gjgsd | 4:d4aeacb47955 | 144 | break; |
| gjgsd | 4:d4aeacb47955 | 145 | default: |
| gjgsd | 4:d4aeacb47955 | 146 | printf("LED IS ON FOR %d SECONDS\r\n",lamp_time); |
| gjgsd | 4:d4aeacb47955 | 147 | led1 = power(2,lamp_bright) * 0.01; |
| gjgsd | 4:d4aeacb47955 | 148 | state = ON; |
| gjgsd | 4:d4aeacb47955 | 149 | } |
| gjgsd | 4:d4aeacb47955 | 150 | } |
| gjgsd | 4:d4aeacb47955 | 151 | else |
| gjgsd | 4:d4aeacb47955 | 152 | { |
| gjgsd | 4:d4aeacb47955 | 153 | print_fc_off(); |
| gjgsd | 3:dd96529b7ae9 | 154 | } |
| gjgsd | 4:d4aeacb47955 | 155 | } |
| gjgsd | 4:d4aeacb47955 | 156 | |
| gjgsd | 4:d4aeacb47955 | 157 | //thread lamp, while led is on |
| gjgsd | 4:d4aeacb47955 | 158 | void led_on() |
| gjgsd | 4:d4aeacb47955 | 159 | { |
| gjgsd | 4:d4aeacb47955 | 160 | if (!strcmp (input,"LEDOFF")) //turn led off |
| gjgsd | 4:d4aeacb47955 | 161 | { |
| gjgsd | 4:d4aeacb47955 | 162 | lamp_time = 1; |
| gjgsd | 4:d4aeacb47955 | 163 | } |
| gjgsd | 4:d4aeacb47955 | 164 | else if(!strcmp (input,"LEDSTATE")) //print LED state |
| gjgsd | 4:d4aeacb47955 | 165 | { |
| gjgsd | 4:d4aeacb47955 | 166 | printf("LED IS ON FOR %d SECONDS\r\n",lamp_time); |
| gjgsd | 4:d4aeacb47955 | 167 | } |
| gjgsd | 4:d4aeacb47955 | 168 | else if(!strncmp(input,"BRIGHTSET:",10)) //BRIGHTSET:x |
| gjgsd | 4:d4aeacb47955 | 169 | { |
| gjgsd | 4:d4aeacb47955 | 170 | int bright = strtoint(input, BRIGHT); |
| gjgsd | 4:d4aeacb47955 | 171 | switch (bright){ |
| gjgsd | 4:d4aeacb47955 | 172 | case -2: // wrong brightness |
| gjgsd | 4:d4aeacb47955 | 173 | printf("WRONG BRIGHTNESS IS SPECIFIED. RANGE IS 0-7\r\n"); |
| gjgsd | 4:d4aeacb47955 | 174 | break; |
| gjgsd | 4:d4aeacb47955 | 175 | case -1: |
| gjgsd | 4:d4aeacb47955 | 176 | printf("PLEASE USE DIGITS FOR BRIGHTNESS SPECIFICATION.\r\n"); |
| gjgsd | 4:d4aeacb47955 | 177 | break; |
| gjgsd | 4:d4aeacb47955 | 178 | default: |
| gjgsd | 4:d4aeacb47955 | 179 | lamp_bright = bright; |
| gjgsd | 4:d4aeacb47955 | 180 | led1 = power(2,lamp_bright) * 0.01; |
| gjgsd | 4:d4aeacb47955 | 181 | printf("BRIGHTNESS IS SET TO %d\r\n",lamp_bright); |
| gjgsd | 4:d4aeacb47955 | 182 | } |
| gjgsd | 4:d4aeacb47955 | 183 | } |
| gjgsd | 4:d4aeacb47955 | 184 | else if(!strcmp (input,"BRIGHTGET")) //print brightness level |
| gjgsd | 4:d4aeacb47955 | 185 | { |
| gjgsd | 4:d4aeacb47955 | 186 | printf("BRIGHTNESS IS SET TO %d\r\n",lamp_bright); |
| gjgsd | 4:d4aeacb47955 | 187 | } |
| gjgsd | 4:d4aeacb47955 | 188 | else if(!strcmp (input,"BUTTONGET")) //print user button state |
| gjgsd | 4:d4aeacb47955 | 189 | { |
| gjgsd | 4:d4aeacb47955 | 190 | printf("BUTTON MONITORRING IS SET TO %s\r\n",b_state?"ON":"OFF"); |
| gjgsd | 4:d4aeacb47955 | 191 | } |
| gjgsd | 4:d4aeacb47955 | 192 | else if(!strcmp (input,"BUTTONENABLE")) //enable button monitoring |
| gjgsd | 4:d4aeacb47955 | 193 | { |
| gjgsd | 4:d4aeacb47955 | 194 | b_state = ON; |
| gjgsd | 4:d4aeacb47955 | 195 | printf("BUTTON MONITORRING IS SET TO ON\r\n"); |
| gjgsd | 4:d4aeacb47955 | 196 | } |
| gjgsd | 4:d4aeacb47955 | 197 | else if(!strcmp (input,"BUTTONDISABLE")) //disable button monitoring |
| gjgsd | 4:d4aeacb47955 | 198 | { |
| gjgsd | 4:d4aeacb47955 | 199 | b_state = OFF; |
| gjgsd | 4:d4aeacb47955 | 200 | printf("BUTTON MONITORRING IS SET TO OFF\r\n"); |
| gjgsd | 4:d4aeacb47955 | 201 | } |
| gjgsd | 4:d4aeacb47955 | 202 | else if(!strcmp (input,"BUTTONSTATE")) //get button state |
| gjgsd | 4:d4aeacb47955 | 203 | { |
| gjgsd | 4:d4aeacb47955 | 204 | printf("BUTTON IS %sPUSHED\r\n",button?"NOT ":""); |
| gjgsd | 4:d4aeacb47955 | 205 | } |
| gjgsd | 4:d4aeacb47955 | 206 | else if(!strcmp (input,"HELP")) //print help message |
| gjgsd | 4:d4aeacb47955 | 207 | { |
| gjgsd | 4:d4aeacb47955 | 208 | print_help(); |
| gjgsd | 4:d4aeacb47955 | 209 | } |
| gjgsd | 4:d4aeacb47955 | 210 | else if (!strncmp (input,"LEDON:",6)) // reinit led timer |
| gjgsd | 4:d4aeacb47955 | 211 | { |
| gjgsd | 4:d4aeacb47955 | 212 | lamp_time = strtoint(input, LED_ON); |
| gjgsd | 4:d4aeacb47955 | 213 | switch (lamp_time){ |
| gjgsd | 4:d4aeacb47955 | 214 | case 0: |
| gjgsd | 4:d4aeacb47955 | 215 | case -2: // wrong time time |
| gjgsd | 4:d4aeacb47955 | 216 | printf("WRONG TIME IS SPECIFIED. RANGE IS 1-1000\r\n"); |
| gjgsd | 4:d4aeacb47955 | 217 | break; |
| gjgsd | 4:d4aeacb47955 | 218 | case -1: |
| gjgsd | 4:d4aeacb47955 | 219 | printf("PLEASE USE DIGITS FOR TIME SPECIFICATION.\r\n"); |
| gjgsd | 4:d4aeacb47955 | 220 | break; |
| gjgsd | 4:d4aeacb47955 | 221 | default: |
| gjgsd | 4:d4aeacb47955 | 222 | printf("LED IS ON FOR %d SECONDS\r\n",lamp_time); |
| gjgsd | 4:d4aeacb47955 | 223 | led1 = power(2,lamp_bright) * 0.01; |
| gjgsd | 4:d4aeacb47955 | 224 | state = ON; |
| gjgsd | 3:dd96529b7ae9 | 225 | } |
| gjgsd | 4:d4aeacb47955 | 226 | } |
| gjgsd | 4:d4aeacb47955 | 227 | else // wrong input |
| gjgsd | 4:d4aeacb47955 | 228 | { |
| gjgsd | 4:d4aeacb47955 | 229 | print_fc_on(); |
| bcostm | 0:5701b41769fd | 230 | } |
| bcostm | 0:5701b41769fd | 231 | } |
| bcostm | 0:5701b41769fd | 232 | |
| gjgsd | 4:d4aeacb47955 | 233 | //thread lamp, main function |
| gjgsd | 4:d4aeacb47955 | 234 | void led() |
| gjgsd | 4:d4aeacb47955 | 235 | { |
| gjgsd | 4:d4aeacb47955 | 236 | while (true) |
| gjgsd | 4:d4aeacb47955 | 237 | { |
| gjgsd | 4:d4aeacb47955 | 238 | scanf("%s",input); |
| gjgsd | 4:d4aeacb47955 | 239 | caps(); |
| gjgsd | 4:d4aeacb47955 | 240 | switch (state){ |
| gjgsd | 4:d4aeacb47955 | 241 | case OFF: |
| gjgsd | 4:d4aeacb47955 | 242 | led_off(); |
| gjgsd | 4:d4aeacb47955 | 243 | break; |
| gjgsd | 4:d4aeacb47955 | 244 | case ON: |
| gjgsd | 4:d4aeacb47955 | 245 | led_on(); |
| gjgsd | 4:d4aeacb47955 | 246 | break; |
| gjgsd | 4:d4aeacb47955 | 247 | default: |
| gjgsd | 4:d4aeacb47955 | 248 | break; |
| gjgsd | 4:d4aeacb47955 | 249 | } |
| gjgsd | 4:d4aeacb47955 | 250 | } |
| gjgsd | 4:d4aeacb47955 | 251 | } |
| gjgsd | 4:d4aeacb47955 | 252 | |
| gjgsd | 4:d4aeacb47955 | 253 | //thread timer, main function |
| gjgsd | 4:d4aeacb47955 | 254 | void timer() |
| gjgsd | 4:d4aeacb47955 | 255 | { |
| gjgsd | 4:d4aeacb47955 | 256 | while(true){ |
| gjgsd | 4:d4aeacb47955 | 257 | while(state == ON) |
| gjgsd | 4:d4aeacb47955 | 258 | { |
| gjgsd | 4:d4aeacb47955 | 259 | lamp_time --; |
| gjgsd | 4:d4aeacb47955 | 260 | if (lamp_time == 0) |
| gjgsd | 4:d4aeacb47955 | 261 | { |
| gjgsd | 4:d4aeacb47955 | 262 | led1 = 0; |
| gjgsd | 4:d4aeacb47955 | 263 | printf("LED IS TURNED OFF\r\n"); |
| gjgsd | 4:d4aeacb47955 | 264 | lamp_thread.start(led_off); |
| gjgsd | 4:d4aeacb47955 | 265 | state = OFF; |
| gjgsd | 4:d4aeacb47955 | 266 | b_state = OFF; |
| gjgsd | 4:d4aeacb47955 | 267 | } |
| gjgsd | 4:d4aeacb47955 | 268 | wait(1); |
| gjgsd | 4:d4aeacb47955 | 269 | } |
| gjgsd | 4:d4aeacb47955 | 270 | wait(1); |
| gjgsd | 4:d4aeacb47955 | 271 | } |
| gjgsd | 4:d4aeacb47955 | 272 | } |
| gjgsd | 4:d4aeacb47955 | 273 | |
| bcostm | 0:5701b41769fd | 274 | int main() |
| bcostm | 0:5701b41769fd | 275 | { |
| gjgsd | 4:d4aeacb47955 | 276 | print_welcome(); |
| gjgsd | 4:d4aeacb47955 | 277 | lamp_thread.start(led); |
| gjgsd | 4:d4aeacb47955 | 278 | timer_thread.start(timer); |
| bcostm | 2:35f13b7f3659 | 279 | |
| bcostm | 0:5701b41769fd | 280 | while (true) { |
| gjgsd | 4:d4aeacb47955 | 281 | |
| gjgsd | 4:d4aeacb47955 | 282 | if (state == ON && b_state == ON) |
| gjgsd | 4:d4aeacb47955 | 283 | { |
| gjgsd | 4:d4aeacb47955 | 284 | if (button != b_push) |
| gjgsd | 4:d4aeacb47955 | 285 | { |
| gjgsd | 4:d4aeacb47955 | 286 | b_push = button; |
| gjgsd | 4:d4aeacb47955 | 287 | printf("BUTTON IS %sPUSHED\r\n",b_push?"NOT ":""); |
| gjgsd | 4:d4aeacb47955 | 288 | } |
| gjgsd | 4:d4aeacb47955 | 289 | } |
| gjgsd | 3:dd96529b7ae9 | 290 | wait(0.2); |
| gjgsd | 3:dd96529b7ae9 | 291 | |
| gjgsd | 3:dd96529b7ae9 | 292 | } |
| gjgsd | 3:dd96529b7ae9 | 293 | |
| bcostm | 0:5701b41769fd | 294 | } |