Main

Dependencies:   mbed

Committer:
muminhadzic
Date:
Mon Jan 13 17:48:03 2020 +0000
Revision:
3:aaaaf9f23f46
Parent:
2:8784f9c96dca
Child:
4:f3985b5c3549
lauflicht

Who changed what in which revision?

UserRevisionLine numberNew contents of line
muminhadzic 0:4c39745fe0c2 1 #include "mbed.h"
muminhadzic 0:4c39745fe0c2 2 #define BUTTON1 p14
muminhadzic 0:4c39745fe0c2 3 //#define BUTTON1 A1
muminhadzic 0:4c39745fe0c2 4
muminhadzic 3:aaaaf9f23f46 5 int lauflicht(bool richtung,int time, int &anz);
muminhadzic 0:4c39745fe0c2 6 //int modifyBit(int x, unsigned char position, bool State);
muminhadzic 1:2513045fcb59 7 void nibbleLeds(int value);
muminhadzic 2:8784f9c96dca 8 void printb(uint8_t x);
muminhadzic 0:4c39745fe0c2 9
muminhadzic 0:4c39745fe0c2 10 BusOut myleds(LED1,LED2,LED3,LED4);
muminhadzic 0:4c39745fe0c2 11 DigitalIn button(BUTTON1);
muminhadzic 0:4c39745fe0c2 12
muminhadzic 0:4c39745fe0c2 13 const int INIT = 0x03;
muminhadzic 0:4c39745fe0c2 14
muminhadzic 1:2513045fcb59 15 //**************************************************************
muminhadzic 0:4c39745fe0c2 16 int main() {
muminhadzic 3:aaaaf9f23f46 17 int anzahl ,anz;
muminhadzic 3:aaaaf9f23f46 18 uint8_t value = INIT;
muminhadzic 1:2513045fcb59 19
muminhadzic 3:aaaaf9f23f46 20 anzahl = lauflicht (true,400,anz=0);
muminhadzic 3:aaaaf9f23f46 21 printf("anzahl=%d\n",anzahl);
muminhadzic 3:aaaaf9f23f46 22
muminhadzic 1:2513045fcb59 23 nibbleLeds(value);
muminhadzic 1:2513045fcb59 24 wait(0.1);
muminhadzic 2:8784f9c96dca 25 printb(value);
muminhadzic 0:4c39745fe0c2 26
muminhadzic 0:4c39745fe0c2 27 }
muminhadzic 1:2513045fcb59 28 //**************************************************************
muminhadzic 0:4c39745fe0c2 29
muminhadzic 1:2513045fcb59 30 void nibbleLeds(int value) {
muminhadzic 1:2513045fcb59 31 myleds= value%16;
muminhadzic 2:8784f9c96dca 32 }
muminhadzic 2:8784f9c96dca 33
muminhadzic 2:8784f9c96dca 34 void printb(uint8_t x){
muminhadzic 2:8784f9c96dca 35 for(int i=sizeof(x)<<3;i;i--)
muminhadzic 2:8784f9c96dca 36 putchar('0'+((x>>(i-1))&1));
muminhadzic 2:8784f9c96dca 37 printf("\n");
muminhadzic 2:8784f9c96dca 38
muminhadzic 3:aaaaf9f23f46 39 }
muminhadzic 3:aaaaf9f23f46 40
muminhadzic 3:aaaaf9f23f46 41 int lauflicht(bool richtung,int time, int &anz){
muminhadzic 3:aaaaf9f23f46 42 int i;
muminhadzic 3:aaaaf9f23f46 43 uint8_t lauf =0x01;
muminhadzic 3:aaaaf9f23f46 44
muminhadzic 3:aaaaf9f23f46 45 if (!richtung)
muminhadzic 3:aaaaf9f23f46 46 lauf =0x08;
muminhadzic 3:aaaaf9f23f46 47 while(1){
muminhadzic 3:aaaaf9f23f46 48 nibbleLeds(lauf&0x0F);
muminhadzic 3:aaaaf9f23f46 49 if(richtung){
muminhadzic 3:aaaaf9f23f46 50 lauf = lauf<<1;
muminhadzic 3:aaaaf9f23f46 51 if(lauf>8)
muminhadzic 3:aaaaf9f23f46 52 lauf = 0x01;
muminhadzic 3:aaaaf9f23f46 53 }
muminhadzic 3:aaaaf9f23f46 54 else {
muminhadzic 3:aaaaf9f23f46 55 lauf=lauf >> 1;
muminhadzic 3:aaaaf9f23f46 56 if(lauf == 0)
muminhadzic 3:aaaaf9f23f46 57 lauf=0x08;
muminhadzic 3:aaaaf9f23f46 58 }
muminhadzic 3:aaaaf9f23f46 59 if(button)
muminhadzic 3:aaaaf9f23f46 60 break;
muminhadzic 3:aaaaf9f23f46 61 wait_ms(time);
muminhadzic 3:aaaaf9f23f46 62 anz++;
muminhadzic 3:aaaaf9f23f46 63 }
muminhadzic 3:aaaaf9f23f46 64
muminhadzic 3:aaaaf9f23f46 65 return anz;
muminhadzic 3:aaaaf9f23f46 66
muminhadzic 3:aaaaf9f23f46 67 }