test programm

Dependencies:   mbed

Committer:
adiam
Date:
Mon Jan 13 18:03:21 2020 +0000
Revision:
5:630756c3af86
Parent:
4:3af6714f01d6
6.funk

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 5:630756c3af86 6 int modifyBit(int x,unsigned char position,bool State);
adiam 5:630756c3af86 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 5:630756c3af86 22 anzahl=lauflicht(true,400,anz=0);
adiam 5:630756c3af86 23 printf("anzahl=%d\n",anzahl);
adiam 5:630756c3af86 24
adiam 1:54883b2b3a1f 25 nibbleLeds(value);
adiam 2:d1f995867839 26 printb(value);
adiam 5:630756c3af86 27 value=modifyBit(value,2,1);
adiam 5:630756c3af86 28 printb(myleds);
adiam 5:630756c3af86 29 printb(modifyBit(INIT,3,1));
adiam 1:54883b2b3a1f 30 wait(0.1);
adiam 1:54883b2b3a1f 31
adiam 0:1988d79fc609 32 }
adiam 0:1988d79fc609 33
adiam 4:3af6714f01d6 34 int modifyBit(int x,uint8_t position,bool State) {
adiam 4:3af6714f01d6 35 int mask=1<<position;
adiam 4:3af6714f01d6 36 int state=int(State);
adiam 4:3af6714f01d6 37 return(x & ~mask) | ((state <<position) & mask);
adiam 4:3af6714f01d6 38 }
adiam 4:3af6714f01d6 39
adiam 4:3af6714f01d6 40
adiam 4:3af6714f01d6 41
adiam 3:0a89775f58f1 42 int lauflicht(bool richtung,int time,int &anz) {
adiam 3:0a89775f58f1 43
adiam 3:0a89775f58f1 44 int i;
adiam 3:0a89775f58f1 45 uint8_t lauf=0x01;
adiam 3:0a89775f58f1 46
adiam 3:0a89775f58f1 47 if(!richtung)
adiam 3:0a89775f58f1 48 lauf=0x08;
adiam 3:0a89775f58f1 49 while(1) {
adiam 3:0a89775f58f1 50 nibbleLeds(lauf&0x0F);
adiam 3:0a89775f58f1 51 if(richtung) {
adiam 3:0a89775f58f1 52 lauf=lauf <<1;
adiam 3:0a89775f58f1 53 if(lauf>8)
adiam 3:0a89775f58f1 54 lauf=0x01;
adiam 3:0a89775f58f1 55 }
adiam 3:0a89775f58f1 56 else {
adiam 3:0a89775f58f1 57 lauf=lauf>>1;
adiam 3:0a89775f58f1 58 if(lauf==0)
adiam 3:0a89775f58f1 59 lauf=0x08;
adiam 3:0a89775f58f1 60 }
adiam 3:0a89775f58f1 61 if(button)
adiam 3:0a89775f58f1 62 break;
adiam 3:0a89775f58f1 63 wait_ms(time);
adiam 3:0a89775f58f1 64 anz++;
adiam 3:0a89775f58f1 65 }
adiam 3:0a89775f58f1 66 return anz;
adiam 3:0a89775f58f1 67 }
adiam 3:0a89775f58f1 68
adiam 3:0a89775f58f1 69
adiam 2:d1f995867839 70 void printb(uint8_t x) {
adiam 2:d1f995867839 71 for(int i=sizeof(x)<<3;i;i--)
adiam 2:d1f995867839 72 putchar('0'+((x>>(i-1))&1));
adiam 2:d1f995867839 73 printf("\n");
adiam 2:d1f995867839 74 }
adiam 5:630756c3af86 75
adiam 1:54883b2b3a1f 76 void nibbleLeds(int value) {
adiam 1:54883b2b3a1f 77 myleds=value%16;
adiam 1:54883b2b3a1f 78 }