arben sutter

Dependencies:   mbed

Fork of Oppgave7_1 by Sølibatgutt

Committer:
olemh88
Date:
Tue Oct 17 12:56:39 2017 +0000
Revision:
7:cd3eaa4ef912
Parent:
6:7c9aad508bf2
Oppgave 7_3;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreped 0:fe54cfab4520 1 #include "mbed.h"
andreped 0:fe54cfab4520 2
andreped 5:da09c341e484 3 AnalogIn noise(p19);
andreped 5:da09c341e484 4 DigitalOut Led1(LED1);
andreped 5:da09c341e484 5 DigitalOut Led2(LED2);
andreped 5:da09c341e484 6 DigitalOut Led3(LED3);
andreped 5:da09c341e484 7 DigitalOut Led4(LED4);
andreped 5:da09c341e484 8 DigitalIn bryter(p20);
olemh88 7:cd3eaa4ef912 9 Serial pc(USBTX, USBRX);
olemh88 7:cd3eaa4ef912 10
olemh88 7:cd3eaa4ef912 11 int svar;
andreped 5:da09c341e484 12
andreped 5:da09c341e484 13 Timer t1;
andreped 5:da09c341e484 14 BusOut bargraph(p21, p22, p23, p24, p25, p26);
andreped 5:da09c341e484 15 int noiseValue();
andreped 5:da09c341e484 16 int tid;
andreped 5:da09c341e484 17 Timer t2;
andreped 5:da09c341e484 18 int noiseValue(int low, int high);
andreped 0:fe54cfab4520 19
andreped 1:07b498c93e9a 20 int main()
andreped 1:07b498c93e9a 21 {
andreped 5:da09c341e484 22 srand(noiseValue(1, 1000));
olemh88 7:cd3eaa4ef912 23 pc.printf ("hvem er raskest av ole, Andreas og Arben\n");
olemh88 7:cd3eaa4ef912 24 pc.printf("LED1,2 og 3 vill lyse for Led4 lyser og du trykker \n");
andreped 0:fe54cfab4520 25 while(1) {
olemh88 7:cd3eaa4ef912 26 int start = 0;
olemh88 7:cd3eaa4ef912 27 t2.start();
andreped 5:da09c341e484 28 int tid = 0;
andreped 5:da09c341e484 29 Led1 = 1;
andreped 5:da09c341e484 30 wait(1);
andreped 5:da09c341e484 31 Led2 = 1;
andreped 5:da09c341e484 32 wait(1);
andreped 5:da09c341e484 33 Led3 = 1;
andreped 5:da09c341e484 34 wait(rand()%10 + 1);
andreped 5:da09c341e484 35 Led4 = 1;
olemh88 6:7c9aad508bf2 36 Led1 = 0;
olemh88 6:7c9aad508bf2 37 Led2 = 0;
olemh88 6:7c9aad508bf2 38 Led3 = 0;
olemh88 7:cd3eaa4ef912 39 t1.stop();
olemh88 7:cd3eaa4ef912 40 start = t2.read();
olemh88 7:cd3eaa4ef912 41 pc.printf("Tiden som har gatt til timeren starter: ");
olemh88 7:cd3eaa4ef912 42 pc.printf("%d", start);
olemh88 7:cd3eaa4ef912 43 if(bryter == 1) {
olemh88 7:cd3eaa4ef912 44 pc.printf("Na juksa du");
olemh88 7:cd3eaa4ef912 45 }
andreped 5:da09c341e484 46 t1.start();
andreped 5:da09c341e484 47
andreped 5:da09c341e484 48 while(bryter == 0) {
andreped 5:da09c341e484 49 wait_ms(1);
andreped 1:07b498c93e9a 50 }
olemh88 7:cd3eaa4ef912 51
andreped 5:da09c341e484 52 t1.stop();
andreped 5:da09c341e484 53 tid = t1.read_ms();
olemh88 7:cd3eaa4ef912 54 pc.printf ("\n din tid ble: ");
olemh88 7:cd3eaa4ef912 55 pc.printf ("%d", tid);
olemh88 7:cd3eaa4ef912 56 if(tid < 20) {
olemh88 7:cd3eaa4ef912 57 pc.printf("Veldig bra");
olemh88 7:cd3eaa4ef912 58 }
olemh88 7:cd3eaa4ef912 59 if (tid == (20 > 50)) {
olemh88 7:cd3eaa4ef912 60 pc.printf("Bra");
olemh88 7:cd3eaa4ef912 61 }
olemh88 7:cd3eaa4ef912 62 if(tid == (50 > 100)) {
olemh88 7:cd3eaa4ef912 63 pc.printf("Treigt");
olemh88 7:cd3eaa4ef912 64 }
olemh88 7:cd3eaa4ef912 65 if(tid > 100) {
olemh88 7:cd3eaa4ef912 66 pc.printf("Haha, du sutter");
olemh88 7:cd3eaa4ef912 67 }
andreped 0:fe54cfab4520 68 }
andreped 0:fe54cfab4520 69 }
andreped 5:da09c341e484 70
andreped 5:da09c341e484 71
andreped 5:da09c341e484 72
olemh88 7:cd3eaa4ef912 73
andreped 5:da09c341e484 74 int noiseValue(int low, int high)
andreped 5:da09c341e484 75 {
andreped 5:da09c341e484 76 uint16_t reading, rnd;
andreped 5:da09c341e484 77 reading = noise.read_u16() & 0xFFF; // keep 12 lsb
andreped 5:da09c341e484 78 reading *= 13;
andreped 5:da09c341e484 79 rnd = reading % (high - low + 1); // find remainder
andreped 5:da09c341e484 80 rnd += low;
andreped 5:da09c341e484 81 return rnd;
andreped 5:da09c341e484 82 }
andreped 5:da09c341e484 83