Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed C12832_lcd LM75B
main.cpp@10:2b0a9fc39109, 2013-09-07 (annotated)
- Committer:
- gatedClock
- Date:
- Sat Sep 07 20:33:38 2013 +0000
- Revision:
- 10:2b0a9fc39109
- Parent:
- 9:cfdb9aa5857c
- Child:
- 11:9cae003da12b
cull old code.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gatedClock | 0:fcca4db7b32a | 1 | /*----------------------------------------------//------------------------------ |
| gatedClock | 0:fcca4db7b32a | 2 | student : m-moore |
| gatedClock | 0:fcca4db7b32a | 3 | class : rtos |
| gatedClock | 10:2b0a9fc39109 | 4 | directory : RTOS_HW_07 |
| gatedClock | 0:fcca4db7b32a | 5 | file : main.cpp |
| gatedClock | 0:fcca4db7b32a | 6 | ----description---------------------------------//------------------------------ |
| gatedClock | 0:fcca4db7b32a | 7 | -----includes-----------------------------------//----------------------------*/ |
| gatedClock | 0:fcca4db7b32a | 8 | #include "mbed.h" // mbed class. |
| gatedClock | 10:2b0a9fc39109 | 9 | #include "rtos.h" // rtos class. |
| gatedClock | 10:2b0a9fc39109 | 10 | #include "C12832_lcd.h" // LCD class. |
| gatedClock | 0:fcca4db7b32a | 11 | //---defines------------------------------------//------------------------------ |
| gatedClock | 9:cfdb9aa5857c | 12 | #define LCD1 lcd.locate(0, 0); // LCD line 1. |
| gatedClock | 9:cfdb9aa5857c | 13 | #define LCD2 lcd.locate(0,11); // LCD line 2. |
| gatedClock | 9:cfdb9aa5857c | 14 | #define LCD3 lcd.locate(0,22); // LCD line 3. |
| gatedClock | 9:cfdb9aa5857c | 15 | |
| gatedClock | 10:2b0a9fc39109 | 16 | |
| gatedClock | 9:cfdb9aa5857c | 17 | #define DEBOUNCE 0.16 // debounce pause duration in S. |
| gatedClock | 0:fcca4db7b32a | 18 | //--global_definitions--------------------------//------------------------------ |
| gatedClock | 0:fcca4db7b32a | 19 | //--global_variables----------------------------//------------------------------ |
| gatedClock | 0:fcca4db7b32a | 20 | //--global_instances----------------------------//------------------------------ |
| gatedClock | 9:cfdb9aa5857c | 21 | C12832_LCD lcd; // LCD object. |
| gatedClock | 0:fcca4db7b32a | 22 | |
| gatedClock | 0:fcca4db7b32a | 23 | InterruptIn iJoyStickUp (p15); // joystick up rising edge. |
| gatedClock | 0:fcca4db7b32a | 24 | InterruptIn iJoyStickDown (p12); // joystick down rising edge. |
| gatedClock | 0:fcca4db7b32a | 25 | InterruptIn iJoyStickLeft (p13); // joystick left rising edge. |
| gatedClock | 0:fcca4db7b32a | 26 | InterruptIn iJoyStickRight (p16); // joystick right rising edge. |
| gatedClock | 0:fcca4db7b32a | 27 | InterruptIn iJoyStickCenter(p14); // 1 if joystick middle pressed. |
| gatedClock | 0:fcca4db7b32a | 28 | |
| gatedClock | 0:fcca4db7b32a | 29 | DigitalOut led3(LED1); // leftmost LED. |
| gatedClock | 0:fcca4db7b32a | 30 | |
| gatedClock | 9:cfdb9aa5857c | 31 | Ticker tickerMetronome; // blinking LED. |
| gatedClock | 9:cfdb9aa5857c | 32 | Ticker tickerLCD; // display ticker. |
| gatedClock | 9:cfdb9aa5857c | 33 | Timeout timeoutDutyCycle; // LED duty cycle delay. |
| gatedClock | 9:cfdb9aa5857c | 34 | Timeout timeoutMetronome; |
| gatedClock | 0:fcca4db7b32a | 35 | //-------prototypes-----------------------------//------------------------------ |
| gatedClock | 9:cfdb9aa5857c | 36 | void initialization(); // initialize settings. |
| gatedClock | 0:fcca4db7b32a | 37 | //==============================================//============================== |
| gatedClock | 0:fcca4db7b32a | 38 | int main(void) |
| gatedClock | 0:fcca4db7b32a | 39 | { |
| gatedClock | 9:cfdb9aa5857c | 40 | iJoyStickUp.rise (&ISR_up); // metronome stop. |
| gatedClock | 9:cfdb9aa5857c | 41 | iJoyStickDown.rise (&ISR_down); // metronome start. |
| gatedClock | 9:cfdb9aa5857c | 42 | |
| gatedClock | 9:cfdb9aa5857c | 43 | iJoyStickLeft.rise (&ISR_left_rising); // increase BPM. |
| gatedClock | 9:cfdb9aa5857c | 44 | iJoyStickLeft.fall (&ISR_left_falling); // anti-bounce. |
| gatedClock | 9:cfdb9aa5857c | 45 | |
| gatedClock | 9:cfdb9aa5857c | 46 | iJoyStickRight.rise(&ISR_right_rising); // decrease BPM. |
| gatedClock | 9:cfdb9aa5857c | 47 | iJoyStickRight.fall(&ISR_right_falling); // anti-bounce. |
| gatedClock | 7:9fbd1d540863 | 48 | |
| gatedClock | 9:cfdb9aa5857c | 49 | iJoyStickCenter.rise(&ISR_center); // 60BPM. |
| gatedClock | 9:cfdb9aa5857c | 50 | |
| gatedClock | 9:cfdb9aa5857c | 51 | initialization(); // initialize variables. |
| gatedClock | 0:fcca4db7b32a | 52 | |
| gatedClock | 9:cfdb9aa5857c | 53 | // metronome ticker. |
| gatedClock | 9:cfdb9aa5857c | 54 | tickerMetronome.attach(&interrupt_service_M,fMetroDelay); |
| gatedClock | 9:cfdb9aa5857c | 55 | |
| gatedClock | 9:cfdb9aa5857c | 56 | // LCD ticker. |
| gatedClock | 9:cfdb9aa5857c | 57 | tickerLCD.attach(&lcd_display,LCDSAMPLERATE); |
| gatedClock | 0:fcca4db7b32a | 58 | |
| gatedClock | 0:fcca4db7b32a | 59 | while(1) // all timer/interrupt driven. |
| gatedClock | 0:fcca4db7b32a | 60 | { |
| gatedClock | 9:cfdb9aa5857c | 61 | wait(10.0); |
| gatedClock | 0:fcca4db7b32a | 62 | } |
| gatedClock | 0:fcca4db7b32a | 63 | } |
| gatedClock | 0:fcca4db7b32a | 64 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 0:fcca4db7b32a | 65 | void initialization(void) // program initializations. |
| gatedClock | 0:fcca4db7b32a | 66 | { |
| gatedClock | 10:2b0a9fc39109 | 67 | |
| gatedClock | 0:fcca4db7b32a | 68 | } |
| gatedClock | 0:fcca4db7b32a | 69 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 70 | void ISR_left_rising(void) // increase BPM. |
| gatedClock | 1:9188d4668a88 | 71 | { |
| gatedClock | 9:cfdb9aa5857c | 72 | __disable_irq(); // anti-bounce. |
| gatedClock | 9:cfdb9aa5857c | 73 | |
| gatedClock | 9:cfdb9aa5857c | 74 | dMetroBPM++; // increase BPM. |
| gatedClock | 9:cfdb9aa5857c | 75 | |
| gatedClock | 9:cfdb9aa5857c | 76 | // saturate metronome BPM. |
| gatedClock | 9:cfdb9aa5857c | 77 | if (dMetroBPM > METROMAX) dMetroBPM = METROMAX; |
| gatedClock | 9:cfdb9aa5857c | 78 | if (dMetroBPM < METROMIN) dMetroBPM = METROMIN; |
| gatedClock | 9:cfdb9aa5857c | 79 | fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time. |
| gatedClock | 9:cfdb9aa5857c | 80 | |
| gatedClock | 9:cfdb9aa5857c | 81 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 9:cfdb9aa5857c | 82 | |
| gatedClock | 9:cfdb9aa5857c | 83 | __enable_irq(); // safe by now. |
| gatedClock | 1:9188d4668a88 | 84 | } |
| gatedClock | 1:9188d4668a88 | 85 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 86 | void ISR_left_falling(void) // ignore rising after falling edge. |
| gatedClock | 1:9188d4668a88 | 87 | { |
| gatedClock | 9:cfdb9aa5857c | 88 | __disable_irq(); // anti-bounce. |
| gatedClock | 9:cfdb9aa5857c | 89 | |
| gatedClock | 9:cfdb9aa5857c | 90 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 9:cfdb9aa5857c | 91 | |
| gatedClock | 9:cfdb9aa5857c | 92 | __enable_irq(); // safe by now. |
| gatedClock | 1:9188d4668a88 | 93 | } |
| gatedClock | 1:9188d4668a88 | 94 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 95 | void ISR_right_rising(void) // decrease BPM. |
| gatedClock | 1:9188d4668a88 | 96 | { |
| gatedClock | 9:cfdb9aa5857c | 97 | __disable_irq(); // anti-bounce. |
| gatedClock | 9:cfdb9aa5857c | 98 | |
| gatedClock | 9:cfdb9aa5857c | 99 | dMetroBPM--; // decrease BPM. |
| gatedClock | 9:cfdb9aa5857c | 100 | |
| gatedClock | 9:cfdb9aa5857c | 101 | // saturate metronome BPM. |
| gatedClock | 9:cfdb9aa5857c | 102 | if (dMetroBPM > METROMAX) dMetroBPM = METROMAX; |
| gatedClock | 9:cfdb9aa5857c | 103 | if (dMetroBPM < METROMIN) dMetroBPM = METROMIN; |
| gatedClock | 9:cfdb9aa5857c | 104 | fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time. |
| gatedClock | 9:cfdb9aa5857c | 105 | |
| gatedClock | 9:cfdb9aa5857c | 106 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 9:cfdb9aa5857c | 107 | |
| gatedClock | 9:cfdb9aa5857c | 108 | __enable_irq(); // safe by now. |
| gatedClock | 1:9188d4668a88 | 109 | } |
| gatedClock | 1:9188d4668a88 | 110 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 111 | void ISR_right_falling(void) // ignore rising after falling edge. |
| gatedClock | 1:9188d4668a88 | 112 | { |
| gatedClock | 9:cfdb9aa5857c | 113 | __disable_irq(); // anti-bounce. |
| gatedClock | 9:cfdb9aa5857c | 114 | |
| gatedClock | 9:cfdb9aa5857c | 115 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 9:cfdb9aa5857c | 116 | |
| gatedClock | 9:cfdb9aa5857c | 117 | __enable_irq(); // safe by now. |
| gatedClock | 9:cfdb9aa5857c | 118 | } |
| gatedClock | 9:cfdb9aa5857c | 119 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 120 | void ISR_up(void) // turn off metronome. |
| gatedClock | 9:cfdb9aa5857c | 121 | { |
| gatedClock | 9:cfdb9aa5857c | 122 | cMetronomeOn = 0; |
| gatedClock | 1:9188d4668a88 | 123 | } |
| gatedClock | 1:9188d4668a88 | 124 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 125 | void ISR_down(void) // metronome on with timeout. |
| gatedClock | 1:9188d4668a88 | 126 | { |
| gatedClock | 9:cfdb9aa5857c | 127 | cMetronomeOn = 1; |
| gatedClock | 9:cfdb9aa5857c | 128 | timeoutMetronome.detach(); |
| gatedClock | 9:cfdb9aa5857c | 129 | timeoutMetronome.attach(&turn_off_metronome,METROTIME); |
| gatedClock | 1:9188d4668a88 | 130 | } |
| gatedClock | 1:9188d4668a88 | 131 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 9:cfdb9aa5857c | 132 | void ISR_center(void) // set BPM = 60. |
| gatedClock | 2:665ffa57031f | 133 | { |
| gatedClock | 9:cfdb9aa5857c | 134 | dMetroBPM = 60; |
| gatedClock | 9:cfdb9aa5857c | 135 | fMetroDelay = 60.0 / (float) (dMetroBPM); // calculate Ticker delay time. |
| gatedClock | 9:cfdb9aa5857c | 136 | tickerMetronome.detach(); // change BPM immediately. |
| gatedClock | 9:cfdb9aa5857c | 137 | tickerMetronome.attach(&interrupt_service_M,fMetroDelay); |
| gatedClock | 2:665ffa57031f | 138 | } |
| gatedClock | 2:665ffa57031f | 139 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 10:2b0a9fc39109 | 140 |