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