![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
basic lightning detector with gps and sd card logging
Dependencies: AS3935 AdafruitGPS SDFileSystem TSI mbed ConfigFile
main.cpp@3:e3974328d808, 2015-06-24 (annotated)
- Committer:
- ftagius
- Date:
- Wed Jun 24 12:37:31 2015 +0000
- Revision:
- 3:e3974328d808
- Parent:
- 2:3edb129c60b2
- Child:
- 4:4d26ba1ae0f7
move the sd card logging out of the isr. it appears if we spend too much time in the isr, the device can hang when interrupts occur in quick succession.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ftagius | 0:3328df4c3116 | 1 | #include "mbed.h" |
ftagius | 0:3328df4c3116 | 2 | #include "GPS.h" |
ftagius | 0:3328df4c3116 | 3 | #include "main.h" |
ftagius | 0:3328df4c3116 | 4 | #include "TSISensor.h" |
ftagius | 0:3328df4c3116 | 5 | #include "SDFileSystem.h" |
ftagius | 0:3328df4c3116 | 6 | #include "AS3935.h" |
ftagius | 0:3328df4c3116 | 7 | |
ftagius | 3:e3974328d808 | 8 | // frdm-kl25z as3935 connections for spi1 |
ftagius | 0:3328df4c3116 | 9 | // ------------------------------------------------ |
ftagius | 0:3328df4c3116 | 10 | // Header -- kl25z -- SD/MMC |
ftagius | 0:3328df4c3116 | 11 | // J2-20 -- PTE1 -- MOSI |
ftagius | 0:3328df4c3116 | 12 | // J9-13 -- PTE4 -- CS |
ftagius | 0:3328df4c3116 | 13 | // J2-14 -- GND -- Vss (GND) |
ftagius | 0:3328df4c3116 | 14 | // J9-9 -- PTE2 -- SCK |
ftagius | 0:3328df4c3116 | 15 | // J9-11 -- PTE3 -- MISO |
ftagius | 0:3328df4c3116 | 16 | |
ftagius | 0:3328df4c3116 | 17 | AS3935 ld(PTE1, PTE3, PTE2, PTE4, "ld", 1000000); // MOSI, MISO, SCK, CS, SPI bus freq (hz) |
ftagius | 0:3328df4c3116 | 18 | InterruptIn IntLightning(PTA12); //IRQ AS3935 |
ftagius | 0:3328df4c3116 | 19 | |
ftagius | 0:3328df4c3116 | 20 | |
ftagius | 0:3328df4c3116 | 21 | // frdm-kl25z sd card connections spi0 |
ftagius | 0:3328df4c3116 | 22 | // ------------------------------------------------ |
ftagius | 0:3328df4c3116 | 23 | // Header -- kl25z -- SPI |
ftagius | 0:3328df4c3116 | 24 | // J2-8 -- PTD2 -- MOSI |
ftagius | 0:3328df4c3116 | 25 | // J2-6 -- PTD0 -- CS |
ftagius | 0:3328df4c3116 | 26 | // J9-12 -- GND -- Vss (GND) |
ftagius | 0:3328df4c3116 | 27 | // J9-4 -- P3V3 -- Vdd (+3.3v) |
ftagius | 0:3328df4c3116 | 28 | // J2-12 -- PTD1 -- SCK |
ftagius | 0:3328df4c3116 | 29 | // J9-14 -- GND -- Vss (GND) |
ftagius | 0:3328df4c3116 | 30 | // J2-10 -- PTD3 -- MISO |
ftagius | 0:3328df4c3116 | 31 | |
ftagius | 0:3328df4c3116 | 32 | SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); // MOSI, MISO, SCK, CS |
ftagius | 0:3328df4c3116 | 33 | |
ftagius | 0:3328df4c3116 | 34 | Serial pc(USBTX, USBRX); |
ftagius | 0:3328df4c3116 | 35 | GPS gpsd(PTE20, PTE21); |
ftagius | 0:3328df4c3116 | 36 | DigitalOut red(LED_RED); |
ftagius | 0:3328df4c3116 | 37 | DigitalOut green(LED_GREEN); |
ftagius | 0:3328df4c3116 | 38 | //DigitalOut blue(LED_BLUE); don't use the blue led, due to a board error, writing to the blue led kills spi |
ftagius | 3:e3974328d808 | 39 | bool debug=false; |
ftagius | 0:3328df4c3116 | 40 | int day, month,year,hour,minute,seconds; |
cmkachur | 2:3edb129c60b2 | 41 | void writeLogFile(int interruptSource, int distance, long energy); |
ftagius | 1:10d2a051285e | 42 | char logName[]="lightning_data.csv"; |
ftagius | 1:10d2a051285e | 43 | int rdistance, rinterrupt; |
ftagius | 1:10d2a051285e | 44 | char directory[]="/sd/lightning_data"; |
ftagius | 3:e3974328d808 | 45 | int OriginInt=-1; |
ftagius | 3:e3974328d808 | 46 | int distance=-1; |
ftagius | 3:e3974328d808 | 47 | long energy=-1; |
ftagius | 0:3328df4c3116 | 48 | |
ftagius | 0:3328df4c3116 | 49 | void DetectLightning() |
ftagius | 0:3328df4c3116 | 50 | { |
ftagius | 0:3328df4c3116 | 51 | OriginInt = ld.interruptSource(); |
ftagius | 3:e3974328d808 | 52 | distance = ld.lightningDistanceKm(); |
ftagius | 3:e3974328d808 | 53 | energy = ld.getEnergy(); |
ftagius | 0:3328df4c3116 | 54 | } |
ftagius | 0:3328df4c3116 | 55 | |
cmkachur | 2:3edb129c60b2 | 56 | void writeLogFile(int interruptSource, int distance, long energy) |
ftagius | 0:3328df4c3116 | 57 | { |
ftagius | 1:10d2a051285e | 58 | char logFilePath[128]; |
ftagius | 0:3328df4c3116 | 59 | static bool header=false; |
ftagius | 0:3328df4c3116 | 60 | FILE *fp; |
ftagius | 1:10d2a051285e | 61 | |
ftagius | 1:10d2a051285e | 62 | sprintf(logFilePath, "%s/%s", directory,logName); |
ftagius | 0:3328df4c3116 | 63 | sd.mount(); |
ftagius | 1:10d2a051285e | 64 | fp = fopen(logFilePath, "a"); |
ftagius | 0:3328df4c3116 | 65 | if(fp == NULL) { |
ftagius | 0:3328df4c3116 | 66 | // retry |
ftagius | 3:e3974328d808 | 67 | wait_ms(200); |
ftagius | 1:10d2a051285e | 68 | fp = fopen(logFilePath, "a"); |
ftagius | 0:3328df4c3116 | 69 | if (fp == NULL) |
ftagius | 0:3328df4c3116 | 70 | { |
ftagius | 1:10d2a051285e | 71 | printf("Could not open file %s for writing\r\n",logFilePath); |
ftagius | 0:3328df4c3116 | 72 | sd.unmount(); |
ftagius | 1:10d2a051285e | 73 | printf("unmount sd card \r\n"); |
ftagius | 0:3328df4c3116 | 74 | return; |
ftagius | 0:3328df4c3116 | 75 | } |
ftagius | 0:3328df4c3116 | 76 | } |
ftagius | 3:e3974328d808 | 77 | if (debug) |
ftagius | 3:e3974328d808 | 78 | pc.printf("Opened log file %s\r\n",logFilePath); |
ftagius | 0:3328df4c3116 | 79 | // write the log file header |
ftagius | 0:3328df4c3116 | 80 | if (header == false) |
ftagius | 0:3328df4c3116 | 81 | { |
cmkachur | 2:3edb129c60b2 | 82 | fprintf(fp,"# date,time,raw timestamp,latitude,longitude,distance,interrupt,energy\r\n"); |
ftagius | 0:3328df4c3116 | 83 | header = true; |
ftagius | 0:3328df4c3116 | 84 | } |
ftagius | 0:3328df4c3116 | 85 | // write to the current log file |
ftagius | 0:3328df4c3116 | 86 | fprintf(fp,"%02d/%02d/20%02d,", gpsd.month, gpsd.day, gpsd.year); |
ftagius | 0:3328df4c3116 | 87 | fprintf(fp,"%02d:%02d:%02d,", gpsd.hour, gpsd.minute, gpsd.seconds); |
ftagius | 0:3328df4c3116 | 88 | fprintf(fp,"%7.0f,",gpsd.timef); |
ftagius | 0:3328df4c3116 | 89 | fprintf(fp,"%5.7f,%5.7f,", gpsd.lat_deg, gpsd.lon_deg); |
ftagius | 1:10d2a051285e | 90 | fprintf(fp,"%d,",distance); |
cmkachur | 2:3edb129c60b2 | 91 | fprintf(fp,"%d,",interruptSource); |
cmkachur | 2:3edb129c60b2 | 92 | fprintf(fp,"%ld",energy); |
ftagius | 0:3328df4c3116 | 93 | fprintf(fp,"\r\n"); |
ftagius | 0:3328df4c3116 | 94 | fflush(fp); |
ftagius | 0:3328df4c3116 | 95 | f_sync((FIL*)fp); |
ftagius | 0:3328df4c3116 | 96 | fclose(fp); |
ftagius | 0:3328df4c3116 | 97 | sd.unmount(); |
ftagius | 3:e3974328d808 | 98 | pc.printf("Event: "); |
ftagius | 3:e3974328d808 | 99 | switch (interruptSource) |
ftagius | 3:e3974328d808 | 100 | { |
ftagius | 3:e3974328d808 | 101 | case 1: |
ftagius | 3:e3974328d808 | 102 | pc.printf("Noise level too high\r\n"); |
ftagius | 3:e3974328d808 | 103 | break; |
ftagius | 3:e3974328d808 | 104 | case 4: |
ftagius | 3:e3974328d808 | 105 | pc.printf("Disturber\r\n"); |
ftagius | 3:e3974328d808 | 106 | break; |
ftagius | 3:e3974328d808 | 107 | case 8: |
ftagius | 3:e3974328d808 | 108 | pc.printf("Lightning detection, distance=%dkm energy=%ld\r\n", distance, energy); |
ftagius | 3:e3974328d808 | 109 | ld.clearStats(); |
ftagius | 3:e3974328d808 | 110 | break; |
ftagius | 3:e3974328d808 | 111 | default: |
ftagius | 3:e3974328d808 | 112 | pc.printf("Unknown interrupt %d\r\n", OriginInt); |
ftagius | 3:e3974328d808 | 113 | |
ftagius | 3:e3974328d808 | 114 | } |
ftagius | 3:e3974328d808 | 115 | |
ftagius | 3:e3974328d808 | 116 | if (debug) |
ftagius | 3:e3974328d808 | 117 | pc.printf("Closed log file %s\r\n",logFilePath); |
ftagius | 0:3328df4c3116 | 118 | } |
ftagius | 0:3328df4c3116 | 119 | |
ftagius | 0:3328df4c3116 | 120 | int main() |
ftagius | 0:3328df4c3116 | 121 | { |
ftagius | 0:3328df4c3116 | 122 | char c; |
ftagius | 0:3328df4c3116 | 123 | Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? |
ftagius | 0:3328df4c3116 | 124 | const int refresh_Time = 1000; //refresh time in ms |
ftagius | 0:3328df4c3116 | 125 | TSISensor tsi; // touch slider |
ftagius | 0:3328df4c3116 | 126 | unsigned long measFreq; |
ftagius | 1:10d2a051285e | 127 | rdistance=-1; |
ftagius | 1:10d2a051285e | 128 | rinterrupt=-1; |
ftagius | 0:3328df4c3116 | 129 | pc.baud(9600); |
ftagius | 0:3328df4c3116 | 130 | // initializations for gps |
ftagius | 0:3328df4c3116 | 131 | green = 1; |
ftagius | 0:3328df4c3116 | 132 | gpsd.setBaud(9600); |
ftagius | 0:3328df4c3116 | 133 | gpsd.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); |
ftagius | 0:3328df4c3116 | 134 | gpsd.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); |
ftagius | 0:3328df4c3116 | 135 | gpsd.sendCommand(PGCMD_ANTENNA); |
ftagius | 0:3328df4c3116 | 136 | gpsd.day=01; |
ftagius | 0:3328df4c3116 | 137 | gpsd.month=01; |
ftagius | 0:3328df4c3116 | 138 | gpsd.year=15; |
ftagius | 0:3328df4c3116 | 139 | gpsd.hour=1; |
ftagius | 0:3328df4c3116 | 140 | gpsd.minute=1; |
ftagius | 0:3328df4c3116 | 141 | gpsd.seconds=1; |
ftagius | 0:3328df4c3116 | 142 | red = 1; |
ftagius | 0:3328df4c3116 | 143 | green = 1; |
ftagius | 3:e3974328d808 | 144 | pc.printf("Touch slider to start lightning detector application\r\n"); |
ftagius | 0:3328df4c3116 | 145 | while(1) { |
ftagius | 0:3328df4c3116 | 146 | green = 1; // turn led off |
ftagius | 0:3328df4c3116 | 147 | wait_ms(200); |
ftagius | 0:3328df4c3116 | 148 | if (tsi.readPercentage()) |
ftagius | 0:3328df4c3116 | 149 | break; |
ftagius | 0:3328df4c3116 | 150 | green = 0; // turn led on |
ftagius | 0:3328df4c3116 | 151 | wait_ms(200); |
ftagius | 0:3328df4c3116 | 152 | if (tsi.readPercentage()) |
ftagius | 0:3328df4c3116 | 153 | break; |
ftagius | 0:3328df4c3116 | 154 | } |
ftagius | 0:3328df4c3116 | 155 | |
ftagius | 3:e3974328d808 | 156 | pc.printf("\r\nInitialize lightning detector\r\n"); |
ftagius | 0:3328df4c3116 | 157 | //initializations for lightning detector |
ftagius | 0:3328df4c3116 | 158 | ld.init(); |
ftagius | 0:3328df4c3116 | 159 | ld.clearStats(); |
ftagius | 1:10d2a051285e | 160 | |
cmkachur | 2:3edb129c60b2 | 161 | ld.calibrateRCOs(IntLightning); |
ftagius | 0:3328df4c3116 | 162 | measFreq = ld.tuneAntenna(IntLightning); |
ftagius | 1:10d2a051285e | 163 | |
cmkachur | 2:3edb129c60b2 | 164 | //ld.powerUp(); |
cmkachur | 2:3edb129c60b2 | 165 | |
ftagius | 1:10d2a051285e | 166 | //ld.setIndoors(); |
ftagius | 1:10d2a051285e | 167 | ld.setOutdoors(); |
ftagius | 0:3328df4c3116 | 168 | ld.setMinimumLightnings(0); |
ftagius | 0:3328df4c3116 | 169 | ld.setSpikeRejection(2); |
ftagius | 0:3328df4c3116 | 170 | ld.setNoiseFloor(2); |
ftagius | 0:3328df4c3116 | 171 | //ld.disableDisturbers(); |
ftagius | 0:3328df4c3116 | 172 | ld.enableDisturbers(); |
ftagius | 0:3328df4c3116 | 173 | ld.setWatchdogThreshold(4); |
ftagius | 0:3328df4c3116 | 174 | IntLightning.rise(&DetectLightning); |
ftagius | 0:3328df4c3116 | 175 | int MinBlysk = ld.getMinimumLightnings(); |
ftagius | 0:3328df4c3116 | 176 | int Noise = ld.getNoiseFloor(); |
ftagius | 1:10d2a051285e | 177 | // ld.setTuneCap(5); // 500kHz |
ftagius | 0:3328df4c3116 | 178 | int TuneCap = ld.getTuneCap(); |
ftagius | 0:3328df4c3116 | 179 | int SpikeRej = ld.getSpikeRejection(); |
ftagius | 0:3328df4c3116 | 180 | int WatchDog = ld.getWatchdogThreshold(); |
ftagius | 0:3328df4c3116 | 181 | |
ftagius | 3:e3974328d808 | 182 | pc.printf("\r\n Min wylad: %i", MinBlysk); |
ftagius | 0:3328df4c3116 | 183 | pc.printf("\r\n"); |
ftagius | 0:3328df4c3116 | 184 | pc.printf(" Gain: 0x%02x\r\n",ld.getGain()); |
ftagius | 0:3328df4c3116 | 185 | pc.printf(" Noise: %i", Noise); |
ftagius | 0:3328df4c3116 | 186 | pc.printf("\r\n"); |
ftagius | 0:3328df4c3116 | 187 | pc.printf(" Tune CAP: %i", TuneCap); |
ftagius | 0:3328df4c3116 | 188 | pc.printf("\r\n"); |
ftagius | 0:3328df4c3116 | 189 | pc.printf(" Spike rej: %i", SpikeRej); |
ftagius | 0:3328df4c3116 | 190 | pc.printf("\r\n"); |
ftagius | 0:3328df4c3116 | 191 | pc.printf(" Watchdog: %i", WatchDog); |
ftagius | 0:3328df4c3116 | 192 | pc.printf("\r\n"); |
ftagius | 0:3328df4c3116 | 193 | pc.printf(" LCO calibration: %ld Hz\n\r", measFreq); |
ftagius | 0:3328df4c3116 | 194 | |
ftagius | 0:3328df4c3116 | 195 | |
ftagius | 0:3328df4c3116 | 196 | refresh_Timer.start(); //starts the clock on the timer |
ftagius | 0:3328df4c3116 | 197 | //Mount the filesystem |
ftagius | 0:3328df4c3116 | 198 | sd.mount(); |
ftagius | 0:3328df4c3116 | 199 | mkdir(directory, 0777); |
ftagius | 1:10d2a051285e | 200 | sd.unmount(); |
ftagius | 1:10d2a051285e | 201 | |
ftagius | 0:3328df4c3116 | 202 | bool gpsFix=false; |
ftagius | 0:3328df4c3116 | 203 | while (1) |
ftagius | 0:3328df4c3116 | 204 | { |
ftagius | 3:e3974328d808 | 205 | if (OriginInt != -1) |
ftagius | 3:e3974328d808 | 206 | { |
ftagius | 3:e3974328d808 | 207 | // the ld detector generated an interrupt, log the event |
ftagius | 3:e3974328d808 | 208 | IntLightning.disable_irq(); |
ftagius | 3:e3974328d808 | 209 | writeLogFile(OriginInt,distance, energy); |
ftagius | 3:e3974328d808 | 210 | ld.clearStats(); |
ftagius | 3:e3974328d808 | 211 | OriginInt = -1; |
ftagius | 3:e3974328d808 | 212 | distance = -1; |
ftagius | 3:e3974328d808 | 213 | energy = -1; |
ftagius | 3:e3974328d808 | 214 | IntLightning.enable_irq(); |
ftagius | 3:e3974328d808 | 215 | } |
ftagius | 3:e3974328d808 | 216 | |
ftagius | 0:3328df4c3116 | 217 | c = gpsd.read(); //queries the GPS |
ftagius | 0:3328df4c3116 | 218 | if (debug) |
ftagius | 0:3328df4c3116 | 219 | { |
ftagius | 0:3328df4c3116 | 220 | if (c) { |
ftagius | 0:3328df4c3116 | 221 | printf("%c", c); //this line will echo the GPS data if not paused |
ftagius | 0:3328df4c3116 | 222 | continue; |
ftagius | 0:3328df4c3116 | 223 | } |
ftagius | 0:3328df4c3116 | 224 | } |
ftagius | 0:3328df4c3116 | 225 | |
ftagius | 0:3328df4c3116 | 226 | //check if we recieved a new message from GPS, if so, attempt to parse it, |
ftagius | 0:3328df4c3116 | 227 | if ( gpsd.newNMEAreceived() ) { |
ftagius | 0:3328df4c3116 | 228 | if ( !gpsd.parse(gpsd.lastNMEA()) ) { |
ftagius | 0:3328df4c3116 | 229 | continue; |
ftagius | 0:3328df4c3116 | 230 | } |
ftagius | 0:3328df4c3116 | 231 | } |
ftagius | 0:3328df4c3116 | 232 | |
ftagius | 0:3328df4c3116 | 233 | // update globals with the lastest gps time stamp |
ftagius | 0:3328df4c3116 | 234 | day=gpsd.day; |
ftagius | 0:3328df4c3116 | 235 | month=gpsd.month; |
ftagius | 0:3328df4c3116 | 236 | year=gpsd.year; |
ftagius | 0:3328df4c3116 | 237 | hour=gpsd.hour; |
ftagius | 0:3328df4c3116 | 238 | minute=gpsd.minute; |
ftagius | 0:3328df4c3116 | 239 | seconds=gpsd.seconds; |
ftagius | 0:3328df4c3116 | 240 | |
ftagius | 0:3328df4c3116 | 241 | //check if enough time has passed to warrant printing GPS info to screen |
ftagius | 0:3328df4c3116 | 242 | //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing |
ftagius | 0:3328df4c3116 | 243 | if (refresh_Timer.read_ms() >= refresh_Time) |
ftagius | 0:3328df4c3116 | 244 | { |
ftagius | 0:3328df4c3116 | 245 | if (gpsd.fix) { |
ftagius | 0:3328df4c3116 | 246 | // got a gps fix |
ftagius | 0:3328df4c3116 | 247 | if (gpsFix == false) |
ftagius | 0:3328df4c3116 | 248 | { |
ftagius | 0:3328df4c3116 | 249 | // first time fix obtained |
ftagius | 0:3328df4c3116 | 250 | gpsFix = true; |
ftagius | 0:3328df4c3116 | 251 | pc.printf("GPS fix obtained on %02d/%02d/20%02d_%02d:%02d:%02d (UTC)\r\n",gpsd.month,gpsd.day,gpsd.year,gpsd.hour,gpsd.minute,gpsd.seconds); |
ftagius | 1:10d2a051285e | 252 | //pc.printf("Touch slider to suspend application\r\n"); |
ftagius | 0:3328df4c3116 | 253 | pc.printf("Waiting for lighting detection...\r\n"); |
ftagius | 0:3328df4c3116 | 254 | } |
ftagius | 0:3328df4c3116 | 255 | |
ftagius | 0:3328df4c3116 | 256 | //red = 1; // turn led off |
ftagius | 0:3328df4c3116 | 257 | //pc.printf("turn green on\r\n"); |
ftagius | 0:3328df4c3116 | 258 | green = 0; // turn led on |
ftagius | 0:3328df4c3116 | 259 | wait_ms(50); |
ftagius | 0:3328df4c3116 | 260 | } |
ftagius | 0:3328df4c3116 | 261 | else |
ftagius | 0:3328df4c3116 | 262 | { |
ftagius | 3:e3974328d808 | 263 | gpsFix = false; |
ftagius | 0:3328df4c3116 | 264 | pc.printf("Waiting for GPS FIX\r\n"); |
ftagius | 0:3328df4c3116 | 265 | red = 0; // turn led on |
ftagius | 0:3328df4c3116 | 266 | } |
ftagius | 0:3328df4c3116 | 267 | |
ftagius | 0:3328df4c3116 | 268 | // restart the timer for the gps print loop |
ftagius | 0:3328df4c3116 | 269 | // writeLogFile(-2); |
ftagius | 0:3328df4c3116 | 270 | refresh_Timer.reset(); |
ftagius | 0:3328df4c3116 | 271 | } |
ftagius | 0:3328df4c3116 | 272 | else |
ftagius | 0:3328df4c3116 | 273 | { |
ftagius | 0:3328df4c3116 | 274 | //red = 0; // turn led on |
ftagius | 0:3328df4c3116 | 275 | //pc.printf("turn green off\r\n"); |
ftagius | 0:3328df4c3116 | 276 | green = 1; // turn green led off |
ftagius | 1:10d2a051285e | 277 | #if 0 |
ftagius | 0:3328df4c3116 | 278 | // check the slider. if touched, disable lighting interrupts and wait for another slider touch |
ftagius | 0:3328df4c3116 | 279 | if (tsi.readPercentage()) |
ftagius | 0:3328df4c3116 | 280 | { |
ftagius | 1:10d2a051285e | 281 | //IntLightning.disable_irq(); |
ftagius | 0:3328df4c3116 | 282 | pc.printf("Touch slider to continue application\r\n"); |
ftagius | 0:3328df4c3116 | 283 | while (1) |
ftagius | 0:3328df4c3116 | 284 | { |
ftagius | 0:3328df4c3116 | 285 | |
ftagius | 0:3328df4c3116 | 286 | green = 1; // turn led off |
ftagius | 0:3328df4c3116 | 287 | wait_ms(200); |
ftagius | 0:3328df4c3116 | 288 | // break of of the loop if the slider is touched |
ftagius | 0:3328df4c3116 | 289 | if (tsi.readPercentage()) |
ftagius | 0:3328df4c3116 | 290 | { |
ftagius | 0:3328df4c3116 | 291 | green = 1; |
ftagius | 0:3328df4c3116 | 292 | red = 1; |
ftagius | 0:3328df4c3116 | 293 | pc.printf("Now monitoring for lightning strikes\r\n"); |
ftagius | 1:10d2a051285e | 294 | //IntLightning.enable_irq(); |
ftagius | 0:3328df4c3116 | 295 | break; |
ftagius | 0:3328df4c3116 | 296 | } |
ftagius | 0:3328df4c3116 | 297 | green = 0; // turn led on |
ftagius | 0:3328df4c3116 | 298 | wait_ms(200); |
ftagius | 0:3328df4c3116 | 299 | // break of of the loop if the slider is touched |
ftagius | 0:3328df4c3116 | 300 | if (tsi.readPercentage()) |
ftagius | 0:3328df4c3116 | 301 | { |
ftagius | 0:3328df4c3116 | 302 | green = 1; |
ftagius | 0:3328df4c3116 | 303 | red = 1; |
ftagius | 0:3328df4c3116 | 304 | pc.printf("Now monitoring for lightning strikes\r\n"); |
ftagius | 1:10d2a051285e | 305 | //IntLightning.enable_irq(); |
ftagius | 0:3328df4c3116 | 306 | break; |
ftagius | 0:3328df4c3116 | 307 | } |
ftagius | 0:3328df4c3116 | 308 | |
ftagius | 0:3328df4c3116 | 309 | } // end while 1 for slider |
ftagius | 0:3328df4c3116 | 310 | } // end if tsi read |
ftagius | 1:10d2a051285e | 311 | #endif |
ftagius | 0:3328df4c3116 | 312 | } // end else refresh timer |
ftagius | 0:3328df4c3116 | 313 | |
ftagius | 0:3328df4c3116 | 314 | } |
ftagius | 0:3328df4c3116 | 315 | |
ftagius | 0:3328df4c3116 | 316 | |
ftagius | 0:3328df4c3116 | 317 | |
ftagius | 0:3328df4c3116 | 318 | } |