Thomas Kemmer
/
CarreraDigitalStartLight
main.cpp@0:0c3677cbbda0, 2017-08-28 (annotated)
- Committer:
- tkem
- Date:
- Mon Aug 28 09:49:12 2017 +0000
- Revision:
- 0:0c3677cbbda0
Imported into mbed online compiler.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tkem | 0:0c3677cbbda0 | 1 | #include "mbed.h" |
tkem | 0:0c3677cbbda0 | 2 | |
tkem | 0:0c3677cbbda0 | 3 | #include "CarreraDigitalControlUnit.h" |
tkem | 0:0c3677cbbda0 | 4 | |
tkem | 0:0c3677cbbda0 | 5 | int main() { |
tkem | 0:0c3677cbbda0 | 6 | // set digital pin 2 as input - make sure it does not deliver more |
tkem | 0:0c3677cbbda0 | 7 | // than 5V or 3.3V, depending on platform! |
tkem | 0:0c3677cbbda0 | 8 | CarreraDigitalControlUnit cu(D2); |
tkem | 0:0c3677cbbda0 | 9 | |
tkem | 0:0c3677cbbda0 | 10 | // set digital pins 3 to 7 as outputs (connected to LEDs) |
tkem | 0:0c3677cbbda0 | 11 | DigitalOut led1(D3); |
tkem | 0:0c3677cbbda0 | 12 | DigitalOut led2(D4); |
tkem | 0:0c3677cbbda0 | 13 | DigitalOut led3(D5); |
tkem | 0:0c3677cbbda0 | 14 | DigitalOut led4(D6); |
tkem | 0:0c3677cbbda0 | 15 | DigitalOut led5(D7); |
tkem | 0:0c3677cbbda0 | 16 | |
tkem | 0:0c3677cbbda0 | 17 | while (true) { |
tkem | 0:0c3677cbbda0 | 18 | uint8_t prog[3]; |
tkem | 0:0c3677cbbda0 | 19 | int data = cu.read(); |
tkem | 0:0c3677cbbda0 | 20 | if (cu.split_programming_word(data, prog)) { |
tkem | 0:0c3677cbbda0 | 21 | // prog = { command, value, address } |
tkem | 0:0c3677cbbda0 | 22 | if (prog[0] == 16 && prog[2] == 7) { |
tkem | 0:0c3677cbbda0 | 23 | led1 = prog[1] >= 1; |
tkem | 0:0c3677cbbda0 | 24 | led2 = prog[1] >= 2; |
tkem | 0:0c3677cbbda0 | 25 | led3 = prog[1] >= 3; |
tkem | 0:0c3677cbbda0 | 26 | led4 = prog[1] >= 4; |
tkem | 0:0c3677cbbda0 | 27 | led5 = prog[1] >= 5; |
tkem | 0:0c3677cbbda0 | 28 | } |
tkem | 0:0c3677cbbda0 | 29 | } |
tkem | 0:0c3677cbbda0 | 30 | } |
tkem | 0:0c3677cbbda0 | 31 | } |