arben sutter
Dependencies: mbed
Fork of Oppgave7_1 by
main.cpp
00001 #include "mbed.h" 00002 00003 AnalogIn noise(p19); 00004 DigitalOut Led1(LED1); 00005 DigitalOut Led2(LED2); 00006 DigitalOut Led3(LED3); 00007 DigitalOut Led4(LED4); 00008 DigitalIn bryter(p20); 00009 Serial pc(USBTX, USBRX); 00010 00011 int svar; 00012 00013 Timer t1; 00014 BusOut bargraph(p21, p22, p23, p24, p25, p26); 00015 int noiseValue(); 00016 int tid; 00017 Timer t2; 00018 int noiseValue(int low, int high); 00019 00020 int main() 00021 { 00022 srand(noiseValue(1, 1000)); 00023 pc.printf ("hvem er raskest av ole, Andreas og Arben\n"); 00024 pc.printf("LED1,2 og 3 vill lyse for Led4 lyser og du trykker \n"); 00025 while(1) { 00026 int start = 0; 00027 t2.start(); 00028 int tid = 0; 00029 Led1 = 1; 00030 wait(1); 00031 Led2 = 1; 00032 wait(1); 00033 Led3 = 1; 00034 wait(rand()%10 + 1); 00035 Led4 = 1; 00036 Led1 = 0; 00037 Led2 = 0; 00038 Led3 = 0; 00039 t1.stop(); 00040 start = t2.read(); 00041 pc.printf("Tiden som har gatt til timeren starter: "); 00042 pc.printf("%d", start); 00043 if(bryter == 1) { 00044 pc.printf("Na juksa du"); 00045 } 00046 t1.start(); 00047 00048 while(bryter == 0) { 00049 wait_ms(1); 00050 } 00051 00052 t1.stop(); 00053 tid = t1.read_ms(); 00054 pc.printf ("\n din tid ble: "); 00055 pc.printf ("%d", tid); 00056 if(tid < 20) { 00057 pc.printf("Veldig bra"); 00058 } 00059 if (tid == (20 > 50)) { 00060 pc.printf("Bra"); 00061 } 00062 if(tid == (50 > 100)) { 00063 pc.printf("Treigt"); 00064 } 00065 if(tid > 100) { 00066 pc.printf("Haha, du sutter"); 00067 } 00068 } 00069 } 00070 00071 00072 00073 00074 int noiseValue(int low, int high) 00075 { 00076 uint16_t reading, rnd; 00077 reading = noise.read_u16() & 0xFFF; // keep 12 lsb 00078 reading *= 13; 00079 rnd = reading % (high - low + 1); // find remainder 00080 rnd += low; 00081 return rnd; 00082 } 00083
Generated on Wed Jul 13 2022 03:23:03 by
1.7.2
