Mike Moore
/
RTOS_HW_04
RTOS homework 4
main.cpp@27:c380923f02d8, 2013-09-13 (annotated)
- Committer:
- gatedClock
- Date:
- Fri Sep 13 04:27:27 2013 +0000
- Revision:
- 27:c380923f02d8
- Parent:
- 26:986b539170fc
ok, got power control without cheating.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gatedClock | 0:1013288b8e43 | 1 | /*----------------------------------------------//------------------------------ |
gatedClock | 0:1013288b8e43 | 2 | student : m-moore |
gatedClock | 0:1013288b8e43 | 3 | class : rtos |
gatedClock | 1:5f41e2df0e85 | 4 | directory : RTOS_HW_04 |
gatedClock | 0:1013288b8e43 | 5 | file : main.cpp |
gatedClock | 0:1013288b8e43 | 6 | ----description---------------------------------//------------------------------ |
gatedClock | 0:1013288b8e43 | 7 | Joystick-Controlled Metronome |
gatedClock | 0:1013288b8e43 | 8 | |
gatedClock | 0:1013288b8e43 | 9 | features: |
gatedClock | 19:0db1451d19ef | 10 | 1. joystick-controlled. |
gatedClock | 19:0db1451d19ef | 11 | 2. turns off after one minute. |
gatedClock | 19:0db1451d19ef | 12 | 3. ISR's for all joystick inputs. |
gatedClock | 19:0db1451d19ef | 13 | 4. joystick debounce. |
gatedClock | 19:0db1451d19ef | 14 | 5. LED and LCD displays. |
gatedClock | 19:0db1451d19ef | 15 | 6. BPM rate adjustable even when metronome is off. |
gatedClock | 19:0db1451d19ef | 16 | 7. BPM saturates at defined lower/upper bounds. |
gatedClock | 18:f19721f1069e | 17 | |
gatedClock | 0:1013288b8e43 | 18 | controls: |
gatedClock | 19:0db1451d19ef | 19 | 1. joystick-left - increase metronome rate. |
gatedClock | 19:0db1451d19ef | 20 | 2. joystick-right - decrease metronome rate. |
gatedClock | 19:0db1451d19ef | 21 | 3. joystick-down - start metronome. |
gatedClock | 19:0db1451d19ef | 22 | 4. joystick-up - stop metronome. |
gatedClock | 19:0db1451d19ef | 23 | 5. joystick-center - set metronome to 60BPM. |
gatedClock | 0:1013288b8e43 | 24 | |
gatedClock | 0:1013288b8e43 | 25 | notes: |
gatedClock | 19:0db1451d19ef | 26 | 1. adding the mbed-rtos library to this project prevents the |
gatedClock | 19:0db1451d19ef | 27 | LED from blinking and the LCD from displaying, even if |
gatedClock | 19:0db1451d19ef | 28 | there is no #include "rtos.h" statement. |
gatedClock | 19:0db1451d19ef | 29 | 2. i was considering having the BPM up/down ISRs set up self- |
gatedClock | 19:0db1451d19ef | 30 | ending threads for continuous button press for rapid rate |
gatedClock | 19:0db1451d19ef | 31 | change, but again, rtos.h was causing trouble. |
gatedClock | 19:0db1451d19ef | 32 | 3. I'm making use of disable-interrupts for bounce suppression. |
gatedClock | 19:0db1451d19ef | 33 | this could microscopically delay the metronome while its |
gatedClock | 19:0db1451d19ef | 34 | BPM is being adjusted, since I can't turn off only the |
gatedClock | 19:0db1451d19ef | 35 | interrupt involved with joystick input. |
gatedClock | 0:1013288b8e43 | 36 | |
gatedClock | 0:1013288b8e43 | 37 | testing: |
gatedClock | 19:0db1451d19ef | 38 | 1. start metronome - verify it blinks, and stops after a minute. |
gatedClock | 19:0db1451d19ef | 39 | 2. stop metronome - verity it stops metronome. |
gatedClock | 19:0db1451d19ef | 40 | 3. verify display indicates ON and OFF state. |
gatedClock | 19:0db1451d19ef | 41 | 4. verify display indicates BPM rate. |
gatedClock | 19:0db1451d19ef | 42 | 5. operate left/right joystick, inspect for BPM jumps (bounce). |
gatedClock | 19:0db1451d19ef | 43 | 6. verify lower/upper BPM bounds. (only lower-bound tested). |
gatedClock | 0:1013288b8e43 | 44 | -----includes-----------------------------------//----------------------------*/ |
gatedClock | 0:1013288b8e43 | 45 | #include "mbed.h" // mbed class. |
gatedClock | 15:7c0a94d2a439 | 46 | // #include "rtos.h" |
gatedClock | 14:fb4c76ac43a1 | 47 | #include "C12832_lcd.h" // LCD class. |
gatedClock | 27:c380923f02d8 | 48 | #include "PowerControl/PowerControl.h" |
gatedClock | 27:c380923f02d8 | 49 | #include "PowerControl/EthernetPowerControl.h" |
gatedClock | 21:eb692e90ae8d | 50 | |
gatedClock | 0:1013288b8e43 | 51 | //---defines------------------------------------//------------------------------ |
gatedClock | 0:1013288b8e43 | 52 | #define LCD1 lcd.locate(0, 0); // LCD line 1. |
gatedClock | 0:1013288b8e43 | 53 | #define LCD2 lcd.locate(0,11); // LCD line 2. |
gatedClock | 0:1013288b8e43 | 54 | #define LCD3 lcd.locate(0,22); // LCD line 3. |
gatedClock | 7:562f136c7681 | 55 | |
gatedClock | 0:1013288b8e43 | 56 | #define METROMAX 800 // max. beats per minute. |
gatedClock | 0:1013288b8e43 | 57 | #define METROMIN 8 // min. beats per minute. |
gatedClock | 19:0db1451d19ef | 58 | #define METROTIME 60.0 // metronome on-time in seconds. |
gatedClock | 0:1013288b8e43 | 59 | #define UDSAMPLERATE 0.1 // how often to sample U/D joystick. |
gatedClock | 0:1013288b8e43 | 60 | #define LCDSAMPLERATE 0.1 // how often to redraw the LCD. |
gatedClock | 0:1013288b8e43 | 61 | #define PULSELENGTH 0.0625 // how long the LED-on-time is. |
gatedClock | 10:4f2fa66cc430 | 62 | #define DEBOUNCE 0.16 // debounce pause duration in S. |
gatedClock | 0:1013288b8e43 | 63 | //--global_definitions--------------------------//------------------------------ |
gatedClock | 0:1013288b8e43 | 64 | //--global_variables----------------------------//------------------------------ |
gatedClock | 0:1013288b8e43 | 65 | float fMetroDelay; // time between ticks, in seconds. |
gatedClock | 0:1013288b8e43 | 66 | float fMetroDuty; // duration of metro high, in seconds. |
gatedClock | 0:1013288b8e43 | 67 | int dMetroBPM; // master parameter. |
gatedClock | 12:fab8e658ae76 | 68 | char cMetronomeOn; // 1 = allow blink. |
gatedClock | 0:1013288b8e43 | 69 | //--global_instances----------------------------//------------------------------ |
gatedClock | 18:f19721f1069e | 70 | C12832_LCD lcd; // LCD object. |
gatedClock | 0:1013288b8e43 | 71 | |
gatedClock | 18:f19721f1069e | 72 | InterruptIn iJoyStickUp (p15); // joystick up rising edge. |
gatedClock | 18:f19721f1069e | 73 | InterruptIn iJoyStickDown (p12); // joystick down rising edge. |
gatedClock | 18:f19721f1069e | 74 | InterruptIn iJoyStickLeft (p13); // joystick left rising edge. |
gatedClock | 18:f19721f1069e | 75 | InterruptIn iJoyStickRight (p16); // joystick right rising edge. |
gatedClock | 18:f19721f1069e | 76 | InterruptIn iJoyStickCenter(p14); // 1 if joystick middle pressed. |
gatedClock | 0:1013288b8e43 | 77 | |
gatedClock | 25:fe4425b11e3c | 78 | DigitalOut led0(LED4); // magnetron enunciator (not magnatron control) |
gatedClock | 25:fe4425b11e3c | 79 | DigitalOut led1(LED3); // carousel enunciator (not carousel control) |
gatedClock | 25:fe4425b11e3c | 80 | DigitalOut led2(LED2); // magnetron CONTROL. |
gatedClock | 25:fe4425b11e3c | 81 | DigitalOut led3(LED1); // carousel CONTROL. |
gatedClock | 0:1013288b8e43 | 82 | |
gatedClock | 0:1013288b8e43 | 83 | Ticker tickerMetronome; // blinking LED. |
gatedClock | 0:1013288b8e43 | 84 | Ticker tickerLCD; // display ticker. |
gatedClock | 0:1013288b8e43 | 85 | Timeout timeoutDutyCycle; // LED duty cycle delay. |
gatedClock | 12:fab8e658ae76 | 86 | Timeout timeoutMetronome; |
gatedClock | 24:fe4e288bbca3 | 87 | |
gatedClock | 24:fe4e288bbca3 | 88 | |
gatedClock | 0:1013288b8e43 | 89 | //-------prototypes-----------------------------//------------------------------ |
gatedClock | 0:1013288b8e43 | 90 | void initialization(); // initialize settings. |
gatedClock | 0:1013288b8e43 | 91 | void lcd_display(); // display on LCD. |
gatedClock | 18:f19721f1069e | 92 | void interrupt_service_M(); // metronome tick. |
gatedClock | 0:1013288b8e43 | 93 | void led3_off(); // attachable LED control. |
gatedClock | 0:1013288b8e43 | 94 | void led3_on(); // attachable LED control. |
gatedClock | 18:f19721f1069e | 95 | void ISR_up(); // stop metronome. |
gatedClock | 18:f19721f1069e | 96 | void ISR_down(); // start metronome. |
gatedClock | 18:f19721f1069e | 97 | void ISR_right_rising(); // decrease BPM. |
gatedClock | 18:f19721f1069e | 98 | void ISR_right_falling(); // bounce protection. |
gatedClock | 18:f19721f1069e | 99 | void ISR_left_rising(); // increase BPM. |
gatedClock | 18:f19721f1069e | 100 | void ISR_left_falling(); // bounce protection. |
gatedClock | 18:f19721f1069e | 101 | void ISR_center(); // set to 60BPM. |
gatedClock | 18:f19721f1069e | 102 | void turn_off_metronome(); // turn off blinker. |
gatedClock | 24:fe4e288bbca3 | 103 | |
gatedClock | 24:fe4e288bbca3 | 104 | |
gatedClock | 24:fe4e288bbca3 | 105 | |
gatedClock | 24:fe4e288bbca3 | 106 | class Watchdog { |
gatedClock | 24:fe4e288bbca3 | 107 | public: |
gatedClock | 24:fe4e288bbca3 | 108 | // Load timeout value in watchdog timer and enable |
gatedClock | 24:fe4e288bbca3 | 109 | void kick(float s) { |
gatedClock | 24:fe4e288bbca3 | 110 | LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK |
gatedClock | 24:fe4e288bbca3 | 111 | uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 |
gatedClock | 24:fe4e288bbca3 | 112 | LPC_WDT->WDTC = s * (float)clk; |
gatedClock | 24:fe4e288bbca3 | 113 | LPC_WDT->WDMOD = 0x3; // Enabled and Reset |
gatedClock | 24:fe4e288bbca3 | 114 | kick(); |
gatedClock | 24:fe4e288bbca3 | 115 | } |
gatedClock | 24:fe4e288bbca3 | 116 | // "kick" or "feed" the dog - reset the watchdog timer |
gatedClock | 24:fe4e288bbca3 | 117 | // by writing this required bit pattern |
gatedClock | 24:fe4e288bbca3 | 118 | void kick() { |
gatedClock | 24:fe4e288bbca3 | 119 | LPC_WDT->WDFEED = 0xAA; |
gatedClock | 24:fe4e288bbca3 | 120 | LPC_WDT->WDFEED = 0x55; |
gatedClock | 24:fe4e288bbca3 | 121 | } |
gatedClock | 24:fe4e288bbca3 | 122 | }; |
gatedClock | 24:fe4e288bbca3 | 123 | Watchdog wdt; // add a wachdog timer. |
gatedClock | 0:1013288b8e43 | 124 | //==============================================//============================== |
gatedClock | 0:1013288b8e43 | 125 | int main(void) |
gatedClock | 0:1013288b8e43 | 126 | { |
gatedClock | 25:fe4425b11e3c | 127 | |
gatedClock | 25:fe4425b11e3c | 128 | |
gatedClock | 25:fe4425b11e3c | 129 | // On reset, indicate a watchdog reset or a pushbutton reset on LED 4 or 3 |
gatedClock | 26:986b539170fc | 130 | if ((LPC_WDT->WDMOD >> 2) & 1) led0 = 1; else led1 = 1; |
gatedClock | 25:fe4425b11e3c | 131 | |
gatedClock | 25:fe4425b11e3c | 132 | |
gatedClock | 25:fe4425b11e3c | 133 | |
gatedClock | 25:fe4425b11e3c | 134 | |
gatedClock | 18:f19721f1069e | 135 | iJoyStickUp.rise (&ISR_up); // metronome stop. |
gatedClock | 18:f19721f1069e | 136 | iJoyStickDown.rise (&ISR_down); // metronome start. |
gatedClock | 11:e764ed79553a | 137 | |
gatedClock | 18:f19721f1069e | 138 | iJoyStickLeft.rise (&ISR_left_rising); // increase BPM. |
gatedClock | 18:f19721f1069e | 139 | iJoyStickLeft.fall (&ISR_left_falling); // anti-bounce. |
gatedClock | 10:4f2fa66cc430 | 140 | |
gatedClock | 18:f19721f1069e | 141 | iJoyStickRight.rise(&ISR_right_rising); // decrease BPM. |
gatedClock | 18:f19721f1069e | 142 | iJoyStickRight.fall(&ISR_right_falling); // anti-bounce. |
gatedClock | 10:4f2fa66cc430 | 143 | |
gatedClock | 18:f19721f1069e | 144 | iJoyStickCenter.rise(&ISR_center); // 60BPM. |
gatedClock | 6:bb5f989e3425 | 145 | |
gatedClock | 18:f19721f1069e | 146 | initialization(); // initialize variables. |
gatedClock | 6:bb5f989e3425 | 147 | |
gatedClock | 18:f19721f1069e | 148 | // metronome ticker. |
gatedClock | 15:7c0a94d2a439 | 149 | tickerMetronome.attach(&interrupt_service_M,fMetroDelay); |
gatedClock | 6:bb5f989e3425 | 150 | |
gatedClock | 15:7c0a94d2a439 | 151 | // LCD ticker. |
gatedClock | 15:7c0a94d2a439 | 152 | tickerLCD.attach(&lcd_display,LCDSAMPLERATE); |
gatedClock | 6:bb5f989e3425 | 153 | |
gatedClock | 26:986b539170fc | 154 | // #ifdef NOETHER |
gatedClock | 22:5d9bcc7f4440 | 155 | // Normal mbed power level for this setup is around 690mW |
gatedClock | 22:5d9bcc7f4440 | 156 | // assuming 5V used on Vin pin |
gatedClock | 22:5d9bcc7f4440 | 157 | // If you don't need networking... |
gatedClock | 22:5d9bcc7f4440 | 158 | // Power down Ethernet interface - saves around 175mW |
gatedClock | 22:5d9bcc7f4440 | 159 | // Also need to unplug network cable - just a cable sucks power |
gatedClock | 22:5d9bcc7f4440 | 160 | PHY_PowerDown(); |
gatedClock | 26:986b539170fc | 161 | //#endif |
gatedClock | 26:986b539170fc | 162 | |
gatedClock | 26:986b539170fc | 163 | wdt.kick(10.0); |
gatedClock | 22:5d9bcc7f4440 | 164 | |
gatedClock | 18:f19721f1069e | 165 | while(1) // all timer/interrupt driven. |
gatedClock | 6:bb5f989e3425 | 166 | { |
gatedClock | 23:99a13f79cdad | 167 | Sleep(); |
gatedClock | 26:986b539170fc | 168 | |
gatedClock | 26:986b539170fc | 169 | |
gatedClock | 26:986b539170fc | 170 | |
gatedClock | 6:bb5f989e3425 | 171 | } |
gatedClock | 0:1013288b8e43 | 172 | } |
gatedClock | 0:1013288b8e43 | 173 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 0:1013288b8e43 | 174 | void initialization(void) // program initializations. |
gatedClock | 0:1013288b8e43 | 175 | { |
gatedClock | 0:1013288b8e43 | 176 | dMetroBPM = 60; // initialize to 60BPM. |
gatedClock | 0:1013288b8e43 | 177 | fMetroDelay = 60.0 / (float) (dMetroBPM); |
gatedClock | 0:1013288b8e43 | 178 | fMetroDuty = PULSELENGTH; // initialize LED on-duration. |
gatedClock | 17:cd6c76be8046 | 179 | cMetronomeOn = 0; |
gatedClock | 0:1013288b8e43 | 180 | } |
gatedClock | 0:1013288b8e43 | 181 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 11:e764ed79553a | 182 | void ISR_left_rising(void) // increase BPM. |
gatedClock | 1:5f41e2df0e85 | 183 | { |
gatedClock | 18:f19721f1069e | 184 | __disable_irq(); // anti-bounce. |
gatedClock | 11:e764ed79553a | 185 | |
gatedClock | 11:e764ed79553a | 186 | dMetroBPM++; // increase BPM. |
gatedClock | 11:e764ed79553a | 187 | |
gatedClock | 12:fab8e658ae76 | 188 | // saturate metronome BPM. |
gatedClock | 12:fab8e658ae76 | 189 | if (dMetroBPM > METROMAX) dMetroBPM = METROMAX; |
gatedClock | 12:fab8e658ae76 | 190 | if (dMetroBPM < METROMIN) dMetroBPM = METROMIN; |
gatedClock | 20:64f1671c57ec | 191 | fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time. |
gatedClock | 12:fab8e658ae76 | 192 | |
gatedClock | 11:e764ed79553a | 193 | wait(DEBOUNCE); // debounce time. |
gatedClock | 11:e764ed79553a | 194 | |
gatedClock | 18:f19721f1069e | 195 | __enable_irq(); // safe by now. |
gatedClock | 1:5f41e2df0e85 | 196 | } |
gatedClock | 1:5f41e2df0e85 | 197 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 11:e764ed79553a | 198 | void ISR_left_falling(void) // ignore rising after falling edge. |
gatedClock | 11:e764ed79553a | 199 | { |
gatedClock | 18:f19721f1069e | 200 | __disable_irq(); // anti-bounce. |
gatedClock | 11:e764ed79553a | 201 | |
gatedClock | 11:e764ed79553a | 202 | wait(DEBOUNCE); // debounce time. |
gatedClock | 11:e764ed79553a | 203 | |
gatedClock | 18:f19721f1069e | 204 | __enable_irq(); // safe by now. |
gatedClock | 11:e764ed79553a | 205 | } |
gatedClock | 11:e764ed79553a | 206 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 10:4f2fa66cc430 | 207 | void ISR_right_rising(void) // decrease BPM. |
gatedClock | 4:67d958cc00e8 | 208 | { |
gatedClock | 18:f19721f1069e | 209 | __disable_irq(); // anti-bounce. |
gatedClock | 10:4f2fa66cc430 | 210 | |
gatedClock | 10:4f2fa66cc430 | 211 | dMetroBPM--; // decrease BPM. |
gatedClock | 4:67d958cc00e8 | 212 | |
gatedClock | 12:fab8e658ae76 | 213 | // saturate metronome BPM. |
gatedClock | 12:fab8e658ae76 | 214 | if (dMetroBPM > METROMAX) dMetroBPM = METROMAX; |
gatedClock | 12:fab8e658ae76 | 215 | if (dMetroBPM < METROMIN) dMetroBPM = METROMIN; |
gatedClock | 20:64f1671c57ec | 216 | fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time. |
gatedClock | 12:fab8e658ae76 | 217 | |
gatedClock | 10:4f2fa66cc430 | 218 | wait(DEBOUNCE); // debounce time. |
gatedClock | 9:ea97a69b9b93 | 219 | |
gatedClock | 18:f19721f1069e | 220 | __enable_irq(); // safe by now. |
gatedClock | 10:4f2fa66cc430 | 221 | } |
gatedClock | 10:4f2fa66cc430 | 222 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 10:4f2fa66cc430 | 223 | void ISR_right_falling(void) // ignore rising after falling edge. |
gatedClock | 10:4f2fa66cc430 | 224 | { |
gatedClock | 18:f19721f1069e | 225 | __disable_irq(); // anti-bounce. |
gatedClock | 10:4f2fa66cc430 | 226 | |
gatedClock | 10:4f2fa66cc430 | 227 | wait(DEBOUNCE); // debounce time. |
gatedClock | 10:4f2fa66cc430 | 228 | |
gatedClock | 18:f19721f1069e | 229 | __enable_irq(); // safe by now. |
gatedClock | 4:67d958cc00e8 | 230 | } |
gatedClock | 4:67d958cc00e8 | 231 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 18:f19721f1069e | 232 | void ISR_up(void) // turn off metronome. |
gatedClock | 1:5f41e2df0e85 | 233 | { |
gatedClock | 17:cd6c76be8046 | 234 | cMetronomeOn = 0; |
gatedClock | 1:5f41e2df0e85 | 235 | } |
gatedClock | 1:5f41e2df0e85 | 236 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 18:f19721f1069e | 237 | void ISR_down(void) // metronome on with timeout. |
gatedClock | 1:5f41e2df0e85 | 238 | { |
gatedClock | 12:fab8e658ae76 | 239 | cMetronomeOn = 1; |
gatedClock | 12:fab8e658ae76 | 240 | timeoutMetronome.detach(); |
gatedClock | 17:cd6c76be8046 | 241 | timeoutMetronome.attach(&turn_off_metronome,METROTIME); |
gatedClock | 1:5f41e2df0e85 | 242 | } |
gatedClock | 1:5f41e2df0e85 | 243 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 3:8ff0c9c853be | 244 | void ISR_center(void) // set BPM = 60. |
gatedClock | 1:5f41e2df0e85 | 245 | { |
gatedClock | 8:95f4f470ae28 | 246 | dMetroBPM = 60; |
gatedClock | 20:64f1671c57ec | 247 | fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time. |
gatedClock | 19:0db1451d19ef | 248 | tickerMetronome.detach(); // change BPM immediately. |
gatedClock | 19:0db1451d19ef | 249 | tickerMetronome.attach(&interrupt_service_M,fMetroDelay); |
gatedClock | 1:5f41e2df0e85 | 250 | } |
gatedClock | 1:5f41e2df0e85 | 251 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 0:1013288b8e43 | 252 | void lcd_display(void) // display metronome info. |
gatedClock | 0:1013288b8e43 | 253 | { |
gatedClock | 0:1013288b8e43 | 254 | lcd.cls(); // clear display. |
gatedClock | 0:1013288b8e43 | 255 | |
gatedClock | 0:1013288b8e43 | 256 | LCD1; // line 1. |
gatedClock | 17:cd6c76be8046 | 257 | |
gatedClock | 16:d7bbd641929c | 258 | if (cMetronomeOn) |
gatedClock | 16:d7bbd641929c | 259 | lcd.printf(" metronome ON"); |
gatedClock | 16:d7bbd641929c | 260 | else |
gatedClock | 16:d7bbd641929c | 261 | lcd.printf(" metronome OFF"); |
gatedClock | 0:1013288b8e43 | 262 | |
gatedClock | 0:1013288b8e43 | 263 | LCD2; // line 2. |
gatedClock | 0:1013288b8e43 | 264 | |
gatedClock | 0:1013288b8e43 | 265 | if (dMetroBPM == METROMIN) // BPM, with saturation notification. |
gatedClock | 0:1013288b8e43 | 266 | lcd.printf(" %5.2d BPM minimum",dMetroBPM); |
gatedClock | 0:1013288b8e43 | 267 | else |
gatedClock | 0:1013288b8e43 | 268 | if (dMetroBPM == METROMAX) |
gatedClock | 0:1013288b8e43 | 269 | lcd.printf(" %5.2d BPM maximum",dMetroBPM); |
gatedClock | 0:1013288b8e43 | 270 | else |
gatedClock | 0:1013288b8e43 | 271 | lcd.printf(" %5.2d BPM",dMetroBPM); |
gatedClock | 0:1013288b8e43 | 272 | |
gatedClock | 0:1013288b8e43 | 273 | LCD3; // line 3. |
gatedClock | 0:1013288b8e43 | 274 | |
gatedClock | 8:95f4f470ae28 | 275 | lcd.printf(" RTOS HW 4"); |
gatedClock | 0:1013288b8e43 | 276 | } |
gatedClock | 0:1013288b8e43 | 277 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 17:cd6c76be8046 | 278 | // this metronome tick ISR will self-adjust to the current user-selected |
gatedClock | 17:cd6c76be8046 | 279 | // metronome rate. that has to be done here, and at the start of the function, |
gatedClock | 17:cd6c76be8046 | 280 | // in order to maintain a constant phase and to prevent a beat-skip. |
gatedClock | 17:cd6c76be8046 | 281 | |
gatedClock | 17:cd6c76be8046 | 282 | void interrupt_service_M() // metronome tick. |
gatedClock | 17:cd6c76be8046 | 283 | { |
gatedClock | 17:cd6c76be8046 | 284 | if (cMetronomeOn) |
gatedClock | 17:cd6c76be8046 | 285 | { |
gatedClock | 18:f19721f1069e | 286 | tickerMetronome.detach(); // only one attachment. |
gatedClock | 17:cd6c76be8046 | 287 | tickerMetronome.attach(&interrupt_service_M,fMetroDelay); |
gatedClock | 17:cd6c76be8046 | 288 | led3_on(); |
gatedClock | 17:cd6c76be8046 | 289 | timeoutDutyCycle.attach(&led3_off,fMetroDuty); |
gatedClock | 17:cd6c76be8046 | 290 | } else led3_off(); |
gatedClock | 17:cd6c76be8046 | 291 | } |
gatedClock | 17:cd6c76be8046 | 292 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 18:f19721f1069e | 293 | void turn_off_metronome(void) // turn off metronome. |
gatedClock | 17:cd6c76be8046 | 294 | { |
gatedClock | 17:cd6c76be8046 | 295 | cMetronomeOn = 0; |
gatedClock | 17:cd6c76be8046 | 296 | } |
gatedClock | 17:cd6c76be8046 | 297 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 0:1013288b8e43 | 298 | void led3_off(void) {led3 = 0;} // turn off the LED. |
gatedClock | 0:1013288b8e43 | 299 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 0:1013288b8e43 | 300 | void led3_on( void) {led3 = 1;} // turn on the led. |
gatedClock | 15:7c0a94d2a439 | 301 | /*----------------------------------------------//----------------------------*/ |