main lauflicht test

Dependencies:   mbed

Committer:
rob117
Date:
Mon Jan 13 17:54:02 2020 +0000
Revision:
6:41d274ed6967
Parent:
5:c2a8fd8dede5
letzte funktion

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rob117 0:696d6bf92662 1 #include "mbed.h"
rob117 1:5756521122a8 2 #define BUTTON1 p14
rob117 0:696d6bf92662 3
rob117 0:696d6bf92662 4
rob117 2:54c01dcbfbc8 5 void nibbleLeds(int value);
rob117 4:8d806106dbb0 6 void printb(uint8_t x);
rob117 5:c2a8fd8dede5 7 int lauflicht(bool richtung, int time, int &anz);
rob117 6:41d274ed6967 8 int modifyBit(int x, unsigned char position, bool State);
rob117 3:f82a2b7fb723 9
rob117 0:696d6bf92662 10 BusOut myleds(LED1, LED2, LED3, LED4);
rob117 0:696d6bf92662 11 DigitalIn button(BUTTON1);
rob117 0:696d6bf92662 12
rob117 2:54c01dcbfbc8 13
rob117 2:54c01dcbfbc8 14
rob117 2:54c01dcbfbc8 15
rob117 2:54c01dcbfbc8 16
rob117 0:696d6bf92662 17 const int INIT = 0x03;
rob117 0:696d6bf92662 18
rob117 0:696d6bf92662 19 int main() {
rob117 3:f82a2b7fb723 20 int anzahl, anz;
rob117 3:f82a2b7fb723 21 uint8_t value = INIT;
rob117 3:f82a2b7fb723 22
rob117 5:c2a8fd8dede5 23 anzahl = lauflicht(true, 400, anz=0);
rob117 5:c2a8fd8dede5 24 printf("anzahl= %d\n", anzahl);
rob117 5:c2a8fd8dede5 25
rob117 3:f82a2b7fb723 26 nibbleLeds(value);
rob117 4:8d806106dbb0 27 printb(value);
rob117 6:41d274ed6967 28 value = modifyBit(value, 2, 1);
rob117 6:41d274ed6967 29 printb(myleds);
rob117 6:41d274ed6967 30 printb(modifyBit(INIT, 3, 1));
rob117 3:f82a2b7fb723 31 wait(0.1);
rob117 0:696d6bf92662 32
rob117 0:696d6bf92662 33
rob117 2:54c01dcbfbc8 34 }
rob117 1:5756521122a8 35
rob117 2:54c01dcbfbc8 36 void nibbleLeds(int value){
rob117 2:54c01dcbfbc8 37 myleds = value%16;
rob117 2:54c01dcbfbc8 38 }
rob117 2:54c01dcbfbc8 39
rob117 4:8d806106dbb0 40 void printb(uint8_t x){
rob117 4:8d806106dbb0 41 for(int i=sizeof(x)<<3; i; i--)
rob117 4:8d806106dbb0 42 putchar('0'+((x>>(i-1))&1));
rob117 4:8d806106dbb0 43 printf("\n");
rob117 4:8d806106dbb0 44
rob117 4:8d806106dbb0 45
rob117 4:8d806106dbb0 46 }
rob117 5:c2a8fd8dede5 47
rob117 5:c2a8fd8dede5 48 int lauflicht(bool richtung, int time, int &anz){
rob117 5:c2a8fd8dede5 49 int i;
rob117 5:c2a8fd8dede5 50 uint8_t lauf = 0x01;
rob117 5:c2a8fd8dede5 51
rob117 5:c2a8fd8dede5 52 if(!richtung)
rob117 5:c2a8fd8dede5 53 lauf = 0x08;
rob117 5:c2a8fd8dede5 54 while(1){
rob117 5:c2a8fd8dede5 55 nibbleLeds(lauf&0x0F);
rob117 5:c2a8fd8dede5 56 if(richtung){
rob117 5:c2a8fd8dede5 57 lauf = lauf << 1;
rob117 5:c2a8fd8dede5 58 if(lauf>8)
rob117 5:c2a8fd8dede5 59 lauf = 0x01;
rob117 5:c2a8fd8dede5 60 }
rob117 5:c2a8fd8dede5 61 else {
rob117 5:c2a8fd8dede5 62 lauf = lauf >>1;
rob117 5:c2a8fd8dede5 63 if(lauf == 0)
rob117 5:c2a8fd8dede5 64 lauf = 0x08;
rob117 5:c2a8fd8dede5 65 }
rob117 5:c2a8fd8dede5 66 if(button)
rob117 5:c2a8fd8dede5 67 break;
rob117 5:c2a8fd8dede5 68 wait_ms(time);
rob117 5:c2a8fd8dede5 69 anz++;
rob117 5:c2a8fd8dede5 70
rob117 5:c2a8fd8dede5 71 }
rob117 5:c2a8fd8dede5 72 return anz;
rob117 5:c2a8fd8dede5 73
rob117 6:41d274ed6967 74 }
rob117 6:41d274ed6967 75 int modifyBit(int x, uint8_t position, bool State){
rob117 6:41d274ed6967 76 int mask = 1 << position;
rob117 6:41d274ed6967 77 int state = int(State);
rob117 6:41d274ed6967 78 return (x & ~mask) | ((State << position) & mask);
rob117 6:41d274ed6967 79
rob117 6:41d274ed6967 80
rob117 6:41d274ed6967 81
rob117 5:c2a8fd8dede5 82 }