Lorenz Sommer
/
photo_8leds
test
Diff: main.cpp
- Revision:
- 0:5d9f7b6a935e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 09 17:53:23 2020 +0000 @@ -0,0 +1,42 @@ + +#include "mbed.h" +#include "platform/mbed_thread.h" +#include "ShiftReg.h" + +#define BLINKING_RATE_MS + + + // Setup + //DigitalOut data(D2); + //DigitalOut clock(D4); + //DigitalOut latch(D3); + AnalogIn light(A0); + char leds = 0; + ShiftReg reg(D2,D3,D4); + + +void updateRegister() + { + reg.ShiftByte(leds); + reg.Latch(); + wait(0.2); + } + + +int main() +{ + while (true) + { + float input = light.read(); + int leds_lit = input*8; + + for (int i = 0; i < leds_lit; i++) + { + leds = leds + (1 << i); // sets the i'th bit + } + + updateRegister(); + } +} + +