![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
arben sutter
Dependencies: mbed
Fork of Oppgave7_1 by
main.cpp
- Committer:
- olemh88
- Date:
- 2017-10-17
- Revision:
- 7:cd3eaa4ef912
- Parent:
- 6:7c9aad508bf2
File content as of revision 7:cd3eaa4ef912:
#include "mbed.h" AnalogIn noise(p19); DigitalOut Led1(LED1); DigitalOut Led2(LED2); DigitalOut Led3(LED3); DigitalOut Led4(LED4); DigitalIn bryter(p20); Serial pc(USBTX, USBRX); int svar; 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)); pc.printf ("hvem er raskest av ole, Andreas og Arben\n"); pc.printf("LED1,2 og 3 vill lyse for Led4 lyser og du trykker \n"); while(1) { int start = 0; t2.start(); int tid = 0; Led1 = 1; wait(1); Led2 = 1; wait(1); Led3 = 1; wait(rand()%10 + 1); Led4 = 1; Led1 = 0; Led2 = 0; Led3 = 0; t1.stop(); start = t2.read(); pc.printf("Tiden som har gatt til timeren starter: "); pc.printf("%d", start); if(bryter == 1) { pc.printf("Na juksa du"); } t1.start(); while(bryter == 0) { wait_ms(1); } t1.stop(); tid = t1.read_ms(); pc.printf ("\n din tid ble: "); pc.printf ("%d", tid); if(tid < 20) { pc.printf("Veldig bra"); } if (tid == (20 > 50)) { pc.printf("Bra"); } if(tid == (50 > 100)) { pc.printf("Treigt"); } if(tid > 100) { pc.printf("Haha, du sutter"); } } } 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; }