Prototype

Dependencies:   mbed ButtonEventDemo

Committer:
Kelrath1984
Date:
Mon Jan 13 17:58:06 2020 +0000
Revision:
16:acf89f757b1b
Parent:
15:b7025faf0571
Child:
17:080847c64d0b
Printb++

Who changed what in which revision?

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