Charles Young's development fork. Going forward I only want to push mature code to main repository.
Fork of GEO_COUNTER_L432KC by
main.cpp@59:f96a503bd228, 2018-09-08 (annotated)
- Committer:
- Charles David Young
- Date:
- Sat Sep 08 21:35:13 2018 -0700
- Revision:
- 59:f96a503bd228
- Parent:
- 58:d15adb224e5a
- Child:
- 60:6ae1a2390600
debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
walter76 | 2:ac0ed3d84d44 | 1 | // GEO COUNTER V1 firmware |
walter76 | 2:ac0ed3d84d44 | 2 | // This FW provides a basic operation of GEO-COUNTER |
walter76 | 2:ac0ed3d84d44 | 3 | // |
walter76 | 2:ac0ed3d84d44 | 4 | // Latest review: August 27, 2018 - Walter Trovo |
walter76 | 1:75827d765e34 | 5 | // |
Charles David Young |
47:f004b4612069 | 6 | // Sep 6, 2018: Charles Young: Functioning mode selection - modes partially implemented |
Charles David Young |
25:0161bf1adc81 | 7 | // Sep 5, 2018: Charles Young: Created LED7segDisplay class |
charlesdavidyoung | 24:db7494389c03 | 8 | // Sep 5, 2018: Charles Young: Still developing mode selection. LEDs turn off |
charlesdavidyoung | 24:db7494389c03 | 9 | // when not in mode selection. Pressing once enters mode selection. |
charlesdavidyoung | 24:db7494389c03 | 10 | // Pressing again enters submode. Temporarily the rotary switch |
charlesdavidyoung | 24:db7494389c03 | 11 | // adjusts the display brightness. This is just for testing. |
charlesdavidyoung | 24:db7494389c03 | 12 | // Sep 4, 2018: Charles Young: Created RotarySwitch class to manage mode selection |
walter76 | 1:75827d765e34 | 13 | // Feb 14, 2018: initial release aimed to test the counters, the serial port |
walter76 | 1:75827d765e34 | 14 | // the PWM output and the MAX7219 operation. |
walter76 | 1:75827d765e34 | 15 | // Feb 15, 2018: Removed MAX7219 libray (replaced with custom routine). |
walter76 | 1:75827d765e34 | 16 | // Added 74HC595 routine. Added beep. Added Gate_write |
walter76 | 1:75827d765e34 | 17 | // |
walter76 | 2:ac0ed3d84d44 | 18 | |
walter76 | 1:75827d765e34 | 19 | |
walter76 | 1:75827d765e34 | 20 | // this block includes key libraries |
walter76 | 1:75827d765e34 | 21 | #include <string> // strings management |
charlesdavidyoung | 24:db7494389c03 | 22 | #include "RotarySwitch.hpp" |
Charles David Young |
25:0161bf1adc81 | 23 | #include "LED7segDisplay.hpp" |
charlesdavidyoung | 20:fb73eaaf0894 | 24 | |
charlesdavidyoung | 24:db7494389c03 | 25 | // Everything associated with the rotary switch and the associated LEDs |
charlesdavidyoung | 24:db7494389c03 | 26 | // is hidden in this class. |
charlesdavidyoung | 20:fb73eaaf0894 | 27 | RotarySwitch ModeSwitch; |
Charles David Young |
25:0161bf1adc81 | 28 | LED7segDisplay DigitsDisplay; |
walter76 | 1:75827d765e34 | 29 | |
Charles David Young |
34:10550b327e3d | 30 | enum Modes { |
Charles David Young |
34:10550b327e3d | 31 | CNT1, |
Charles David Young |
34:10550b327e3d | 32 | CNT2, |
Charles David Young |
34:10550b327e3d | 33 | PROSPECT, |
Charles David Young |
34:10550b327e3d | 34 | NULL1, |
Charles David Young |
37:6f7bb913e08b | 35 | NULL2, |
Charles David Young |
38:1642320d83a0 | 36 | VOLTS, |
Charles David Young |
38:1642320d83a0 | 37 | VOLUME, |
Charles David Young |
34:10550b327e3d | 38 | DIM, |
Charles David Young |
34:10550b327e3d | 39 | NumberOfModes |
Charles David Young |
34:10550b327e3d | 40 | }; |
Charles David Young |
38:1642320d83a0 | 41 | uint8_t currentMode = CNT1; |
Charles David Young |
38:1642320d83a0 | 42 | uint8_t currentModeToDisplay = CNT1; |
Charles David Young |
34:10550b327e3d | 43 | |
charlesdavidyoung | 5:4f90b458dbdf | 44 | // LED on processor board |
charlesdavidyoung | 5:4f90b458dbdf | 45 | DigitalOut led1(LED1); |
walter76 | 1:75827d765e34 | 46 | |
walter76 | 1:75827d765e34 | 47 | // definitions of peripherals and devices |
Charles David Young |
7:9f975e00600c | 48 | |
charlesdavidyoung | 17:6eed17197004 | 49 | I2C i2c(D4, D5); // I2C port |
charlesdavidyoung | 17:6eed17197004 | 50 | Ticker SecTenth_Beat; // .1 second ticker |
walter76 | 1:75827d765e34 | 51 | Ticker Sec_Beat; // 1 second ticker |
walter76 | 1:75827d765e34 | 52 | Serial PC(USBTX, USBRX); // Virtual COM via USB (PC connection) |
walter76 | 1:75827d765e34 | 53 | Serial GPS(D1, D0); // Serial port for GPS module |
walter76 | 0:6d1742703713 | 54 | |
walter76 | 0:6d1742703713 | 55 | // Global variables |
walter76 | 1:75827d765e34 | 56 | time_t seconds; // Real-Time Clock (RTC) timestamp |
walter76 | 1:75827d765e34 | 57 | unsigned int value = 0; // displayed value on the 6-digits of the display |
Charles David Young |
44:a26ca542ae5e | 58 | |
walter76 | 1:75827d765e34 | 59 | uint32_t Count1, Count2; // pulse counters (32-bit) |
Charles David Young |
46:c7ce8fccb712 | 60 | int32_t TickerCorrection = 0; |
Charles David Young |
58:d15adb224e5a | 61 | uint32_t TickerPeriod = 100000; |
Charles David Young |
53:04999d536e92 | 62 | uint32_t TickerPeriodCount = 0; |
Charles David Young |
53:04999d536e92 | 63 | const uint32_t TickerPeriodsPerSecond = 1000000/TickerPeriod; |
Charles David Young |
44:a26ca542ae5e | 64 | const int16_t TickerCorrectionMax = 99; |
Charles David Young |
44:a26ca542ae5e | 65 | const int16_t TickerCorrectionMin = -99; |
Charles David Young |
44:a26ca542ae5e | 66 | |
walter76 | 1:75827d765e34 | 67 | char Text[40]=""; // used to send messages over the serial port |
walter76 | 1:75827d765e34 | 68 | uint8_t Disp_mode = 0x01, Disp_unit = 0xA0; // status of 1st row and 2nd rows of LEDs |
kd5byb | 4:b17c6556cf1f | 69 | bool Stopped = 0; // status of counting activity |
charlesdavidyoung | 5:4f90b458dbdf | 70 | bool StartStopPressed = 0;// status of counting activity |
walter76 | 1:75827d765e34 | 71 | double ADC_val; // used to read ADC value |
charlesdavidyoung | 24:db7494389c03 | 72 | float direction = 0; |
walter76 | 0:6d1742703713 | 73 | |
Charles David Young |
38:1642320d83a0 | 74 | #define maxVolume 10 |
Charles David Young |
38:1642320d83a0 | 75 | uint8_t volume = maxVolume; |
Charles David Young |
38:1642320d83a0 | 76 | |
walter76 | 1:75827d765e34 | 77 | // ----- Prototypes of routines (defined below the main) ------------------- |
Charles David Young |
16:b2e77eb76ab4 | 78 | void UpdateInput(void); // periodically called by the ticker |
Charles David Young |
16:b2e77eb76ab4 | 79 | void UpdateOutput(void); // periodically called by the ticker |
Charles David Young |
53:04999d536e92 | 80 | void UpdateIO(void); // periodically called by the ticker |
walter76 | 1:75827d765e34 | 81 | void Count1_up(void); // called every time an edge is detected on TRIG1 pin |
walter76 | 1:75827d765e34 | 82 | void Count2_up(void); // called every time an edge is detected on TRIG2 pin |
walter76 | 1:75827d765e34 | 83 | void Beep(void); // used to generate a short beep (buzzer) |
walter76 | 0:6d1742703713 | 84 | |
walter76 | 0:6d1742703713 | 85 | //============================================================================== |
walter76 | 0:6d1742703713 | 86 | //============================================================================== |
walter76 | 0:6d1742703713 | 87 | |
walter76 | 0:6d1742703713 | 88 | int main() |
walter76 | 0:6d1742703713 | 89 | { |
walter76 | 0:6d1742703713 | 90 | |
Charles David Young |
28:c81d00ec28a3 | 91 | PC.baud(115200); // set baud-rate of virtual COM port (PC connection) |
Charles David Young |
28:c81d00ec28a3 | 92 | PC.printf("\nGEO COUNTER V1 2108"); |
Charles David Young |
28:c81d00ec28a3 | 93 | PC.printf(__DATE__); |
Charles David Young |
28:c81d00ec28a3 | 94 | PC.printf(" "); |
Charles David Young |
28:c81d00ec28a3 | 95 | PC.printf(__TIME__); |
walter76 | 1:75827d765e34 | 96 | |
Charles David Young |
28:c81d00ec28a3 | 97 | GPS.baud(9600); // set the baud-rate of the serial port dedicated to the GPS |
walter76 | 0:6d1742703713 | 98 | |
Charles David Young |
28:c81d00ec28a3 | 99 | CS1 = 1; // presets CS of MAX7219 |
Charles David Young |
28:c81d00ec28a3 | 100 | CS2 = 1; // preset CS of 74HC595 |
walter76 | 1:75827d765e34 | 101 | |
Charles David Young |
28:c81d00ec28a3 | 102 | DigitsDisplay.Display_6D_write(0x543210); |
Charles David Young |
28:c81d00ec28a3 | 103 | DigitsDisplay.Display_2D_write(0); |
walter76 | 0:6d1742703713 | 104 | |
Charles David Young |
28:c81d00ec28a3 | 105 | // RTC is supposed to be loose time at power down (no backup battery) |
Charles David Young |
28:c81d00ec28a3 | 106 | // An initialization is performed anyway |
Charles David Young |
28:c81d00ec28a3 | 107 | set_time(0); // Set time |
charlesdavidyoung | 24:db7494389c03 | 108 | |
Charles David Young |
28:c81d00ec28a3 | 109 | PWM.period_ms(3); // set the PWM period |
Charles David Young |
28:c81d00ec28a3 | 110 | PWM.write(0.8); // set the PWM duty-cycle |
walter76 | 1:75827d765e34 | 111 | |
Charles David Young |
28:c81d00ec28a3 | 112 | Beep(); // initial beep |
walter76 | 1:75827d765e34 | 113 | |
Charles David Young |
28:c81d00ec28a3 | 114 | // set the 1 sec ticker to periodically call the Update() routine |
Charles David Young |
28:c81d00ec28a3 | 115 | // NOTE: this is also the 1-sec time base for counters. A better approach |
Charles David Young |
28:c81d00ec28a3 | 116 | // would replace the ticker with an interrupt from the RTC (to be implemented) |
Charles David Young |
53:04999d536e92 | 117 | SecTenth_Beat.attach_us(&UpdateIO, TickerPeriod); |
Charles David Young |
28:c81d00ec28a3 | 118 | //RTC::attach(&Update, RTC::Second); |
Charles David Young |
28:c81d00ec28a3 | 119 | //RTC::detach(RTC::Second); |
walter76 | 1:75827d765e34 | 120 | |
Charles David Young |
28:c81d00ec28a3 | 121 | // main loop does nothing as all activities are interrupt driven |
Charles David Young |
28:c81d00ec28a3 | 122 | while(1) |
Charles David Young |
28:c81d00ec28a3 | 123 | { |
Charles David Young |
28:c81d00ec28a3 | 124 | // dance (or drink a beer) |
Charles David Young |
28:c81d00ec28a3 | 125 | } |
walter76 | 0:6d1742703713 | 126 | } |
walter76 | 0:6d1742703713 | 127 | |
walter76 | 0:6d1742703713 | 128 | |
walter76 | 1:75827d765e34 | 129 | //-------- END OF MAIN -------------- |
walter76 | 0:6d1742703713 | 130 | //============================================================================== |
walter76 | 0:6d1742703713 | 131 | |
walter76 | 1:75827d765e34 | 132 | // Definition of routines |
walter76 | 1:75827d765e34 | 133 | |
walter76 | 1:75827d765e34 | 134 | //--------------------------------------------------------------------------- |
walter76 | 1:75827d765e34 | 135 | // Update values to be displayed |
Charles David Young |
10:f48cc6be5ae8 | 136 | void logToPC() |
Charles David Young |
10:f48cc6be5ae8 | 137 | { |
Charles David Young |
10:f48cc6be5ae8 | 138 | PC.printf("\nADC: %.02f", ADC_val); |
Charles David Young |
10:f48cc6be5ae8 | 139 | PC.printf(Stopped ? " stopped" : " started"); |
Charles David Young |
10:f48cc6be5ae8 | 140 | // Timestamp to PC (debug) |
Charles David Young |
10:f48cc6be5ae8 | 141 | seconds = time(NULL); // get current time |
Charles David Young |
10:f48cc6be5ae8 | 142 | strftime(Text, 50, "%H:%M:%S", localtime(&seconds)); |
Charles David Young |
10:f48cc6be5ae8 | 143 | PC.printf(" RTC: %s, CNT1: %7d CNT2: %7d",Text, Count1, Count2); |
charlesdavidyoung | 24:db7494389c03 | 144 | PC.printf(" wheel %f", direction); |
Charles David Young |
10:f48cc6be5ae8 | 145 | } |
walter76 | 1:75827d765e34 | 146 | |
Charles David Young |
53:04999d536e92 | 147 | void UpdateIO() |
Charles David Young |
53:04999d536e92 | 148 | { |
Charles David Young |
53:04999d536e92 | 149 | if (++TickerPeriodCount >= TickerPeriodsPerSecond) |
Charles David Young |
53:04999d536e92 | 150 | { |
Charles David Young |
53:04999d536e92 | 151 | TickerPeriodCount = 0; |
Charles David Young |
53:04999d536e92 | 152 | UpdateOutput(); |
Charles David Young |
53:04999d536e92 | 153 | } |
Charles David Young |
53:04999d536e92 | 154 | UpdateInput(); |
Charles David Young |
53:04999d536e92 | 155 | } |
Charles David Young |
53:04999d536e92 | 156 | |
Charles David Young |
53:04999d536e92 | 157 | void UpdateOutput() |
charlesdavidyoung | 18:ef5678ab1889 | 158 | { |
Charles David Young |
49:a67f2a3d228a | 159 | // Capture the counts early so they will be more accurate |
Charles David Young |
49:a67f2a3d228a | 160 | uint32_t Count1Save = Count1; |
Charles David Young |
49:a67f2a3d228a | 161 | uint32_t Count2Save = Count2; |
Charles David Young |
50:19ab5315e2b4 | 162 | Count1 = 0; |
Charles David Young |
50:19ab5315e2b4 | 163 | Count2 = 0; |
Charles David Young |
49:a67f2a3d228a | 164 | |
Charles David Young |
49:a67f2a3d228a | 165 | if(Stopped) |
Charles David Young |
49:a67f2a3d228a | 166 | { |
Charles David Young |
49:a67f2a3d228a | 167 | // disable interrupts on TRIG1 and TRIG2 |
Charles David Young |
49:a67f2a3d228a | 168 | TRIG1.rise(NULL); |
Charles David Young |
49:a67f2a3d228a | 169 | TRIG2.rise(NULL); |
Charles David Young |
49:a67f2a3d228a | 170 | } |
Charles David Young |
49:a67f2a3d228a | 171 | |
Charles David Young |
28:c81d00ec28a3 | 172 | // This must be called periodically to update the LEDs |
Charles David Young |
28:c81d00ec28a3 | 173 | ModeSwitch.UpdateOutput(); |
charlesdavidyoung | 24:db7494389c03 | 174 | |
Charles David Young |
38:1642320d83a0 | 175 | switch (currentModeToDisplay) { |
Charles David Young |
34:10550b327e3d | 176 | case CNT1: |
Charles David Young |
49:a67f2a3d228a | 177 | DigitsDisplay.Display_6D_write(Count1Save); |
Charles David Young |
41:08bf3ea5eba4 | 178 | DigitsDisplay.Display_2D_Blank(); |
Charles David Young |
34:10550b327e3d | 179 | break; |
Charles David Young |
34:10550b327e3d | 180 | case CNT2: |
Charles David Young |
49:a67f2a3d228a | 181 | DigitsDisplay.Display_6D_write(Count2Save); |
Charles David Young |
41:08bf3ea5eba4 | 182 | DigitsDisplay.Display_2D_Blank(); |
Charles David Young |
34:10550b327e3d | 183 | break; |
Charles David Young |
34:10550b327e3d | 184 | case PROSPECT: |
Charles David Young |
49:a67f2a3d228a | 185 | if (Count1Save) |
Charles David Young |
49:a67f2a3d228a | 186 | DigitsDisplay.Display_6D_write(Count1Save); |
Charles David Young |
44:a26ca542ae5e | 187 | else |
Charles David Young |
49:a67f2a3d228a | 188 | DigitsDisplay.Display_6D_write(Count2Save); |
Charles David Young |
41:08bf3ea5eba4 | 189 | DigitsDisplay.Display_2D_Blank(); |
Charles David Young |
34:10550b327e3d | 190 | break; |
Charles David Young |
34:10550b327e3d | 191 | case NULL1: |
Charles David Young |
34:10550b327e3d | 192 | DigitsDisplay.Display_6D_write(0); |
Charles David Young |
41:08bf3ea5eba4 | 193 | DigitsDisplay.Display_2D_Blank(); |
Charles David Young |
34:10550b327e3d | 194 | break; |
Charles David Young |
37:6f7bb913e08b | 195 | case NULL2: |
Charles David Young |
34:10550b327e3d | 196 | DigitsDisplay.Display_6D_write(0); |
Charles David Young |
41:08bf3ea5eba4 | 197 | DigitsDisplay.Display_2D_Blank(); |
Charles David Young |
34:10550b327e3d | 198 | break; |
Charles David Young |
38:1642320d83a0 | 199 | case VOLTS: |
Charles David Young |
34:10550b327e3d | 200 | DigitsDisplay.Display_6D_write(0); |
Charles David Young |
41:08bf3ea5eba4 | 201 | DigitsDisplay.Display_2D_Blank(); |
Charles David Young |
34:10550b327e3d | 202 | break; |
Charles David Young |
38:1642320d83a0 | 203 | case VOLUME: |
Charles David Young |
34:10550b327e3d | 204 | case DIM: |
Charles David Young |
34:10550b327e3d | 205 | default: |
Charles David Young |
34:10550b327e3d | 206 | break; |
Charles David Young |
34:10550b327e3d | 207 | } |
Charles David Young |
16:b2e77eb76ab4 | 208 | } |
Charles David Young |
16:b2e77eb76ab4 | 209 | |
Charles David Young |
16:b2e77eb76ab4 | 210 | void UpdateInput() |
charlesdavidyoung | 24:db7494389c03 | 211 | { |
charlesdavidyoung | 24:db7494389c03 | 212 | // This must be called periodically to monitor switch input |
Charles David Young |
38:1642320d83a0 | 213 | direction = ModeSwitch.UpdateInput(); |
Charles David Young |
34:10550b327e3d | 214 | currentMode = ModeSwitch.GetPosition(); |
Charles David Young |
34:10550b327e3d | 215 | |
Charles David Young |
34:10550b327e3d | 216 | switch (currentMode) { |
Charles David Young |
34:10550b327e3d | 217 | case CNT1: |
Charles David Young |
34:10550b327e3d | 218 | case CNT2: |
Charles David Young |
44:a26ca542ae5e | 219 | currentModeToDisplay = currentMode; |
Charles David Young |
44:a26ca542ae5e | 220 | |
Charles David Young |
44:a26ca542ae5e | 221 | if ( (direction > 0) |
Charles David Young |
44:a26ca542ae5e | 222 | && (TickerCorrection < TickerCorrectionMax)) |
Charles David Young |
44:a26ca542ae5e | 223 | { |
Charles David Young |
44:a26ca542ae5e | 224 | TickerCorrection++; |
Charles David Young |
46:c7ce8fccb712 | 225 | Sec_Beat.attach_us(&UpdateOutput, 1000000 + 1000*TickerCorrection); |
Charles David Young |
51:6b916f91f4d9 | 226 | DigitsDisplay.Display_2D_write(TickerCorrection); |
Charles David Young |
44:a26ca542ae5e | 227 | } |
Charles David Young |
44:a26ca542ae5e | 228 | else |
Charles David Young |
44:a26ca542ae5e | 229 | if ( (direction < 0) |
Charles David Young |
44:a26ca542ae5e | 230 | && (TickerCorrection > TickerCorrectionMin)) |
Charles David Young |
44:a26ca542ae5e | 231 | { |
Charles David Young |
44:a26ca542ae5e | 232 | TickerCorrection--; |
Charles David Young |
46:c7ce8fccb712 | 233 | Sec_Beat.attach_us(&UpdateOutput, 1000000 + 1000*TickerCorrection); |
Charles David Young |
51:6b916f91f4d9 | 234 | DigitsDisplay.Display_2D_write(TickerCorrection); |
Charles David Young |
44:a26ca542ae5e | 235 | } |
Charles David Young |
44:a26ca542ae5e | 236 | break; |
Charles David Young |
34:10550b327e3d | 237 | case PROSPECT: |
Charles David Young |
34:10550b327e3d | 238 | case VOLTS: |
Charles David Young |
38:1642320d83a0 | 239 | currentModeToDisplay = currentMode; |
Charles David Young |
34:10550b327e3d | 240 | break; |
Charles David Young |
34:10550b327e3d | 241 | case NULL1: |
Charles David Young |
37:6f7bb913e08b | 242 | case NULL2: |
Charles David Young |
34:10550b327e3d | 243 | break; |
Charles David Young |
38:1642320d83a0 | 244 | case VOLUME: |
Charles David Young |
39:dee91966b45c | 245 | if ( (direction > 0) |
Charles David Young |
39:dee91966b45c | 246 | && (volume < maxVolume)) |
Charles David Young |
39:dee91966b45c | 247 | volume++; |
Charles David Young |
39:dee91966b45c | 248 | else |
Charles David Young |
39:dee91966b45c | 249 | if ( (direction < 0) |
Charles David Young |
39:dee91966b45c | 250 | && (volume > 0)) |
Charles David Young |
39:dee91966b45c | 251 | volume--; |
Charles David Young |
39:dee91966b45c | 252 | |
Charles David Young |
38:1642320d83a0 | 253 | DigitsDisplay.Display_2D_write(volume); |
Charles David Young |
34:10550b327e3d | 254 | break; |
Charles David Young |
34:10550b327e3d | 255 | case DIM: |
Charles David Young |
39:dee91966b45c | 256 | if (direction > 0) |
Charles David Young |
39:dee91966b45c | 257 | DigitsDisplay.Display_brightness_up(); |
Charles David Young |
39:dee91966b45c | 258 | else |
Charles David Young |
39:dee91966b45c | 259 | if (direction < 0) |
Charles David Young |
39:dee91966b45c | 260 | DigitsDisplay.Display_brightness_down(); |
Charles David Young |
39:dee91966b45c | 261 | |
Charles David Young |
38:1642320d83a0 | 262 | DigitsDisplay.Display_2D_write(DigitsDisplay.GetBrightness()); |
Charles David Young |
34:10550b327e3d | 263 | break; |
Charles David Young |
34:10550b327e3d | 264 | default: |
Charles David Young |
34:10550b327e3d | 265 | break; |
charlesdavidyoung | 24:db7494389c03 | 266 | } |
Charles David Young |
34:10550b327e3d | 267 | |
Charles David Young |
53:04999d536e92 | 268 | ADC_val = KEYB.read(); // read voltage from keyboard |
Charles David Young |
53:04999d536e92 | 269 | if ( (ADC_val<0.1) // START/STOP pushbutton pressed |
Charles David Young |
53:04999d536e92 | 270 | && (!StartStopPressed)) |
Charles David Young |
53:04999d536e92 | 271 | { |
Charles David Young |
53:04999d536e92 | 272 | StartStopPressed = true; |
Charles David Young |
59:f96a503bd228 | 273 | if (Stopped) |
Charles David Young |
59:f96a503bd228 | 274 | { |
Charles David Young |
59:f96a503bd228 | 275 | // Enable interrupts on rising edge of digital inputs TRIG1 & TRIG2 |
Charles David Young |
59:f96a503bd228 | 276 | TRIG1.rise(&Count1_up); |
Charles David Young |
59:f96a503bd228 | 277 | TRIG2.rise(&Count2_up); |
Charles David Young |
59:f96a503bd228 | 278 | } |
Charles David Young |
53:04999d536e92 | 279 | Stopped=!Stopped; // toggle status |
Charles David Young |
53:04999d536e92 | 280 | } |
Charles David Young |
53:04999d536e92 | 281 | else |
Charles David Young |
53:04999d536e92 | 282 | StartStopPressed = false; |
charlesdavidyoung | 5:4f90b458dbdf | 283 | |
Charles David Young |
53:04999d536e92 | 284 | if((ADC_val>0.6)&&(ADC_val<0.7)) // CLEAR pushbutton pressed |
Charles David Young |
53:04999d536e92 | 285 | { |
Charles David Young |
53:04999d536e92 | 286 | Count1 = 0; // clear counters |
Charles David Young |
53:04999d536e92 | 287 | Count2 = 0; |
Charles David Young |
53:04999d536e92 | 288 | } |
Charles David Young |
57:f4215ca747e5 | 289 | //logToPC(); |
Charles David Young |
16:b2e77eb76ab4 | 290 | return; |
Charles David Young |
16:b2e77eb76ab4 | 291 | } |
walter76 | 1:75827d765e34 | 292 | |
walter76 | 0:6d1742703713 | 293 | //--------------------------------------------------------------------------- |
walter76 | 1:75827d765e34 | 294 | // Increment CNT1 every time a rising edge is detected on TRIG1 (interrupt) |
walter76 | 1:75827d765e34 | 295 | |
walter76 | 1:75827d765e34 | 296 | void Count1_up(void) |
walter76 | 1:75827d765e34 | 297 | { |
Charles David Young |
33:35e3ab4d5ba7 | 298 | //Beep(); |
Charles David Young |
28:c81d00ec28a3 | 299 | Count1++; |
Charles David Young |
28:c81d00ec28a3 | 300 | return; |
walter76 | 1:75827d765e34 | 301 | } |
walter76 | 1:75827d765e34 | 302 | |
walter76 | 1:75827d765e34 | 303 | //--------------------------------------------------------------------------- |
walter76 | 1:75827d765e34 | 304 | // Increment CNT1 every time a rising edge is detected on TRIG2 (interrupt) |
walter76 | 1:75827d765e34 | 305 | |
walter76 | 1:75827d765e34 | 306 | void Count2_up(void) |
walter76 | 1:75827d765e34 | 307 | { |
Charles David Young |
33:35e3ab4d5ba7 | 308 | //Beep(); |
Charles David Young |
28:c81d00ec28a3 | 309 | Count2++; |
Charles David Young |
28:c81d00ec28a3 | 310 | return; |
walter76 | 1:75827d765e34 | 311 | } |
walter76 | 1:75827d765e34 | 312 | |
walter76 | 1:75827d765e34 | 313 | |
walter76 | 1:75827d765e34 | 314 | //--------------------------------------------------------------------------- |
walter76 | 1:75827d765e34 | 315 | //Generates a short beep via BUZZ |
walter76 | 1:75827d765e34 | 316 | |
walter76 | 1:75827d765e34 | 317 | void Beep(void) |
walter76 | 1:75827d765e34 | 318 | { |
Charles David Young |
28:c81d00ec28a3 | 319 | BUZZ = 1; // turn-on the buzzer |
Charles David Young |
33:35e3ab4d5ba7 | 320 | wait_us(100); // wait |
Charles David Young |
28:c81d00ec28a3 | 321 | BUZZ = 0; // turn-off the buzzer |
Charles David Young |
28:c81d00ec28a3 | 322 | return; |
walter76 | 0:6d1742703713 | 323 | } |
walter76 | 0:6d1742703713 | 324 | |
walter76 | 1:75827d765e34 | 325 | //-------- END OF FILE -------------- |
walter76 | 1:75827d765e34 | 326 | //============================================================================== |