forked from remidebord/STM32F0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsevenseg_2.c
60 lines (46 loc) · 1.52 KB
/
sevenseg_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "main.h"
#include "SevenSeg.h"
// Ticker for base timer
Ticker tick(TIM16);
// Array of digital out (segment)
DigitalOut segment[] = {DigitalOut(PA0), DigitalOut(PA1), DigitalOut(PA4), DigitalOut(PF5),
DigitalOut(PF4), DigitalOut(PA2), DigitalOut(PA3), DigitalOut(PA5)};
// Array of digital out (digit)
DigitalOut digit[] = {DigitalOut(PB0, GPIO_OType_OD), DigitalOut(PB1, GPIO_OType_OD),
DigitalOut(PB2, GPIO_OType_OD), DigitalOut(PB10, GPIO_OType_OD),
DigitalOut(PB11, GPIO_OType_OD), DigitalOut(PB12, GPIO_OType_OD)};
// One seven segment is composed of an array of segment and one digit pin
SevenSeg sevenSeg0(segment, &digit[0]);
SevenSeg sevenSeg1(segment, &digit[1]);
SevenSeg sevenSeg2(segment, &digit[2]);
SevenSeg sevenSeg3(segment, &digit[3]);
SevenSeg sevenSeg4(segment, &digit[4]);
SevenSeg sevenSeg5(segment, &digit[5]);
// Create group of seven segment
SevenSegGroup sevenSegGroup;
int delay = 0;
int inc = 0;
void GlobalBaseTime(void)
{
sevenSegGroup.timer();
if(delay) delay--;
}
int main(void)
{
Systick_Init();
// Callback executed every 1 ms (1000 us)
tick.attach_us(&GlobalBaseTime, 1000);
// Add seven segment into a group
sevenSegGroup.add(&sevenSeg0);
sevenSegGroup.add(&sevenSeg1);
sevenSegGroup.add(&sevenSeg2);
sevenSegGroup.add(&sevenSeg3);
sevenSegGroup.add(&sevenSeg4);
sevenSegGroup.add(&sevenSeg5);
sevenSegGroup.scroll(200);
sevenSegGroup.set((char*)"Hello", 5);
while (1)
{
sevenSegGroup.update();
}
}