Oppgave 2.1
Dependencies: mbed
Revision 5:da09c341e484, committed 2017-10-17
- Comitter:
- andreped
- Date:
- Tue Oct 17 11:36:30 2017 +0000
- Parent:
- 3:cdd8af1b6f39
- Commit message:
- Oppgave 7.1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r cdd8af1b6f39 -r da09c341e484 main.cpp --- a/main.cpp Tue Sep 05 11:25:10 2017 +0000 +++ b/main.cpp Tue Oct 17 11:36:30 2017 +0000 @@ -1,17 +1,52 @@ #include "mbed.h" -BusOut teller(p21, p22, p23, p24, p25, p26); +AnalogIn noise(p19); +DigitalOut Led1(LED1); +DigitalOut Led2(LED2); +DigitalOut Led3(LED3); +DigitalOut Led4(LED4); +DigitalIn bryter(p20); + +Timer t1; +BusOut bargraph(p21, p22, p23, p24, p25, p26); +int noiseValue(); +int tid; +Timer t2; +int noiseValue(int low, int high); int main() { + srand(noiseValue(1, 1000)); while(1) { - int x = teller; - if ( x = 63) { - x = 0; - } else { - x >= 63; - x = ++; - wait(0.25); + int tid = 0; + Led1 = 1; + wait(1); + Led2 = 1; + wait(1); + Led3 = 1; + wait(rand()%10 + 1); + Led4 = 1; + t1.start(); + + while(bryter == 0) { + wait_ms(1); } + + t1.stop(); + tid = t1.read_ms(); + bargraph = tid / 10; } } + + + +int noiseValue(int low, int high) +{ + uint16_t reading, rnd; + reading = noise.read_u16() & 0xFFF; // keep 12 lsb + reading *= 13; + rnd = reading % (high - low + 1); // find remainder + rnd += low; + return rnd; +} +