Main

Dependencies:   mbed

Committer:
riad
Date:
Mon Jan 13 17:17:58 2020 +0000
Revision:
2:47d9c6c7eb9e
Parent:
1:a3d6a365dc15
Child:
3:f80e65dd4ee3
lauflicht

Who changed what in which revision?

UserRevisionLine numberNew contents of line
riad 0:7925301ed8e4 1 #include "mbed.h"
riad 0:7925301ed8e4 2 #define BUTTON1 p14
riad 0:7925301ed8e4 3 #define BUTTON! A1
riad 0:7925301ed8e4 4
riad 0:7925301ed8e4 5 int modifyBit(int x, unsingned char position, bool State);
riad 0:7925301ed8e4 6 int lauflicht(bool richtung, int time, int &anz);
riad 0:7925301ed8e4 7 void nibbleLeds(int value);
riad 2:47d9c6c7eb9e 8 void printb(uint8_t x);
riad 0:7925301ed8e4 9
riad 0:7925301ed8e4 10
riad 0:7925301ed8e4 11 BusOut myleds(LED1,LED2,LED3,LED4);
riad 0:7925301ed8e4 12 DigitalIn button(BUTTON1);
riad 0:7925301ed8e4 13
riad 0:7925301ed8e4 14 const int INIT = 0x03;
riad 0:7925301ed8e4 15
riad 2:47d9c6c7eb9e 16 int main ()
riad 2:47d9c6c7eb9e 17 {
riad 0:7925301ed8e4 18 int anzahl, anz;
riad 0:7925301ed8e4 19 uint8_t value = INIT;
riad 2:47d9c6c7eb9e 20
riad 2:47d9c6c7eb9e 21
riad 1:a3d6a365dc15 22 }
riad 1:a3d6a365dc15 23
riad 2:47d9c6c7eb9e 24 int modifyBit (int x, uint8_t position, bool State)
riad 2:47d9c6c7eb9e 25 {
riad 1:a3d6a365dc15 26 int mask = 1 << position;
riad 1:a3d6a365dc15 27 int state = int(State);
riad 1:a3d6a365dc15 28 return (x & ~mask) | ((state << position) & mask);
riad 2:47d9c6c7eb9e 29 }
riad 2:47d9c6c7eb9e 30
riad 2:47d9c6c7eb9e 31 int lauflicht (bool richtung, int time, int &anz)
riad 2:47d9c6c7eb9e 32 {
riad 2:47d9c6c7eb9e 33 int i;
riad 2:47d9c6c7eb9e 34 uint8_t lauf = 0x01;
riad 2:47d9c6c7eb9e 35
riad 2:47d9c6c7eb9e 36 if(!richtung)
riad 2:47d9c6c7eb9e 37 lauf = 0x08;
riad 2:47d9c6c7eb9e 38 while(1) {
riad 2:47d9c6c7eb9e 39 nibbleLeds(lauf&0x0F);
riad 2:47d9c6c7eb9e 40 if(richtung) {
riad 2:47d9c6c7eb9e 41 lauf = lauf << 1;
riad 2:47d9c6c7eb9e 42 if(lauf > 8)
riad 2:47d9c6c7eb9e 43 lauf = 0x01;
riad 2:47d9c6c7eb9e 44 } else {
riad 2:47d9c6c7eb9e 45 lauf = lauf >> 1;
riad 2:47d9c6c7eb9e 46 if(lauf == 0)
riad 2:47d9c6c7eb9e 47 lauf = 0x08;
riad 2:47d9c6c7eb9e 48 }
riad 2:47d9c6c7eb9e 49 if(button)
riad 2:47d9c6c7eb9e 50 break;
riad 2:47d9c6c7eb9e 51 wait_ms(time);
riad 2:47d9c6c7eb9e 52 anz++;
riad 2:47d9c6c7eb9e 53 }
riad 2:47d9c6c7eb9e 54 return anz;
riad 2:47d9c6c7eb9e 55 }