RTOS example - multiplex display on a 4-digit 7-segment LED tube driven by two 74HC595 shift registers. Hardware: NUCLEO_F446RE board with Arduino Multifunction Shield. The ShiftOut Library by Ollie Milton was applied.
Dependencies: mbed mbed-rtos ShiftOut
main.cpp@0:2ae7b6b39e93, 2022-02-24 (annotated)
- Committer:
- cspista
- Date:
- Thu Feb 24 07:52:29 2022 +0000
- Revision:
- 0:2ae7b6b39e93
RTOS example - multiplex display on a four digit, 7-segment display. ; Hardware: NUCLEO-F446RE board and Arduino Multifunctional Shield (3461B type 7-segment LED display driven by two 74HC595 shift registers).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cspista | 0:2ae7b6b39e93 | 1 | #include "mbed.h" |
cspista | 0:2ae7b6b39e93 | 2 | #include "rtos.h" |
cspista | 0:2ae7b6b39e93 | 3 | #include "ShiftOut.h" // Ollie Milton, https://os.mbed.com/users/ollie8/code/ShiftOut/ |
cspista | 0:2ae7b6b39e93 | 4 | uint8_t segment_data[4] = {0xFF, 0xFF, 0xFF, 0xFF}; // A frissítendő szegmenskép |
cspista | 0:2ae7b6b39e93 | 5 | /* Számjegyek (0 – 9) szegmensképe, negatív logikával */ |
cspista | 0:2ae7b6b39e93 | 6 | const uint8_t SEGMENT_MAP[]= {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; |
cspista | 0:2ae7b6b39e93 | 7 | /* Számjegy (1 - 4) kiválasztó jelek */ |
cspista | 0:2ae7b6b39e93 | 8 | const uint8_t SEGMENT_SELECT[] = {0x01, 0x02, 0x04, 0x08}; |
cspista | 0:2ae7b6b39e93 | 9 | |
cspista | 0:2ae7b6b39e93 | 10 | Thread thread; |
cspista | 0:2ae7b6b39e93 | 11 | DigitalOut buzzer(D3); |
cspista | 0:2ae7b6b39e93 | 12 | |
cspista | 0:2ae7b6b39e93 | 13 | void led2_thread() |
cspista | 0:2ae7b6b39e93 | 14 | { |
cspista | 0:2ae7b6b39e93 | 15 | ShiftOut display(D7, D8, D4); // clk=D7, data=D8, latch=D4) |
cspista | 0:2ae7b6b39e93 | 16 | while (true) { |
cspista | 0:2ae7b6b39e93 | 17 | for(int i = 0; i<4; i++) { |
cspista | 0:2ae7b6b39e93 | 18 | display.write(segment_data[i]); |
cspista | 0:2ae7b6b39e93 | 19 | display.write(SEGMENT_SELECT[i]); |
cspista | 0:2ae7b6b39e93 | 20 | Thread::wait(2); |
cspista | 0:2ae7b6b39e93 | 21 | } |
cspista | 0:2ae7b6b39e93 | 22 | } |
cspista | 0:2ae7b6b39e93 | 23 | } |
cspista | 0:2ae7b6b39e93 | 24 | |
cspista | 0:2ae7b6b39e93 | 25 | int main() |
cspista | 0:2ae7b6b39e93 | 26 | { |
cspista | 0:2ae7b6b39e93 | 27 | int n =0; |
cspista | 0:2ae7b6b39e93 | 28 | buzzer = true; |
cspista | 0:2ae7b6b39e93 | 29 | thread.start(led2_thread); |
cspista | 0:2ae7b6b39e93 | 30 | |
cspista | 0:2ae7b6b39e93 | 31 | while (true) { |
cspista | 0:2ae7b6b39e93 | 32 | segment_data[0] = SEGMENT_MAP[(n/1000) %10]; |
cspista | 0:2ae7b6b39e93 | 33 | segment_data[1] = SEGMENT_MAP[(n/100) % 10]; |
cspista | 0:2ae7b6b39e93 | 34 | segment_data[2] = SEGMENT_MAP[(n/10) % 10]; |
cspista | 0:2ae7b6b39e93 | 35 | segment_data[3] = SEGMENT_MAP[n % 10]; |
cspista | 0:2ae7b6b39e93 | 36 | n = n+1; |
cspista | 0:2ae7b6b39e93 | 37 | buzzer = (n%100) != 0; |
cspista | 0:2ae7b6b39e93 | 38 | Thread::wait(250); |
cspista | 0:2ae7b6b39e93 | 39 | } |
cspista | 0:2ae7b6b39e93 | 40 | } |