This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
/
main.cpp
75 lines (64 loc) · 1.85 KB
/
main.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <xpcc/architecture/platform.hpp>
#include <xpcc/processing.hpp>
#include "leds.hpp"
#include "animations.hpp"
// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
// connect the Timer Channels to the LEDs
Board::LedGreen::connect(Timer4::Channel1);
Board::LedOrange::connect(Timer4::Channel2);
Board::LedRed::connect(Timer4::Channel3);
Board::LedBlue::connect(Timer4::Channel4);
// set up the timer for 16bit PWM
Timer4::enable();
Timer4::setMode(Timer4::Mode::UpCounter);
// 42 MHz / 1 / 2^16 ~ 640 Hz refresh rate
Timer4::setPrescaler(1);
Timer4::setOverflow(65535);
// configure the output channels
Timer4::configureOutputChannel(1, Timer2::OutputCompareMode::Pwm, 0);
Timer4::configureOutputChannel(2, Timer2::OutputCompareMode::Pwm, 0);
Timer4::configureOutputChannel(3, Timer2::OutputCompareMode::Pwm, 0);
Timer4::configureOutputChannel(4, Timer2::OutputCompareMode::Pwm, 0);
Timer4::applyAndReset();
// start the timer
Timer4::start();
// set the animation mode for autoreverse the keyframes
animator.setMode(xpcc::ui::KeyFrameAnimationMode::Autoreverse);
// set the indicator period change to 15s
pulsePeriod.setPeriod(10000);
// pulse between 0.5s and 5s.
pulsePeriod.setRange(500, 5000);
indicator.setRange(0, 100);
// start all animations indefinitely
pulse.start();
indicator.start();
strobe.start();
animator.start();
pulsePeriod.start();
while (1)
{
// update all standard animations
pulse.update();
indicator.update();
strobe.update();
// udpate the custoom animations
animator.update();
pulsePeriod.update();
// update all leds
blue.update();
red.update();
orange.update();
green.update();
// udpate the custom animator
if (periodAnimator.update())
{
// a new value is available
pulse.setPeriod(period);
}
}
return 0;
}