![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ATT_SMS_System for home security system
Dependencies: FXOS8700CQ MODSERIAL mbed-rtos mbed
Fork of ATT_Cellular_IOT_Button by
main.cpp@73:4a7aa34332b9, 2018-04-30 (annotated)
- Committer:
- natschwa
- Date:
- Mon Apr 30 17:14:34 2018 +0000
- Revision:
- 73:4a7aa34332b9
- Parent:
- 71:bcbc072b85e1
Working ATT_SMS_System
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rfinn | 68:d38834307b17 | 1 | #include "mbed.h" |
JMF | 0:9d5134074d84 | 2 | #include <cctype> |
JMF | 0:9d5134074d84 | 3 | #include <string> |
JMF | 2:0e2ef866af95 | 4 | #include "config_me.h" |
stefanrousseau | 61:f6b93129f954 | 5 | #include "cell_modem.h" |
stefanrousseau | 11:e6602513730f | 6 | #include "hardware.h" |
stefanrousseau | 11:e6602513730f | 7 | |
natschwa | 73:4a7aa34332b9 | 8 | #define RX_ PTB10 |
natschwa | 73:4a7aa34332b9 | 9 | #define TX_ PTB11 |
natschwa | 73:4a7aa34332b9 | 10 | |
natschwa | 73:4a7aa34332b9 | 11 | Serial BlueTooth(TX_, RX_); // bluetooth serial port |
natschwa | 73:4a7aa34332b9 | 12 | |
stefanrousseau | 61:f6b93129f954 | 13 | I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used |
stefanrousseau | 56:cb42ff383dab | 14 | MODSERIAL pc(USBTX, USBRX, 256, 256); // tx, rx with default tx, rx buffer sizes |
stefanrousseau | 63:90d7c69993cd | 15 | MODSERIAL mdm(PTD3, PTD2, 4096, 4096); |
stefanrousseau | 16:17c5916f2d12 | 16 | DigitalOut led_green(LED_GREEN); |
stefanrousseau | 16:17c5916f2d12 | 17 | DigitalOut led_red(LED_RED); |
stefanrousseau | 16:17c5916f2d12 | 18 | DigitalOut led_blue(LED_BLUE); |
JMF | 0:9d5134074d84 | 19 | |
natschwa | 73:4a7aa34332b9 | 20 | DigitalOut Green(LED_GREEN); |
natschwa | 73:4a7aa34332b9 | 21 | DigitalOut Red(LED_RED); |
natschwa | 73:4a7aa34332b9 | 22 | DigitalOut Blue(LED_BLUE); |
natschwa | 73:4a7aa34332b9 | 23 | |
natschwa | 73:4a7aa34332b9 | 24 | //DigitalIn motion(D8); |
natschwa | 73:4a7aa34332b9 | 25 | |
rfinn | 68:d38834307b17 | 26 | // interrupts for buttons |
rfinn | 68:d38834307b17 | 27 | InterruptIn sw3(SW3); |
rfinn | 68:d38834307b17 | 28 | InterruptIn sw2(SW2); |
JMF | 0:9d5134074d84 | 29 | |
natschwa | 73:4a7aa34332b9 | 30 | //Thread thread1; |
natschwa | 73:4a7aa34332b9 | 31 | |
rfinn | 68:d38834307b17 | 32 | // flag - must be volatile as changes within ISR |
rfinn | 68:d38834307b17 | 33 | // g_ prefix makes it easier to distinguish it as global |
rfinn | 68:d38834307b17 | 34 | volatile int g_sw3_flag = 0; |
rfinn | 68:d38834307b17 | 35 | volatile int g_sw2_flag = 0; |
rfinn | 68:d38834307b17 | 36 | |
rfinn | 68:d38834307b17 | 37 | // SW2 event-triggered interrupt |
rfinn | 71:bcbc072b85e1 | 38 | // ISR = interrupt service routine |
rfinn | 71:bcbc072b85e1 | 39 | // down = button was pushed down/falling |
rfinn | 71:bcbc072b85e1 | 40 | // up = button was released/rising |
rfinn | 68:d38834307b17 | 41 | void sw2_isr_down() |
stefanrousseau | 3:26b3cc155f39 | 42 | { |
rfinn | 68:d38834307b17 | 43 | g_sw2_flag = 1; // set flag in ISR |
rfinn | 68:d38834307b17 | 44 | } |
stefanrousseau | 12:7c94ec5069dc | 45 | |
rfinn | 68:d38834307b17 | 46 | void sw2_isr_up() |
stefanrousseau | 3:26b3cc155f39 | 47 | { |
rfinn | 68:d38834307b17 | 48 | g_sw2_flag = 0; |
rfinn | 68:d38834307b17 | 49 | } |
rfinn | 68:d38834307b17 | 50 | |
rfinn | 68:d38834307b17 | 51 | // SW3 event-triggered interrupt |
rfinn | 68:d38834307b17 | 52 | void sw3_isr_down() |
rfinn | 68:d38834307b17 | 53 | { |
rfinn | 68:d38834307b17 | 54 | g_sw3_flag = 1; // set flag in ISR |
rfinn | 68:d38834307b17 | 55 | } |
rfinn | 68:d38834307b17 | 56 | |
rfinn | 68:d38834307b17 | 57 | void sw3_isr_up() |
stefanrousseau | 3:26b3cc155f39 | 58 | { |
rfinn | 68:d38834307b17 | 59 | g_sw3_flag = 0; |
rfinn | 68:d38834307b17 | 60 | } |
rfinn | 68:d38834307b17 | 61 | |
rfinn | 68:d38834307b17 | 62 | void GenerateModemString(char * modem_string, char btn1, char btn2) |
rfinn | 68:d38834307b17 | 63 | { |
natschwa | 73:4a7aa34332b9 | 64 | |
rfinn | 68:d38834307b17 | 65 | sprintf(modem_string, "serial:%s button1:%c button2:%c\r\n", |
rfinn | 68:d38834307b17 | 66 | M2X_DEVICE_SERIAL, btn1, btn2 |
rfinn | 68:d38834307b17 | 67 | ); |
rfinn | 70:e25fe7e5488a | 68 | |
natschwa | 73:4a7aa34332b9 | 69 | |
rfinn | 70:e25fe7e5488a | 70 | // HTTP method |
natschwa | 73:4a7aa34332b9 | 71 | /* |
natschwa | 73:4a7aa34332b9 | 72 | sprintf(modem_string, "GET %s%s?serial=%s&button1=%c&button2=%c %s%s\r\n\r\n",FLOW_BASE_PATH, |
natschwa | 73:4a7aa34332b9 | 73 | FLOW_INPUT_NAME, M2X_DEVICE_SERIAL, |
natschwa | 73:4a7aa34332b9 | 74 | btn1, btn2, FLOW_URL_TYPE, MY_SERVER_NAME); |
natschwa | 73:4a7aa34332b9 | 75 | */ |
rfinn | 70:e25fe7e5488a | 76 | |
rfinn | 68:d38834307b17 | 77 | } //GenerateModemString |
rfinn | 68:d38834307b17 | 78 | |
stefanrousseau | 3:26b3cc155f39 | 79 | |
stefanrousseau | 16:17c5916f2d12 | 80 | //******************************************************************************************************************************************** |
stefanrousseau | 16:17c5916f2d12 | 81 | //* Set the RGB LED's Color |
rfinn | 68:d38834307b17 | 82 | //* LED Color 0=Off to 7=White. 3 bits represent BGR (bit0=Red, bit1=Green, bit2=Blue) |
stefanrousseau | 16:17c5916f2d12 | 83 | //******************************************************************************************************************************************** |
stefanrousseau | 16:17c5916f2d12 | 84 | void SetLedColor(unsigned char ucColor) |
stefanrousseau | 16:17c5916f2d12 | 85 | { |
stefanrousseau | 16:17c5916f2d12 | 86 | //Note that when an LED is on, you write a 0 to it: |
stefanrousseau | 16:17c5916f2d12 | 87 | led_red = !(ucColor & 0x1); //bit 0 |
stefanrousseau | 16:17c5916f2d12 | 88 | led_green = !(ucColor & 0x2); //bit 1 |
stefanrousseau | 16:17c5916f2d12 | 89 | led_blue = !(ucColor & 0x4); //bit 2 |
stefanrousseau | 16:17c5916f2d12 | 90 | } //SetLedColor() |
stefanrousseau | 16:17c5916f2d12 | 91 | |
stefanrousseau | 16:17c5916f2d12 | 92 | //******************************************************************************************************************************************** |
rfinn | 68:d38834307b17 | 93 | //* Process the JSON response. In this example we are only extracting a LED color. |
stefanrousseau | 16:17c5916f2d12 | 94 | //******************************************************************************************************************************************** |
stefanrousseau | 16:17c5916f2d12 | 95 | bool parse_JSON(char* json_string) |
stefanrousseau | 16:17c5916f2d12 | 96 | { |
stefanrousseau | 16:17c5916f2d12 | 97 | char* beginquote; |
stefanrousseau | 16:17c5916f2d12 | 98 | char token[] = "\"LED\":\""; |
stefanrousseau | 16:17c5916f2d12 | 99 | beginquote = strstr(json_string, token ); |
rfinn | 68:d38834307b17 | 100 | if ((beginquote != 0)) { |
stefanrousseau | 16:17c5916f2d12 | 101 | char cLedColor = beginquote[strlen(token)]; |
stefanrousseau | 64:09004cd610df | 102 | PRINTF(GRN "LED Found : %c" DEF "\r\n", cLedColor); |
rfinn | 68:d38834307b17 | 103 | switch(cLedColor) { |
rfinn | 68:d38834307b17 | 104 | case 'O': { |
rfinn | 68:d38834307b17 | 105 | //Off |
stefanrousseau | 16:17c5916f2d12 | 106 | SetLedColor(0); |
stefanrousseau | 16:17c5916f2d12 | 107 | break; |
stefanrousseau | 16:17c5916f2d12 | 108 | } |
rfinn | 68:d38834307b17 | 109 | case 'R': { |
rfinn | 68:d38834307b17 | 110 | //Red |
stefanrousseau | 16:17c5916f2d12 | 111 | SetLedColor(1); |
stefanrousseau | 16:17c5916f2d12 | 112 | break; |
stefanrousseau | 16:17c5916f2d12 | 113 | } |
rfinn | 68:d38834307b17 | 114 | case 'G': { |
rfinn | 68:d38834307b17 | 115 | //Green |
stefanrousseau | 16:17c5916f2d12 | 116 | SetLedColor(2); |
stefanrousseau | 16:17c5916f2d12 | 117 | break; |
stefanrousseau | 16:17c5916f2d12 | 118 | } |
rfinn | 68:d38834307b17 | 119 | case 'Y': { |
rfinn | 68:d38834307b17 | 120 | //Yellow |
stefanrousseau | 16:17c5916f2d12 | 121 | SetLedColor(3); |
stefanrousseau | 16:17c5916f2d12 | 122 | break; |
stefanrousseau | 16:17c5916f2d12 | 123 | } |
rfinn | 68:d38834307b17 | 124 | case 'B': { |
rfinn | 68:d38834307b17 | 125 | //Blue |
stefanrousseau | 16:17c5916f2d12 | 126 | SetLedColor(4); |
stefanrousseau | 16:17c5916f2d12 | 127 | break; |
stefanrousseau | 16:17c5916f2d12 | 128 | } |
rfinn | 68:d38834307b17 | 129 | case 'M': { |
rfinn | 68:d38834307b17 | 130 | //Magenta |
stefanrousseau | 16:17c5916f2d12 | 131 | SetLedColor(5); |
stefanrousseau | 16:17c5916f2d12 | 132 | break; |
stefanrousseau | 16:17c5916f2d12 | 133 | } |
rfinn | 68:d38834307b17 | 134 | case 'T': { |
rfinn | 68:d38834307b17 | 135 | //Turquoise |
stefanrousseau | 16:17c5916f2d12 | 136 | SetLedColor(6); |
stefanrousseau | 16:17c5916f2d12 | 137 | break; |
stefanrousseau | 16:17c5916f2d12 | 138 | } |
rfinn | 68:d38834307b17 | 139 | case 'W': { |
rfinn | 68:d38834307b17 | 140 | //White |
stefanrousseau | 16:17c5916f2d12 | 141 | SetLedColor(7); |
stefanrousseau | 16:17c5916f2d12 | 142 | break; |
stefanrousseau | 16:17c5916f2d12 | 143 | } |
rfinn | 68:d38834307b17 | 144 | default: { |
stefanrousseau | 16:17c5916f2d12 | 145 | break; |
stefanrousseau | 16:17c5916f2d12 | 146 | } |
stefanrousseau | 16:17c5916f2d12 | 147 | } //switch(cLedColor) |
stefanrousseau | 16:17c5916f2d12 | 148 | return true; |
rfinn | 68:d38834307b17 | 149 | } else { |
stefanrousseau | 16:17c5916f2d12 | 150 | return false; |
stefanrousseau | 16:17c5916f2d12 | 151 | } |
stefanrousseau | 16:17c5916f2d12 | 152 | } //parse_JSON |
stefanrousseau | 16:17c5916f2d12 | 153 | |
rfinn | 68:d38834307b17 | 154 | void send_button_data(char btn1, char btn2) |
rfinn | 68:d38834307b17 | 155 | { |
rfinn | 68:d38834307b17 | 156 | char modem_string[512]; |
rfinn | 68:d38834307b17 | 157 | GenerateModemString(&modem_string[0], btn1, btn2); |
rfinn | 68:d38834307b17 | 158 | char myJsonResponse[512]; |
rfinn | 68:d38834307b17 | 159 | if (cell_modem_Sendreceive(&modem_string[0], &myJsonResponse[0])) { |
rfinn | 68:d38834307b17 | 160 | if (true) { |
rfinn | 68:d38834307b17 | 161 | //ledOnce = 1; |
rfinn | 68:d38834307b17 | 162 | SetLedColor(0x2); //Green |
rfinn | 68:d38834307b17 | 163 | } |
rfinn | 68:d38834307b17 | 164 | parse_JSON(&myJsonResponse[0]); |
rfinn | 68:d38834307b17 | 165 | } |
rfinn | 68:d38834307b17 | 166 | } |
rfinn | 68:d38834307b17 | 167 | |
natschwa | 73:4a7aa34332b9 | 168 | void sendMsg(char msg,int time); |
natschwa | 73:4a7aa34332b9 | 169 | void read_BlueTooth(void); |
natschwa | 73:4a7aa34332b9 | 170 | void LED_Color(char color,int blink); |
natschwa | 73:4a7aa34332b9 | 171 | |
natschwa | 73:4a7aa34332b9 | 172 | char Base_ConnectACK ='H'; |
natschwa | 73:4a7aa34332b9 | 173 | char Base_ConnectREQ = 'H'; |
natschwa | 73:4a7aa34332b9 | 174 | char ReconnectREQ = 'R'; |
natschwa | 73:4a7aa34332b9 | 175 | char IntruderAlert = 'I'; |
natschwa | 73:4a7aa34332b9 | 176 | |
natschwa | 73:4a7aa34332b9 | 177 | bool ReconnectFlg = false; |
natschwa | 73:4a7aa34332b9 | 178 | bool readyFlg = true; |
natschwa | 73:4a7aa34332b9 | 179 | bool BlueFlg = true; |
natschwa | 73:4a7aa34332b9 | 180 | bool motionFlg = true; |
natschwa | 73:4a7aa34332b9 | 181 | |
natschwa | 73:4a7aa34332b9 | 182 | DigitalIn motion(D10); |
natschwa | 73:4a7aa34332b9 | 183 | DigitalOut camera(PTB20); |
natschwa | 73:4a7aa34332b9 | 184 | |
rfinn | 68:d38834307b17 | 185 | int main() |
rfinn | 68:d38834307b17 | 186 | { |
rfinn | 68:d38834307b17 | 187 | //static unsigned ledOnce = 0; |
fkellermavnet | 20:27a4f27254d0 | 188 | |
stefanrousseau | 61:f6b93129f954 | 189 | pc.baud(115200); |
rfinn | 68:d38834307b17 | 190 | PRINTF(GRN "Hello World from the Cellular IoT Kit!\r\n"); |
rfinn | 68:d38834307b17 | 191 | PRINTF(GRN "Cellular IoT Buttons!\r\n\r\n"); |
JMF | 0:9d5134074d84 | 192 | |
rfinn | 68:d38834307b17 | 193 | // SW have a pull-up resistor, so the pin will be at 3.3 V by default |
rfinn | 68:d38834307b17 | 194 | // and fall to 0 V when pressed. We therefore need to look for a falling edge |
rfinn | 68:d38834307b17 | 195 | // on the pin to fire the interrupt |
rfinn | 68:d38834307b17 | 196 | sw3.fall(&sw3_isr_down); |
rfinn | 68:d38834307b17 | 197 | sw3.rise(&sw3_isr_up); |
rfinn | 68:d38834307b17 | 198 | sw2.fall(&sw2_isr_down); |
rfinn | 68:d38834307b17 | 199 | sw2.rise(&sw2_isr_up); |
rfinn | 68:d38834307b17 | 200 | // since SW have an external pull-up, we should disable to internal pull-down |
rfinn | 68:d38834307b17 | 201 | // resistor that is enabled by default using InterruptIn |
rfinn | 68:d38834307b17 | 202 | sw3.mode(PullNone); |
rfinn | 68:d38834307b17 | 203 | sw2.mode(PullNone); |
stefanrousseau | 11:e6602513730f | 204 | |
natschwa | 73:4a7aa34332b9 | 205 | LED_Color('P',0); //Red |
natschwa | 73:4a7aa34332b9 | 206 | |
stefanrousseau | 64:09004cd610df | 207 | PRINTF("\r\n"); |
natschwa | 73:4a7aa34332b9 | 208 | //cell_modem_init(); // Initialize the modem |
JMF | 0:9d5134074d84 | 209 | |
JMF | 2:0e2ef866af95 | 210 | // Send and receive data perpetually |
natschwa | 73:4a7aa34332b9 | 211 | |
natschwa | 73:4a7aa34332b9 | 212 | sendMsg(ReconnectREQ,10); // sending master reconnection request |
natschwa | 73:4a7aa34332b9 | 213 | while(true) |
natschwa | 73:4a7aa34332b9 | 214 | { |
natschwa | 73:4a7aa34332b9 | 215 | if(BlueFlg){ |
natschwa | 73:4a7aa34332b9 | 216 | read_BlueTooth(); |
natschwa | 73:4a7aa34332b9 | 217 | } |
natschwa | 73:4a7aa34332b9 | 218 | |
natschwa | 73:4a7aa34332b9 | 219 | if( ReconnectFlg ) |
natschwa | 73:4a7aa34332b9 | 220 | { |
natschwa | 73:4a7aa34332b9 | 221 | SetLedColor(5); //purple |
natschwa | 73:4a7aa34332b9 | 222 | printf("Connected\n\rSending Ack to Master\n\r"); |
natschwa | 73:4a7aa34332b9 | 223 | |
natschwa | 73:4a7aa34332b9 | 224 | sendMsg(Base_ConnectACK,10); // sending master acknowledgment |
natschwa | 73:4a7aa34332b9 | 225 | |
natschwa | 73:4a7aa34332b9 | 226 | //printf("System Ready\n\r"); // turn LGB LED blue upon Ack recived |
natschwa | 73:4a7aa34332b9 | 227 | //LED_Color('B',0); |
natschwa | 73:4a7aa34332b9 | 228 | //cell_modem_init(); // Initialize the modem |
natschwa | 73:4a7aa34332b9 | 229 | ReconnectFlg = false; |
natschwa | 73:4a7aa34332b9 | 230 | readyFlg = true; |
natschwa | 73:4a7aa34332b9 | 231 | } |
natschwa | 73:4a7aa34332b9 | 232 | |
rfinn | 68:d38834307b17 | 233 | if (g_sw3_flag) { |
rfinn | 68:d38834307b17 | 234 | printf("%s\n","SW3 Button"); |
natschwa | 73:4a7aa34332b9 | 235 | LED_Color('Y',0); |
natschwa | 73:4a7aa34332b9 | 236 | sendMsg(IntruderAlert,10); |
rfinn | 68:d38834307b17 | 237 | send_button_data('0','1'); |
natschwa | 73:4a7aa34332b9 | 238 | readyFlg = true; |
natschwa | 73:4a7aa34332b9 | 239 | //wait(4); |
natschwa | 73:4a7aa34332b9 | 240 | } |
rfinn | 68:d38834307b17 | 241 | |
natschwa | 73:4a7aa34332b9 | 242 | if (motionFlg) { |
natschwa | 73:4a7aa34332b9 | 243 | if(motion){ |
natschwa | 73:4a7aa34332b9 | 244 | printf("\n\rMotion Detected\n\r"); |
natschwa | 73:4a7aa34332b9 | 245 | LED_Color('Y',0); |
natschwa | 73:4a7aa34332b9 | 246 | camera = 1; |
natschwa | 73:4a7aa34332b9 | 247 | sendMsg(IntruderAlert,100); |
natschwa | 73:4a7aa34332b9 | 248 | send_button_data('0','1'); |
natschwa | 73:4a7aa34332b9 | 249 | camera =0; |
natschwa | 73:4a7aa34332b9 | 250 | motionFlg = false; |
natschwa | 73:4a7aa34332b9 | 251 | readyFlg = true; |
natschwa | 73:4a7aa34332b9 | 252 | wait(4); |
natschwa | 73:4a7aa34332b9 | 253 | } |
natschwa | 73:4a7aa34332b9 | 254 | } |
natschwa | 73:4a7aa34332b9 | 255 | |
natschwa | 73:4a7aa34332b9 | 256 | if(readyFlg) |
natschwa | 73:4a7aa34332b9 | 257 | { |
natschwa | 73:4a7aa34332b9 | 258 | readyFlg = false; |
natschwa | 73:4a7aa34332b9 | 259 | BlueFlg = false; |
natschwa | 73:4a7aa34332b9 | 260 | motionFlg =true; |
natschwa | 73:4a7aa34332b9 | 261 | LED_Color('B',0); |
natschwa | 73:4a7aa34332b9 | 262 | cell_modem_init(); // Initialize the modem |
natschwa | 73:4a7aa34332b9 | 263 | LED_Color('G',0); |
natschwa | 73:4a7aa34332b9 | 264 | printf("System Ready\n\r"); |
rfinn | 68:d38834307b17 | 265 | } |
rfinn | 68:d38834307b17 | 266 | |
rfinn | 68:d38834307b17 | 267 | // put the MCU to sleep until an interrupt wakes it up |
natschwa | 73:4a7aa34332b9 | 268 | //sleep(); |
natschwa | 73:4a7aa34332b9 | 269 | //printf("\rWaiting..."); |
stefanrousseau | 3:26b3cc155f39 | 270 | } //forever loop |
JMF | 0:9d5134074d84 | 271 | } |
natschwa | 73:4a7aa34332b9 | 272 | |
natschwa | 73:4a7aa34332b9 | 273 | void read_BlueTooth(){ |
natschwa | 73:4a7aa34332b9 | 274 | |
natschwa | 73:4a7aa34332b9 | 275 | if(BlueTooth.readable()) // read data from the bluetooth serial port |
natschwa | 73:4a7aa34332b9 | 276 | { |
natschwa | 73:4a7aa34332b9 | 277 | //printf("data:%c\n\r",BlueTooth.getc()); |
natschwa | 73:4a7aa34332b9 | 278 | if( BlueTooth.getc() == Base_ConnectREQ ){ |
natschwa | 73:4a7aa34332b9 | 279 | printf("Connecting to Master\n\r"); |
natschwa | 73:4a7aa34332b9 | 280 | ReconnectFlg = true; |
natschwa | 73:4a7aa34332b9 | 281 | } |
natschwa | 73:4a7aa34332b9 | 282 | }//end if |
natschwa | 73:4a7aa34332b9 | 283 | |
natschwa | 73:4a7aa34332b9 | 284 | |
natschwa | 73:4a7aa34332b9 | 285 | }// read_BlueTooth |
natschwa | 73:4a7aa34332b9 | 286 | |
natschwa | 73:4a7aa34332b9 | 287 | void sendMsg(char msg,int time){ |
natschwa | 73:4a7aa34332b9 | 288 | //printf("send:%c\n\r",msg); |
natschwa | 73:4a7aa34332b9 | 289 | while(time--){ |
natschwa | 73:4a7aa34332b9 | 290 | BlueTooth.putc(msg); |
natschwa | 73:4a7aa34332b9 | 291 | wait(0.1); |
natschwa | 73:4a7aa34332b9 | 292 | } |
natschwa | 73:4a7aa34332b9 | 293 | }//end sendMSg |
natschwa | 73:4a7aa34332b9 | 294 | |
natschwa | 73:4a7aa34332b9 | 295 | void LED_Color(char color,int blink){ |
natschwa | 73:4a7aa34332b9 | 296 | |
natschwa | 73:4a7aa34332b9 | 297 | /*LedsOFF (active low)*/ |
natschwa | 73:4a7aa34332b9 | 298 | Red = 1; |
natschwa | 73:4a7aa34332b9 | 299 | Green = 1; |
natschwa | 73:4a7aa34332b9 | 300 | Blue = 1; |
natschwa | 73:4a7aa34332b9 | 301 | if (color == 'C') |
natschwa | 73:4a7aa34332b9 | 302 | return; |
natschwa | 73:4a7aa34332b9 | 303 | else if(color == 'G') |
natschwa | 73:4a7aa34332b9 | 304 | Green = 0; |
natschwa | 73:4a7aa34332b9 | 305 | else if(color == 'R') |
natschwa | 73:4a7aa34332b9 | 306 | Red = 0; |
natschwa | 73:4a7aa34332b9 | 307 | else if(color == 'B') |
natschwa | 73:4a7aa34332b9 | 308 | Blue = 0; |
natschwa | 73:4a7aa34332b9 | 309 | else if(color == 'Y'){ |
natschwa | 73:4a7aa34332b9 | 310 | Red = 0; |
natschwa | 73:4a7aa34332b9 | 311 | Green = 0; |
natschwa | 73:4a7aa34332b9 | 312 | } |
natschwa | 73:4a7aa34332b9 | 313 | else if(color == 'P'){ |
natschwa | 73:4a7aa34332b9 | 314 | Blue = 0; |
natschwa | 73:4a7aa34332b9 | 315 | Red = 0; |
natschwa | 73:4a7aa34332b9 | 316 | } |
natschwa | 73:4a7aa34332b9 | 317 | else if(color == 'W'){ |
natschwa | 73:4a7aa34332b9 | 318 | Blue = 0; |
natschwa | 73:4a7aa34332b9 | 319 | Red = 0; |
natschwa | 73:4a7aa34332b9 | 320 | Green = 0; |
natschwa | 73:4a7aa34332b9 | 321 | } |
natschwa | 73:4a7aa34332b9 | 322 | else{} // do nothing |
natschwa | 73:4a7aa34332b9 | 323 | |
natschwa | 73:4a7aa34332b9 | 324 | if(blink){ |
natschwa | 73:4a7aa34332b9 | 325 | wait(0.1f); // wait a small period of time |
natschwa | 73:4a7aa34332b9 | 326 | Red = 1; |
natschwa | 73:4a7aa34332b9 | 327 | Green = 1; |
natschwa | 73:4a7aa34332b9 | 328 | Blue = 1; |
natschwa | 73:4a7aa34332b9 | 329 | wait(0.1f); |
natschwa | 73:4a7aa34332b9 | 330 | } |
natschwa | 73:4a7aa34332b9 | 331 | }//end LED_Color |