test programm

Dependencies:   mbed

Committer:
adiam
Date:
Mon Jan 13 17:50:53 2020 +0000
Revision:
4:3af6714f01d6
Parent:
3:0a89775f58f1
Child:
5:630756c3af86
5.funktion

Who changed what in which revision?

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