Nucleo SPI Sequencer
Dependencies: AverageAnalogIn N5110 Nucleo_rtos_UI_Test PinDetect RotaryEncoder Sequence mbed-rtos mbed FilterController
Fork of Nucleo_rtos_UI_Test by
main.cpp@0:468e49a35876, 2016-05-24 (annotated)
- Committer:
- ryood
- Date:
- Tue May 24 22:33:03 2016 +0000
- Revision:
- 0:468e49a35876
- Child:
- 2:8cc6dff1d7fd
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryood | 0:468e49a35876 | 1 | #include "mbed.h" |
ryood | 0:468e49a35876 | 2 | #include "rtos.h" |
ryood | 0:468e49a35876 | 3 | #include "N5110.h" |
ryood | 0:468e49a35876 | 4 | #include "RotaryEncoder.h" |
ryood | 0:468e49a35876 | 5 | |
ryood | 0:468e49a35876 | 6 | // SPI2 Morpho |
ryood | 0:468e49a35876 | 7 | // VCC, SCE, RST, D/C, MOSI, SCLK, LED |
ryood | 0:468e49a35876 | 8 | N5110 Lcd(PA_12, PB_1, PB_2, PB_12, PB_15, PB_13, PA_11); |
ryood | 0:468e49a35876 | 9 | RotaryEncoder RotEnc(D2, D3); |
ryood | 0:468e49a35876 | 10 | DigitalOut Led1(LED1); |
ryood | 0:468e49a35876 | 11 | |
ryood | 0:468e49a35876 | 12 | void LedThread(void const *argument) |
ryood | 0:468e49a35876 | 13 | { |
ryood | 0:468e49a35876 | 14 | while (true) { |
ryood | 0:468e49a35876 | 15 | Led1 = !Led1; |
ryood | 0:468e49a35876 | 16 | Thread::wait(500); |
ryood | 0:468e49a35876 | 17 | } |
ryood | 0:468e49a35876 | 18 | } |
ryood | 0:468e49a35876 | 19 | |
ryood | 0:468e49a35876 | 20 | void updateLCD(int count) |
ryood | 0:468e49a35876 | 21 | { |
ryood | 0:468e49a35876 | 22 | char buff[20]; |
ryood | 0:468e49a35876 | 23 | |
ryood | 0:468e49a35876 | 24 | Lcd.clear(); |
ryood | 0:468e49a35876 | 25 | Lcd.printString("RTOS UI Test.", 0, 0); |
ryood | 0:468e49a35876 | 26 | sprintf(buff, "count: %d", count); |
ryood | 0:468e49a35876 | 27 | Lcd.printString(buff, 0, 1); |
ryood | 0:468e49a35876 | 28 | Lcd.refresh(); |
ryood | 0:468e49a35876 | 29 | } |
ryood | 0:468e49a35876 | 30 | |
ryood | 0:468e49a35876 | 31 | int main() |
ryood | 0:468e49a35876 | 32 | { |
ryood | 0:468e49a35876 | 33 | int count, prevCount; |
ryood | 0:468e49a35876 | 34 | bool isDirty = false; |
ryood | 0:468e49a35876 | 35 | |
ryood | 0:468e49a35876 | 36 | printf("\n\n\r*** RTOS UI Test ***\r\n"); |
ryood | 0:468e49a35876 | 37 | |
ryood | 0:468e49a35876 | 38 | // Init devices |
ryood | 0:468e49a35876 | 39 | RotEnc.setInterval(500); |
ryood | 0:468e49a35876 | 40 | |
ryood | 0:468e49a35876 | 41 | Lcd.init(); |
ryood | 0:468e49a35876 | 42 | Lcd.normalMode(); // normal colour mode |
ryood | 0:468e49a35876 | 43 | Lcd.setBrightness(0.5); // put LED backlight on 50% |
ryood | 0:468e49a35876 | 44 | |
ryood | 0:468e49a35876 | 45 | // Thread sart |
ryood | 0:468e49a35876 | 46 | Thread thread1(LedThread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); |
ryood | 0:468e49a35876 | 47 | |
ryood | 0:468e49a35876 | 48 | // Main loop |
ryood | 0:468e49a35876 | 49 | prevCount = -1; |
ryood | 0:468e49a35876 | 50 | while (true) { |
ryood | 0:468e49a35876 | 51 | count = RotEnc.getVal(); |
ryood | 0:468e49a35876 | 52 | if (prevCount != count) { |
ryood | 0:468e49a35876 | 53 | prevCount = count; |
ryood | 0:468e49a35876 | 54 | isDirty = true; |
ryood | 0:468e49a35876 | 55 | } |
ryood | 0:468e49a35876 | 56 | if (isDirty) { |
ryood | 0:468e49a35876 | 57 | updateLCD(count); |
ryood | 0:468e49a35876 | 58 | isDirty = false; |
ryood | 0:468e49a35876 | 59 | } |
ryood | 0:468e49a35876 | 60 | } |
ryood | 0:468e49a35876 | 61 | } |