![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo1
Dependencies: SHT30-DIS-B WakeUp mbed
Fork of M1DK_Skywire_Demo by
main.cpp@14:44eb72d9995e, 2018-06-22 (annotated)
- Committer:
- charlesxu918
- Date:
- Fri Jun 22 12:40:45 2018 +0000
- Revision:
- 14:44eb72d9995e
- Parent:
- 13:f827f384f0a1
Demo1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kholland | 4:e7a79d3542e1 | 1 | /* main.cpp */ |
kylerodgers | 13:f827f384f0a1 | 2 | /* Copyright (C) 2017 nimbelink.com, MIT License |
kholland | 4:e7a79d3542e1 | 3 | * |
kholland | 4:e7a79d3542e1 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kholland | 4:e7a79d3542e1 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kholland | 4:e7a79d3542e1 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kholland | 4:e7a79d3542e1 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kholland | 4:e7a79d3542e1 | 8 | * furnished to do so, subject to the following conditions: |
kholland | 4:e7a79d3542e1 | 9 | * |
kholland | 4:e7a79d3542e1 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
kholland | 4:e7a79d3542e1 | 11 | * substantial portions of the Software. |
kholland | 4:e7a79d3542e1 | 12 | * |
kholland | 4:e7a79d3542e1 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kholland | 4:e7a79d3542e1 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kholland | 4:e7a79d3542e1 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kholland | 4:e7a79d3542e1 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kholland | 4:e7a79d3542e1 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kholland | 4:e7a79d3542e1 | 18 | */ |
kholland | 0:3095958bc639 | 19 | |
kholland | 10:5974a7b2cf38 | 20 | /* |
kholland | 10:5974a7b2cf38 | 21 | * DESCRIPTION |
kylerodgers | 13:f827f384f0a1 | 22 | * This code sends sensor data to Dweet.io on the NL-M1DK. |
kholland | 10:5974a7b2cf38 | 23 | */ |
kholland | 10:5974a7b2cf38 | 24 | |
kholland | 10:5974a7b2cf38 | 25 | /* |
kholland | 10:5974a7b2cf38 | 26 | * INSTRUCTIONS FOR USING THIS CODE |
kylerodgers | 13:f827f384f0a1 | 27 | * 1. Change the "DeviceID" to a unique identifier for your Nucleo board. One recommendation |
kholland | 10:5974a7b2cf38 | 28 | * would be to use the MEID/IMEI of your Skywire Modem. |
kholland | 10:5974a7b2cf38 | 29 | */ |
kholland | 10:5974a7b2cf38 | 30 | |
GregNash | 11:78a28ca6409f | 31 | #include "mbed.h" // mbed Library |
GregNash | 11:78a28ca6409f | 32 | #include "pinmap.h" // pinmap needed for hardware flow control |
GregNash | 11:78a28ca6409f | 33 | |
GregNash | 11:78a28ca6409f | 34 | #include "SHT30DISB.h" |
kholland | 0:3095958bc639 | 35 | |
charlesxu918 | 14:44eb72d9995e | 36 | #include "WakeUp.h" |
charlesxu918 | 14:44eb72d9995e | 37 | |
charlesxu918 | 14:44eb72d9995e | 38 | #include "LowPowerTimeout.h" |
charlesxu918 | 14:44eb72d9995e | 39 | #include "sleep_api.h" |
charlesxu918 | 14:44eb72d9995e | 40 | #include "cmsis.h" |
charlesxu918 | 14:44eb72d9995e | 41 | |
GregNash | 11:78a28ca6409f | 42 | // --CHANGE THIS FOR YOUR SETUP-- |
charlesxu918 | 14:44eb72d9995e | 43 | #define DeviceID "CP Prototype001" //DweetIO unique IDA |
GregNash | 11:78a28ca6409f | 44 | |
GregNash | 11:78a28ca6409f | 45 | // --CHANGE THIS FOR YOUR SETUP (IF APPLICABLE)-- |
kylerodgers | 13:f827f384f0a1 | 46 | const char *APN = "NIMBLINK.GW12.VZWENTP"; |
kholland | 0:3095958bc639 | 47 | |
kholland | 10:5974a7b2cf38 | 48 | DigitalOut myled(LED1); // Main LED |
kylerodgers | 13:f827f384f0a1 | 49 | DigitalOut skywire_rts(PB_5); // Skywire Send |
kylerodgers | 13:f827f384f0a1 | 50 | DigitalOut green_LED(D7); // Green LED |
kylerodgers | 13:f827f384f0a1 | 51 | DigitalOut red_LED(D10); // Red LED |
kholland | 0:3095958bc639 | 52 | |
kylerodgers | 13:f827f384f0a1 | 53 | DigitalOut nRESET(PB_4); // Skywire Reset line |
kylerodgers | 13:f827f384f0a1 | 54 | |
kylerodgers | 13:f827f384f0a1 | 55 | AnalogIn photo_trans(A3); // Photo Transistor |
kylerodgers | 13:f827f384f0a1 | 56 | DigitalOut photo_trans_nEN(D11); // Photo Transistor Enable |
kylerodgers | 13:f827f384f0a1 | 57 | DigitalIn button1(PA_5); // Button 1 |
kholland | 10:5974a7b2cf38 | 58 | |
kholland | 10:5974a7b2cf38 | 59 | Serial skywire(PA_9,PA_10); // Serial comms to Skywire |
kholland | 10:5974a7b2cf38 | 60 | Serial debug_pc(USBTX, USBRX); // USB connection to PC |
kholland | 10:5974a7b2cf38 | 61 | |
kholland | 10:5974a7b2cf38 | 62 | I2C i2c(PB_9,PB_8); // Setup I2C bus for sensors |
GregNash | 11:78a28ca6409f | 63 | |
kylerodgers | 13:f827f384f0a1 | 64 | // SHT30 Sensor Setup |
kylerodgers | 13:f827f384f0a1 | 65 | SHT30DISB SHT30(i2c); |
kholland | 10:5974a7b2cf38 | 66 | |
kylerodgers | 13:f827f384f0a1 | 67 | // variable to switch state |
kylerodgers | 13:f827f384f0a1 | 68 | bool sw1; |
kholland | 0:3095958bc639 | 69 | |
kholland | 10:5974a7b2cf38 | 70 | // char array for reading from Skywire |
kholland | 3:4b2176f6474c | 71 | char str[255]; |
kylerodgers | 13:f827f384f0a1 | 72 | |
kylerodgers | 13:f827f384f0a1 | 73 | // Variables for checking CSQ |
GregNash | 11:78a28ca6409f | 74 | char csq[3]="99"; |
GregNash | 11:78a28ca6409f | 75 | int csq_val = 99; |
kholland | 3:4b2176f6474c | 76 | |
kholland | 10:5974a7b2cf38 | 77 | // Variables for UART comms |
kholland | 3:4b2176f6474c | 78 | volatile int rx_in=0; |
kholland | 3:4b2176f6474c | 79 | volatile int rx_out=0; |
kholland | 10:5974a7b2cf38 | 80 | const int buffer_size = 600; |
kholland | 3:4b2176f6474c | 81 | char rx_buffer[buffer_size+1]; |
kholland | 3:4b2176f6474c | 82 | char rx_line[buffer_size]; |
kholland | 3:4b2176f6474c | 83 | |
kholland | 10:5974a7b2cf38 | 84 | // Interrupt for the Skywire |
kholland | 10:5974a7b2cf38 | 85 | void Skywire_Rx_interrupt() |
kholland | 10:5974a7b2cf38 | 86 | { |
kholland | 3:4b2176f6474c | 87 | // Loop just in case more than one character is in UART's receive FIFO buffer |
kholland | 3:4b2176f6474c | 88 | // Stop if buffer full |
kholland | 3:4b2176f6474c | 89 | while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { |
kholland | 3:4b2176f6474c | 90 | rx_buffer[rx_in] = skywire.getc(); |
kholland | 3:4b2176f6474c | 91 | rx_in = (rx_in + 1) % buffer_size; |
kholland | 3:4b2176f6474c | 92 | } |
kholland | 3:4b2176f6474c | 93 | return; |
kholland | 3:4b2176f6474c | 94 | } |
kholland | 3:4b2176f6474c | 95 | |
kholland | 10:5974a7b2cf38 | 96 | // Read line from the UART |
kholland | 10:5974a7b2cf38 | 97 | void read_line() |
kholland | 10:5974a7b2cf38 | 98 | { |
kholland | 3:4b2176f6474c | 99 | int i; |
kholland | 3:4b2176f6474c | 100 | i = 0; |
kholland | 3:4b2176f6474c | 101 | // Start Critical Section - don't interrupt while changing global buffer variables |
kholland | 3:4b2176f6474c | 102 | __disable_irq(); |
kholland | 3:4b2176f6474c | 103 | // Loop reading rx buffer characters until end of line character |
kholland | 3:4b2176f6474c | 104 | while ((i==0) || (rx_line[i-1] != '\n')) { |
kholland | 3:4b2176f6474c | 105 | // Wait if buffer empty |
kholland | 3:4b2176f6474c | 106 | if (rx_in == rx_out) { |
kholland | 3:4b2176f6474c | 107 | // End Critical Section - need to allow rx interrupt to get new characters for buffer |
kholland | 3:4b2176f6474c | 108 | __enable_irq(); |
kholland | 3:4b2176f6474c | 109 | while (rx_in == rx_out) { |
kholland | 3:4b2176f6474c | 110 | } |
kholland | 3:4b2176f6474c | 111 | // Start Critical Section - don't interrupt while changing global buffer variables |
kholland | 3:4b2176f6474c | 112 | __disable_irq(); |
kholland | 3:4b2176f6474c | 113 | } |
kholland | 3:4b2176f6474c | 114 | rx_line[i] = rx_buffer[rx_out]; |
kholland | 3:4b2176f6474c | 115 | i++; |
kholland | 3:4b2176f6474c | 116 | rx_out = (rx_out + 1) % buffer_size; |
kholland | 3:4b2176f6474c | 117 | } |
kholland | 3:4b2176f6474c | 118 | // End Critical Section |
kholland | 3:4b2176f6474c | 119 | __enable_irq(); |
kholland | 3:4b2176f6474c | 120 | rx_line[i-1] = 0; |
kholland | 3:4b2176f6474c | 121 | return; |
kholland | 3:4b2176f6474c | 122 | } |
kholland | 10:5974a7b2cf38 | 123 | |
kholland | 10:5974a7b2cf38 | 124 | // Wait for specific response |
GregNash | 11:78a28ca6409f | 125 | int WaitForResponse(const char *response) |
kholland | 10:5974a7b2cf38 | 126 | { |
GregNash | 11:78a28ca6409f | 127 | debug_pc.printf("Command sent. Waiting for: %s\r\n", response); |
kholland | 3:4b2176f6474c | 128 | do { |
kholland | 3:4b2176f6474c | 129 | read_line(); |
kylerodgers | 13:f827f384f0a1 | 130 | // If we get ERROR, return with 1 |
kylerodgers | 13:f827f384f0a1 | 131 | if (strncmp(rx_line, "ERROR", strlen("ERROR")) == 0) { |
kylerodgers | 13:f827f384f0a1 | 132 | debug_pc.printf("ERROR\r\n"); |
kylerodgers | 13:f827f384f0a1 | 133 | return 1; |
kylerodgers | 13:f827f384f0a1 | 134 | } |
kholland | 3:4b2176f6474c | 135 | debug_pc.printf("Waiting for: %s, Recieved: %s\r\n", response, rx_line); |
GregNash | 11:78a28ca6409f | 136 | } while (strncmp(rx_line, response, strlen(response))); |
GregNash | 11:78a28ca6409f | 137 | return 0; |
GregNash | 11:78a28ca6409f | 138 | } |
GregNash | 11:78a28ca6409f | 139 | |
kylerodgers | 13:f827f384f0a1 | 140 | // Send AT+CSQ until we get a good signal |
GregNash | 11:78a28ca6409f | 141 | int GetCSQResponse() |
GregNash | 11:78a28ca6409f | 142 | { |
GregNash | 11:78a28ca6409f | 143 | do { |
GregNash | 11:78a28ca6409f | 144 | skywire.printf("AT+CSQ\r"); |
GregNash | 11:78a28ca6409f | 145 | WaitForResponse("OK"); |
GregNash | 11:78a28ca6409f | 146 | csq[0]=rx_line[6]; |
GregNash | 11:78a28ca6409f | 147 | csq[1]=rx_line[7]; |
GregNash | 11:78a28ca6409f | 148 | csq_val=atoi(csq); |
GregNash | 11:78a28ca6409f | 149 | } while (!strncmp(rx_line, "CSQ: 99,", 8)); |
GregNash | 11:78a28ca6409f | 150 | return csq_val; |
GregNash | 11:78a28ca6409f | 151 | } |
GregNash | 11:78a28ca6409f | 152 | |
charlesxu918 | 14:44eb72d9995e | 153 | |
charlesxu918 | 14:44eb72d9995e | 154 | |
charlesxu918 | 14:44eb72d9995e | 155 | |
charlesxu918 | 14:44eb72d9995e | 156 | //LowPowerTimeout timeout; |
charlesxu918 | 14:44eb72d9995e | 157 | |
charlesxu918 | 14:44eb72d9995e | 158 | |
charlesxu918 | 14:44eb72d9995e | 159 | |
charlesxu918 | 14:44eb72d9995e | 160 | |
charlesxu918 | 14:44eb72d9995e | 161 | |
charlesxu918 | 14:44eb72d9995e | 162 | |
charlesxu918 | 14:44eb72d9995e | 163 | |
kholland | 10:5974a7b2cf38 | 164 | int main() |
kholland | 0:3095958bc639 | 165 | { |
charlesxu918 | 14:44eb72d9995e | 166 | |
charlesxu918 | 14:44eb72d9995e | 167 | |
charlesxu918 | 14:44eb72d9995e | 168 | debug_pc.baud(115200); |
charlesxu918 | 14:44eb72d9995e | 169 | /* sleep mode testing. |
charlesxu918 | 14:44eb72d9995e | 170 | |
GregNash | 11:78a28ca6409f | 171 | red_LED = 1; |
kholland | 0:3095958bc639 | 172 | float temp; |
kylerodgers | 7:00d66e743603 | 173 | float humi; |
GregNash | 11:78a28ca6409f | 174 | float photo; |
charlesxu918 | 14:44eb72d9995e | 175 | char *CSQValue; |
kholland | 0:3095958bc639 | 176 | |
kholland | 10:5974a7b2cf38 | 177 | // Setup serial comms with Skywire and PC |
kholland | 0:3095958bc639 | 178 | debug_pc.baud(115200); |
charlesxu918 | 14:44eb72d9995e | 179 | skywire.baud(115200); |
kylerodgers | 13:f827f384f0a1 | 180 | skywire_rts = 0; |
kholland | 10:5974a7b2cf38 | 181 | debug_pc.printf("SystemCoreClock = %d Hz\r\n", SystemCoreClock); |
kylerodgers | 13:f827f384f0a1 | 182 | debug_pc.printf("Attaching interrupt...\r\n"); |
kholland | 3:4b2176f6474c | 183 | skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq); |
kylerodgers | 13:f827f384f0a1 | 184 | debug_pc.printf("Interrupt attached...\r\n"); |
kholland | 10:5974a7b2cf38 | 185 | |
kylerodgers | 13:f827f384f0a1 | 186 | // Reset the Skywire to get AT commands, and recover from any previous state |
kylerodgers | 13:f827f384f0a1 | 187 | debug_pc.printf("Resetting Skywire...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 188 | nRESET = 1; |
kylerodgers | 13:f827f384f0a1 | 189 | wait_ms(100); |
kylerodgers | 13:f827f384f0a1 | 190 | nRESET = 0; |
charlesxu918 | 14:44eb72d9995e | 191 | wait(6); |
kylerodgers | 13:f827f384f0a1 | 192 | debug_pc.printf("Resetting baud...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 193 | skywire.printf("\rAT+IPR=115200\r"); |
kylerodgers | 13:f827f384f0a1 | 194 | wait_ms(100); |
kylerodgers | 13:f827f384f0a1 | 195 | skywire.baud(115200); |
kylerodgers | 13:f827f384f0a1 | 196 | wait_ms(100); |
kylerodgers | 13:f827f384f0a1 | 197 | debug_pc.printf("Baud reset!\r\n"); |
kholland | 0:3095958bc639 | 198 | myled=0; |
kholland | 3:4b2176f6474c | 199 | debug_pc.printf("Starting Demo...\r\n"); |
kholland | 3:4b2176f6474c | 200 | debug_pc.printf("Waiting for Skywire to Boot...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 201 | green_LED = !green_LED; |
kholland | 3:4b2176f6474c | 202 | myled=1; |
charlesxu918 | 14:44eb72d9995e | 203 | //wait(120); |
kholland | 10:5974a7b2cf38 | 204 | |
charlesxu918 | 14:44eb72d9995e | 205 | |
charlesxu918 | 14:44eb72d9995e | 206 | // Make them comments for debugging: |
kylerodgers | 13:f827f384f0a1 | 207 | debug_pc.printf("Sending AT\r\n"); |
kylerodgers | 13:f827f384f0a1 | 208 | skywire.printf("\rAT\r"); |
GregNash | 11:78a28ca6409f | 209 | WaitForResponse("OK"); |
charlesxu918 | 14:44eb72d9995e | 210 | //WaitForResponse("+CEREG: 1"); |
charlesxu918 | 14:44eb72d9995e | 211 | debug_pc.printf("Sending AT+CFUN=1\r\n"); |
charlesxu918 | 14:44eb72d9995e | 212 | skywire.printf("AT+CFUN=1\r"); |
charlesxu918 | 14:44eb72d9995e | 213 | WaitForResponse("OK"); |
charlesxu918 | 14:44eb72d9995e | 214 | //wait_ms(2000); |
charlesxu918 | 14:44eb72d9995e | 215 | |
kylerodgers | 13:f827f384f0a1 | 216 | // Check CSQ |
GregNash | 11:78a28ca6409f | 217 | debug_pc.printf("Getting CSQ...\r\n"); |
GregNash | 11:78a28ca6409f | 218 | GetCSQResponse(); |
kylerodgers | 13:f827f384f0a1 | 219 | green_LED = !green_LED; |
GregNash | 11:78a28ca6409f | 220 | while(csq_val==99 || csq_val==0) |
GregNash | 11:78a28ca6409f | 221 | { |
GregNash | 11:78a28ca6409f | 222 | |
GregNash | 11:78a28ca6409f | 223 | debug_pc.printf("CSQ Value: %i\r\n",csq_val); |
GregNash | 11:78a28ca6409f | 224 | debug_pc.printf("No network sginal detected. \r\n"); |
GregNash | 11:78a28ca6409f | 225 | debug_pc.printf("Waiting for device to connect to the network. \r\n"); |
GregNash | 11:78a28ca6409f | 226 | debug_pc.printf("Please check antenna connections if network is not found after 30 seconds. \r\n"); |
GregNash | 11:78a28ca6409f | 227 | wait(1); |
GregNash | 11:78a28ca6409f | 228 | //add elapsed time |
GregNash | 11:78a28ca6409f | 229 | debug_pc.printf("Checking network connectrion. \r\n"); |
GregNash | 11:78a28ca6409f | 230 | GetCSQResponse(); |
GregNash | 11:78a28ca6409f | 231 | red_LED = !red_LED; |
GregNash | 11:78a28ca6409f | 232 | } |
GregNash | 11:78a28ca6409f | 233 | |
GregNash | 11:78a28ca6409f | 234 | debug_pc.printf("Network detected. Checking authorization...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 235 | skywire.printf("AT+CEREG?\r"); |
GregNash | 11:78a28ca6409f | 236 | WaitForResponse("OK"); |
kylerodgers | 7:00d66e743603 | 237 | |
kylerodgers | 13:f827f384f0a1 | 238 | //debug_pc.printf("Connecting to Network...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 239 | debug_pc.printf("Setting up socket...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 240 | skywire.printf("AT+SQNSCFG=3,3,300,90,600,50\r"); |
kylerodgers | 13:f827f384f0a1 | 241 | WaitForResponse("OK"); |
kholland | 10:5974a7b2cf38 | 242 | |
GregNash | 11:78a28ca6409f | 243 | red_LED = 1; |
GregNash | 11:78a28ca6409f | 244 | green_LED = 0; |
GregNash | 11:78a28ca6409f | 245 | |
charlesxu918 | 14:44eb72d9995e | 246 | |
charlesxu918 | 14:44eb72d9995e | 247 | debug_pc.printf("Check Version...\r\n"); |
charlesxu918 | 14:44eb72d9995e | 248 | skywire.printf("ATI1\r"); |
charlesxu918 | 14:44eb72d9995e | 249 | WaitForResponse("OK"); |
charlesxu918 | 14:44eb72d9995e | 250 | |
charlesxu918 | 14:44eb72d9995e | 251 | |
charlesxu918 | 14:44eb72d9995e | 252 | |
charlesxu918 | 14:44eb72d9995e | 253 | ////////////////Added on April 18, 2018 |
charlesxu918 | 14:44eb72d9995e | 254 | |
charlesxu918 | 14:44eb72d9995e | 255 | SPI spi(PB_15, PB_14,PB_13); // mosi, miso, sclk |
charlesxu918 | 14:44eb72d9995e | 256 | DigitalOut cs(PB_12); |
charlesxu918 | 14:44eb72d9995e | 257 | |
charlesxu918 | 14:44eb72d9995e | 258 | // Select the device by setting chip select low |
charlesxu918 | 14:44eb72d9995e | 259 | cs = 0; |
charlesxu918 | 14:44eb72d9995e | 260 | |
charlesxu918 | 14:44eb72d9995e | 261 | // Send 0x8f, the command to read the WHOAMI register |
charlesxu918 | 14:44eb72d9995e | 262 | //spi.write(0x80); |
charlesxu918 | 14:44eb72d9995e | 263 | |
charlesxu918 | 14:44eb72d9995e | 264 | // Send a dummy byte to receive the contents of the WHOAMI register |
charlesxu918 | 14:44eb72d9995e | 265 | long whoami = spi.write(0x80); |
charlesxu918 | 14:44eb72d9995e | 266 | |
charlesxu918 | 14:44eb72d9995e | 267 | debug_pc.printf("Read SPI information...\r\n"); |
charlesxu918 | 14:44eb72d9995e | 268 | debug_pc.printf("SPI Value: %i\r\n",whoami ); |
charlesxu918 | 14:44eb72d9995e | 269 | long whoami1 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 270 | debug_pc.printf("SPI Value: %i\r\n",whoami1 ); |
charlesxu918 | 14:44eb72d9995e | 271 | long whoami2 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 272 | debug_pc.printf("SPI Value: %i\r\n",whoami2 ); |
charlesxu918 | 14:44eb72d9995e | 273 | long whoami3 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 274 | debug_pc.printf("SPI Value: %i\r\n",whoami3 ); |
charlesxu918 | 14:44eb72d9995e | 275 | long whoami4 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 276 | debug_pc.printf("SPI Value: %i\r\n",whoami4 ); |
charlesxu918 | 14:44eb72d9995e | 277 | |
charlesxu918 | 14:44eb72d9995e | 278 | // Deselect the device |
charlesxu918 | 14:44eb72d9995e | 279 | cs = 1; |
charlesxu918 | 14:44eb72d9995e | 280 | //// Added on April 18, 2018 |
charlesxu918 | 14:44eb72d9995e | 281 | |
charlesxu918 | 14:44eb72d9995e | 282 | wait_ms(100); |
charlesxu918 | 14:44eb72d9995e | 283 | |
charlesxu918 | 14:44eb72d9995e | 284 | |
charlesxu918 | 14:44eb72d9995e | 285 | |
kholland | 0:3095958bc639 | 286 | while(1) { |
kholland | 10:5974a7b2cf38 | 287 | // Green on to indicate code position |
kholland | 10:5974a7b2cf38 | 288 | // Start of loop. Either entered loop for the first time or just sent to dweet.io |
kholland | 10:5974a7b2cf38 | 289 | red_LED = 0; |
kholland | 10:5974a7b2cf38 | 290 | green_LED = 1; |
charlesxu918 | 14:44eb72d9995e | 291 | //* Comments for debugging |
kylerodgers | 13:f827f384f0a1 | 292 | int retries = 0; |
kylerodgers | 13:f827f384f0a1 | 293 | while (retries < 5) { |
charlesxu918 | 14:44eb72d9995e | 294 | //skywire.printf("AT+SQNSD=3,0,80,\"dweet.io\"\r"); |
charlesxu918 | 14:44eb72d9995e | 295 | skywire.printf("AT+SQNSD=3,0,59001,\"12.193.202.234\"\r"); |
charlesxu918 | 14:44eb72d9995e | 296 | //skywire.printf("AT+SQNSD=3,0,60001,\"<12.25.92.72>\"\r"); |
kylerodgers | 13:f827f384f0a1 | 297 | if (WaitForResponse("CONNECT") == 1) { |
kylerodgers | 13:f827f384f0a1 | 298 | retries += 1; |
kylerodgers | 13:f827f384f0a1 | 299 | wait(1); |
kylerodgers | 13:f827f384f0a1 | 300 | } else |
kylerodgers | 13:f827f384f0a1 | 301 | break; |
GregNash | 11:78a28ca6409f | 302 | } |
kylerodgers | 13:f827f384f0a1 | 303 | |
charlesxu918 | 14:44eb72d9995e | 304 | //*/ |
charlesxu918 | 14:44eb72d9995e | 305 | |
charlesxu918 | 14:44eb72d9995e | 306 | |
charlesxu918 | 14:44eb72d9995e | 307 | |
charlesxu918 | 14:44eb72d9995e | 308 | /* sleep mode testing. |
charlesxu918 | 14:44eb72d9995e | 309 | |
charlesxu918 | 14:44eb72d9995e | 310 | |
kylerodgers | 13:f827f384f0a1 | 311 | //get temp and humi |
GregNash | 11:78a28ca6409f | 312 | temp=SHT30.cTemp(); |
GregNash | 11:78a28ca6409f | 313 | humi=SHT30.humidity(); |
GregNash | 11:78a28ca6409f | 314 | photo_trans_nEN=0; |
GregNash | 11:78a28ca6409f | 315 | photo=photo_trans*200; |
charlesxu918 | 14:44eb72d9995e | 316 | |
charlesxu918 | 14:44eb72d9995e | 317 | |
charlesxu918 | 14:44eb72d9995e | 318 | |
charlesxu918 | 14:44eb72d9995e | 319 | //humi=csq_val; |
kholland | 10:5974a7b2cf38 | 320 | wait(1); |
charlesxu918 | 14:44eb72d9995e | 321 | |
charlesxu918 | 14:44eb72d9995e | 322 | |
charlesxu918 | 14:44eb72d9995e | 323 | // SPI Reading Procedure Added on April 18 2018 |
charlesxu918 | 14:44eb72d9995e | 324 | wait(2); |
charlesxu918 | 14:44eb72d9995e | 325 | // Select the device by setting chip select low |
charlesxu918 | 14:44eb72d9995e | 326 | cs = 0; |
charlesxu918 | 14:44eb72d9995e | 327 | |
charlesxu918 | 14:44eb72d9995e | 328 | // Send a dummy byte to receive the contents of the WHOAMI register |
charlesxu918 | 14:44eb72d9995e | 329 | char whoami = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 330 | |
charlesxu918 | 14:44eb72d9995e | 331 | debug_pc.printf("Read SPI information...\r\n"); |
charlesxu918 | 14:44eb72d9995e | 332 | debug_pc.printf("SPI Value: %i\r\n",whoami ); |
charlesxu918 | 14:44eb72d9995e | 333 | |
charlesxu918 | 14:44eb72d9995e | 334 | //long whoami1 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 335 | char whoami1 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 336 | debug_pc.printf("SPI Value: %i\r\n",whoami1 ); |
charlesxu918 | 14:44eb72d9995e | 337 | char whoami2 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 338 | debug_pc.printf("SPI Value: %i\r\n",whoami2 ); |
charlesxu918 | 14:44eb72d9995e | 339 | char whoami3 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 340 | debug_pc.printf("SPI Value: %i\r\n",whoami3 ); |
charlesxu918 | 14:44eb72d9995e | 341 | char whoami4 = spi.write(0x00); |
charlesxu918 | 14:44eb72d9995e | 342 | debug_pc.printf("SPI Value: %i\r\n",whoami4 ); |
charlesxu918 | 14:44eb72d9995e | 343 | |
charlesxu918 | 14:44eb72d9995e | 344 | photo=whoami1/14.5; |
charlesxu918 | 14:44eb72d9995e | 345 | |
charlesxu918 | 14:44eb72d9995e | 346 | unsigned char mask=1<<5; |
charlesxu918 | 14:44eb72d9995e | 347 | int sign=mask&whoami; |
charlesxu918 | 14:44eb72d9995e | 348 | |
charlesxu918 | 14:44eb72d9995e | 349 | long tempLong1=0; |
charlesxu918 | 14:44eb72d9995e | 350 | long tempLong2=0; |
charlesxu918 | 14:44eb72d9995e | 351 | long tempLong3=0; |
charlesxu918 | 14:44eb72d9995e | 352 | long tempLong4=0; |
charlesxu918 | 14:44eb72d9995e | 353 | |
charlesxu918 | 14:44eb72d9995e | 354 | char tempChar; |
charlesxu918 | 14:44eb72d9995e | 355 | long convertedResults=0;// converted results |
charlesxu918 | 14:44eb72d9995e | 356 | |
charlesxu918 | 14:44eb72d9995e | 357 | float output; |
charlesxu918 | 14:44eb72d9995e | 358 | |
charlesxu918 | 14:44eb72d9995e | 359 | if (sign==0) // negative readings: |
charlesxu918 | 14:44eb72d9995e | 360 | { |
charlesxu918 | 14:44eb72d9995e | 361 | |
charlesxu918 | 14:44eb72d9995e | 362 | tempChar=whoami; |
charlesxu918 | 14:44eb72d9995e | 363 | tempChar=tempChar<<3; |
charlesxu918 | 14:44eb72d9995e | 364 | tempChar=tempChar>>3; |
charlesxu918 | 14:44eb72d9995e | 365 | debug_pc.printf("test1 Value is: %i\r\n", tempChar ); |
charlesxu918 | 14:44eb72d9995e | 366 | |
charlesxu918 | 14:44eb72d9995e | 367 | tempLong1=tempLong1|tempChar; |
charlesxu918 | 14:44eb72d9995e | 368 | debug_pc.printf("test2 Value is: %i\r\n", tempLong1 ); |
charlesxu918 | 14:44eb72d9995e | 369 | |
charlesxu918 | 14:44eb72d9995e | 370 | tempLong1=tempLong1<<24; |
charlesxu918 | 14:44eb72d9995e | 371 | debug_pc.printf("test3 Value is: %i\r\n", tempLong1 ); |
charlesxu918 | 14:44eb72d9995e | 372 | |
charlesxu918 | 14:44eb72d9995e | 373 | |
charlesxu918 | 14:44eb72d9995e | 374 | tempChar=whoami1; |
charlesxu918 | 14:44eb72d9995e | 375 | tempLong2=tempLong2|tempChar; |
charlesxu918 | 14:44eb72d9995e | 376 | tempLong2=tempLong2<<16; |
charlesxu918 | 14:44eb72d9995e | 377 | |
charlesxu918 | 14:44eb72d9995e | 378 | tempChar=whoami2; |
charlesxu918 | 14:44eb72d9995e | 379 | tempLong3=tempLong3|tempChar; |
charlesxu918 | 14:44eb72d9995e | 380 | tempLong3=tempLong3<<8; |
charlesxu918 | 14:44eb72d9995e | 381 | |
charlesxu918 | 14:44eb72d9995e | 382 | tempChar=whoami3; |
charlesxu918 | 14:44eb72d9995e | 383 | tempChar=tempChar>>5; |
charlesxu918 | 14:44eb72d9995e | 384 | tempChar=tempChar<<5; |
charlesxu918 | 14:44eb72d9995e | 385 | tempLong4=tempLong4&tempChar; |
charlesxu918 | 14:44eb72d9995e | 386 | |
charlesxu918 | 14:44eb72d9995e | 387 | convertedResults=tempLong1|tempLong2|tempLong3|tempLong4; |
charlesxu918 | 14:44eb72d9995e | 388 | convertedResults=~ convertedResults; |
charlesxu918 | 14:44eb72d9995e | 389 | convertedResults=convertedResults<<3; |
charlesxu918 | 14:44eb72d9995e | 390 | convertedResults=convertedResults>>3; |
charlesxu918 | 14:44eb72d9995e | 391 | convertedResults= convertedResults>>5; |
charlesxu918 | 14:44eb72d9995e | 392 | |
charlesxu918 | 14:44eb72d9995e | 393 | |
charlesxu918 | 14:44eb72d9995e | 394 | |
charlesxu918 | 14:44eb72d9995e | 395 | debug_pc.printf("Long1 Value is: %i\r\n", tempLong1 ); |
charlesxu918 | 14:44eb72d9995e | 396 | debug_pc.printf("Long2 Value is: %i\r\n", tempLong2 ); |
charlesxu918 | 14:44eb72d9995e | 397 | debug_pc.printf("Long3 Value is: %i\r\n", tempLong3 ); |
charlesxu918 | 14:44eb72d9995e | 398 | debug_pc.printf("Long4 Value is: %i\r\n", tempLong4 ); |
charlesxu918 | 14:44eb72d9995e | 399 | |
charlesxu918 | 14:44eb72d9995e | 400 | output = -convertedResults*0.0000120; |
charlesxu918 | 14:44eb72d9995e | 401 | |
charlesxu918 | 14:44eb72d9995e | 402 | |
charlesxu918 | 14:44eb72d9995e | 403 | |
charlesxu918 | 14:44eb72d9995e | 404 | } |
charlesxu918 | 14:44eb72d9995e | 405 | else // positive readings: |
charlesxu918 | 14:44eb72d9995e | 406 | { |
charlesxu918 | 14:44eb72d9995e | 407 | tempChar=whoami; |
charlesxu918 | 14:44eb72d9995e | 408 | tempChar=tempChar<<3; |
charlesxu918 | 14:44eb72d9995e | 409 | tempChar=tempChar>>3; |
charlesxu918 | 14:44eb72d9995e | 410 | debug_pc.printf("test1 Value is: %i\r\n", tempChar ); |
charlesxu918 | 14:44eb72d9995e | 411 | |
charlesxu918 | 14:44eb72d9995e | 412 | tempLong1=tempLong1|tempChar; |
charlesxu918 | 14:44eb72d9995e | 413 | debug_pc.printf("test2 Value is: %i\r\n", tempLong1 ); |
charlesxu918 | 14:44eb72d9995e | 414 | |
charlesxu918 | 14:44eb72d9995e | 415 | tempLong1=tempLong1<<24; |
charlesxu918 | 14:44eb72d9995e | 416 | debug_pc.printf("test3 Value is: %i\r\n", tempLong1 ); |
charlesxu918 | 14:44eb72d9995e | 417 | |
charlesxu918 | 14:44eb72d9995e | 418 | |
charlesxu918 | 14:44eb72d9995e | 419 | tempChar=whoami1; |
charlesxu918 | 14:44eb72d9995e | 420 | tempLong2=tempLong2|tempChar; |
charlesxu918 | 14:44eb72d9995e | 421 | tempLong2=tempLong2<<16; |
charlesxu918 | 14:44eb72d9995e | 422 | |
charlesxu918 | 14:44eb72d9995e | 423 | tempChar=whoami2; |
charlesxu918 | 14:44eb72d9995e | 424 | tempLong3=tempLong3|tempChar; |
charlesxu918 | 14:44eb72d9995e | 425 | tempLong3=tempLong3<<8; |
charlesxu918 | 14:44eb72d9995e | 426 | |
charlesxu918 | 14:44eb72d9995e | 427 | tempChar=whoami3; |
charlesxu918 | 14:44eb72d9995e | 428 | tempChar=tempChar>>5; |
charlesxu918 | 14:44eb72d9995e | 429 | tempChar=tempChar<<5; |
charlesxu918 | 14:44eb72d9995e | 430 | tempLong4=tempLong4&tempChar; |
charlesxu918 | 14:44eb72d9995e | 431 | |
charlesxu918 | 14:44eb72d9995e | 432 | convertedResults=tempLong1|tempLong2|tempLong3|tempLong4; |
charlesxu918 | 14:44eb72d9995e | 433 | convertedResults= convertedResults>>5; |
charlesxu918 | 14:44eb72d9995e | 434 | |
charlesxu918 | 14:44eb72d9995e | 435 | |
charlesxu918 | 14:44eb72d9995e | 436 | |
charlesxu918 | 14:44eb72d9995e | 437 | debug_pc.printf("Long1 Value is: %i\r\n", tempLong1 ); |
charlesxu918 | 14:44eb72d9995e | 438 | debug_pc.printf("Long2 Value is: %i\r\n", tempLong2 ); |
charlesxu918 | 14:44eb72d9995e | 439 | debug_pc.printf("Long3 Value is: %i\r\n", tempLong3 ); |
charlesxu918 | 14:44eb72d9995e | 440 | debug_pc.printf("Long4 Value is: %i\r\n", tempLong4 ); |
charlesxu918 | 14:44eb72d9995e | 441 | output = convertedResults*0.0000120; |
charlesxu918 | 14:44eb72d9995e | 442 | } |
charlesxu918 | 14:44eb72d9995e | 443 | |
charlesxu918 | 14:44eb72d9995e | 444 | |
charlesxu918 | 14:44eb72d9995e | 445 | debug_pc.printf("Measured Value Sign is: %i\r\n",sign ); |
charlesxu918 | 14:44eb72d9995e | 446 | |
charlesxu918 | 14:44eb72d9995e | 447 | |
charlesxu918 | 14:44eb72d9995e | 448 | debug_pc.printf("Converted Value is: %i\r\n", convertedResults ); |
charlesxu918 | 14:44eb72d9995e | 449 | debug_pc.printf("Converted True Value is: %f\r\n", output ); |
charlesxu918 | 14:44eb72d9995e | 450 | |
charlesxu918 | 14:44eb72d9995e | 451 | |
charlesxu918 | 14:44eb72d9995e | 452 | // Deselect the device |
charlesxu918 | 14:44eb72d9995e | 453 | |
charlesxu918 | 14:44eb72d9995e | 454 | |
charlesxu918 | 14:44eb72d9995e | 455 | cs = 1; |
charlesxu918 | 14:44eb72d9995e | 456 | //// End of SPI Reading Procedure Added on April 18, 2018 |
charlesxu918 | 14:44eb72d9995e | 457 | |
charlesxu918 | 14:44eb72d9995e | 458 | |
charlesxu918 | 14:44eb72d9995e | 459 | |
charlesxu918 | 14:44eb72d9995e | 460 | |
charlesxu918 | 14:44eb72d9995e | 461 | |
charlesxu918 | 14:44eb72d9995e | 462 | wait(2); |
charlesxu918 | 14:44eb72d9995e | 463 | |
charlesxu918 | 14:44eb72d9995e | 464 | |
kholland | 10:5974a7b2cf38 | 465 | |
kholland | 10:5974a7b2cf38 | 466 | // Check buttons for presses |
kholland | 10:5974a7b2cf38 | 467 | if (button1 == 0) |
kylerodgers | 13:f827f384f0a1 | 468 | sw1 = 1; |
kholland | 10:5974a7b2cf38 | 469 | else |
kylerodgers | 13:f827f384f0a1 | 470 | sw1 = 0; |
kholland | 3:4b2176f6474c | 471 | |
kholland | 10:5974a7b2cf38 | 472 | // Green on to indicate code position: |
kholland | 10:5974a7b2cf38 | 473 | // Sensors updated, have not sent to dweet.io |
kholland | 10:5974a7b2cf38 | 474 | red_LED = 1; |
kholland | 10:5974a7b2cf38 | 475 | green_LED = 0; |
charlesxu918 | 14:44eb72d9995e | 476 | |
charlesxu918 | 14:44eb72d9995e | 477 | // /* |
charlesxu918 | 14:44eb72d9995e | 478 | photo=output; |
charlesxu918 | 14:44eb72d9995e | 479 | float para1; |
charlesxu918 | 14:44eb72d9995e | 480 | float para2; |
charlesxu918 | 14:44eb72d9995e | 481 | float para3; |
charlesxu918 | 14:44eb72d9995e | 482 | float para4; |
charlesxu918 | 14:44eb72d9995e | 483 | float para5; |
charlesxu918 | 14:44eb72d9995e | 484 | float para6; |
charlesxu918 | 14:44eb72d9995e | 485 | float para7; |
charlesxu918 | 14:44eb72d9995e | 486 | float para8; |
charlesxu918 | 14:44eb72d9995e | 487 | float para9; |
charlesxu918 | 14:44eb72d9995e | 488 | float para10; |
charlesxu918 | 14:44eb72d9995e | 489 | float para11; |
charlesxu918 | 14:44eb72d9995e | 490 | para1=csq_val; |
charlesxu918 | 14:44eb72d9995e | 491 | para2=temp/1.4; |
charlesxu918 | 14:44eb72d9995e | 492 | para3=output; |
charlesxu918 | 14:44eb72d9995e | 493 | para4=humi; |
charlesxu918 | 14:44eb72d9995e | 494 | para5=0; |
charlesxu918 | 14:44eb72d9995e | 495 | para6=0; |
charlesxu918 | 14:44eb72d9995e | 496 | para7=0; |
charlesxu918 | 14:44eb72d9995e | 497 | para8=0; |
charlesxu918 | 14:44eb72d9995e | 498 | para9=0; |
charlesxu918 | 14:44eb72d9995e | 499 | para10=0; |
charlesxu918 | 14:44eb72d9995e | 500 | para11=0; |
kylerodgers | 13:f827f384f0a1 | 501 | if (retries != 5) { |
GregNash | 11:78a28ca6409f | 502 | debug_pc.printf("Sending information...\r\n"); |
GregNash | 11:78a28ca6409f | 503 | // Report the sensor data to dweet.io |
charlesxu918 | 14:44eb72d9995e | 504 | //skywire.printf("POST /dweet/for/%s?temp=%.3f&sw1=%d&photo=%.3f&CSQ=%.3f HTTP/1.0\r\n\r\n", DeviceID, temp, sw1, photo, humi); |
charlesxu918 | 14:44eb72d9995e | 505 | //skywire.printf("POST %s,%.3f,%.3f,%.3f,%.3f HTTP/1.0\r\n\r\n", DeviceID, temp, sw1, photo, humi); |
charlesxu918 | 14:44eb72d9995e | 506 | skywire.printf("%s,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f \r\n\r\n", DeviceID, para1, para2, para3, para4,para5,para6,para7,para8,para9,para10,para11); |
GregNash | 11:78a28ca6409f | 507 | WaitForResponse("NO CARRIER"); |
kylerodgers | 13:f827f384f0a1 | 508 | } |
kylerodgers | 13:f827f384f0a1 | 509 | // } |
kylerodgers | 13:f827f384f0a1 | 510 | debug_pc.printf("Closing socket...\r\n"); |
kylerodgers | 13:f827f384f0a1 | 511 | skywire.printf("AT+SQNSH=3\r"); |
kylerodgers | 13:f827f384f0a1 | 512 | WaitForResponse("OK"); |
charlesxu918 | 14:44eb72d9995e | 513 | wait(2); |
kylerodgers | 13:f827f384f0a1 | 514 | skywire.printf("AT+CGATT=0\r"); |
kylerodgers | 13:f827f384f0a1 | 515 | WaitForResponse("OK"); |
charlesxu918 | 14:44eb72d9995e | 516 | wait(2); |
kylerodgers | 13:f827f384f0a1 | 517 | skywire.printf("AT+CGATT=1\r"); |
kylerodgers | 13:f827f384f0a1 | 518 | WaitForResponse("+CEREG: 1"); |
charlesxu918 | 14:44eb72d9995e | 519 | wait(2); |
kholland | 10:5974a7b2cf38 | 520 | red_LED = 0; |
GregNash | 11:78a28ca6409f | 521 | green_LED = 1; |
charlesxu918 | 14:44eb72d9995e | 522 | |
charlesxu918 | 14:44eb72d9995e | 523 | wait(3); |
charlesxu918 | 14:44eb72d9995e | 524 | skywire.printf("AT+CSQ\r"); |
charlesxu918 | 14:44eb72d9995e | 525 | WaitForResponse("OK"); |
charlesxu918 | 14:44eb72d9995e | 526 | csq[0]=rx_line[6]; |
charlesxu918 | 14:44eb72d9995e | 527 | csq[1]=rx_line[7]; |
charlesxu918 | 14:44eb72d9995e | 528 | csq_val=atoi(csq); |
charlesxu918 | 14:44eb72d9995e | 529 | wait(6); |
charlesxu918 | 14:44eb72d9995e | 530 | |
charlesxu918 | 14:44eb72d9995e | 531 | // sleeping testing |
charlesxu918 | 14:44eb72d9995e | 532 | |
charlesxu918 | 14:44eb72d9995e | 533 | |
charlesxu918 | 14:44eb72d9995e | 534 | // after data sending: |
charlesxu918 | 14:44eb72d9995e | 535 | |
charlesxu918 | 14:44eb72d9995e | 536 | */ //Sleep mode testing |
charlesxu918 | 14:44eb72d9995e | 537 | |
charlesxu918 | 14:44eb72d9995e | 538 | |
charlesxu918 | 14:44eb72d9995e | 539 | |
charlesxu918 | 14:44eb72d9995e | 540 | |
charlesxu918 | 14:44eb72d9995e | 541 | |
charlesxu918 | 14:44eb72d9995e | 542 | |
charlesxu918 | 14:44eb72d9995e | 543 | wait(5); |
charlesxu918 | 14:44eb72d9995e | 544 | |
charlesxu918 | 14:44eb72d9995e | 545 | //The low-power oscillator can be quite inaccurate on some targets |
charlesxu918 | 14:44eb72d9995e | 546 | //this function calibrates it against the main clock |
charlesxu918 | 14:44eb72d9995e | 547 | WakeUp::calibrate(); |
charlesxu918 | 14:44eb72d9995e | 548 | |
charlesxu918 | 14:44eb72d9995e | 549 | |
charlesxu918 | 14:44eb72d9995e | 550 | while(1) { |
charlesxu918 | 14:44eb72d9995e | 551 | //Set LED to zero |
charlesxu918 | 14:44eb72d9995e | 552 | red_LED = 0; |
charlesxu918 | 14:44eb72d9995e | 553 | green_LED = 1; |
charlesxu918 | 14:44eb72d9995e | 554 | //Set wakeup time for 2 seconds |
charlesxu918 | 14:44eb72d9995e | 555 | WakeUp::set_ms(2000); |
charlesxu918 | 14:44eb72d9995e | 556 | |
charlesxu918 | 14:44eb72d9995e | 557 | //Enter deepsleep, the program won't go beyond this point until it is woken up |
charlesxu918 | 14:44eb72d9995e | 558 | deepsleep(); |
charlesxu918 | 14:44eb72d9995e | 559 | |
charlesxu918 | 14:44eb72d9995e | 560 | //Set LED for 1 second to one |
charlesxu918 | 14:44eb72d9995e | 561 | red_LED = 1; |
charlesxu918 | 14:44eb72d9995e | 562 | green_LED = 0; |
charlesxu918 | 14:44eb72d9995e | 563 | wait(1); |
charlesxu918 | 14:44eb72d9995e | 564 | } |
charlesxu918 | 14:44eb72d9995e | 565 | |
charlesxu918 | 14:44eb72d9995e | 566 | |
charlesxu918 | 14:44eb72d9995e | 567 | |
charlesxu918 | 14:44eb72d9995e | 568 | |
charlesxu918 | 14:44eb72d9995e | 569 | |
charlesxu918 | 14:44eb72d9995e | 570 | |
charlesxu918 | 14:44eb72d9995e | 571 | |
charlesxu918 | 14:44eb72d9995e | 572 | // End of sleeping, get back to work |
charlesxu918 | 14:44eb72d9995e | 573 | |
charlesxu918 | 14:44eb72d9995e | 574 | |
charlesxu918 | 14:44eb72d9995e | 575 | |
charlesxu918 | 14:44eb72d9995e | 576 | |
charlesxu918 | 14:44eb72d9995e | 577 | |
charlesxu918 | 14:44eb72d9995e | 578 | |
charlesxu918 | 14:44eb72d9995e | 579 | |
charlesxu918 | 14:44eb72d9995e | 580 | |
GregNash | 11:78a28ca6409f | 581 | } |