Prototype

Dependencies:   mbed ButtonEventDemo

Committer:
Kelrath1984
Date:
Mon Jan 13 17:33:47 2020 +0000
Revision:
14:0ccc3d5ca8ce
Parent:
13:024d65ed9c26
Child:
15:b7025faf0571
Lauflicht++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kelrath1984 12:e4ee1507e722 1 #include "mbed.h"
Kelrath1984 12:e4ee1507e722 2
Kelrath1984 12:e4ee1507e722 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 12:e4ee1507e722 10 //void printb(uint_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 13:024d65ed9c26 17
Kelrath1984 14:0ccc3d5ca8ce 18 lauflicht(0,400,anz=0)
Kelrath1984 14:0ccc3d5ca8ce 19 }
Kelrath1984 14:0ccc3d5ca8ce 20
Kelrath1984 14:0ccc3d5ca8ce 21 int lauflicht(bool richtung, int time, int &anz){
Kelrath1984 14:0ccc3d5ca8ce 22 int i=0;
Kelrath1984 14:0ccc3d5ca8ce 23 uint8_t lauf=0x01;
Kelrath1984 14:0ccc3d5ca8ce 24
Kelrath1984 14:0ccc3d5ca8ce 25 if(!richtung){
Kelrath1984 14:0ccc3d5ca8ce 26 lauf= 0x08;
Kelrath1984 14:0ccc3d5ca8ce 27 }
Kelrath1984 12:e4ee1507e722 28 while(1){
Kelrath1984 14:0ccc3d5ca8ce 29 nibbleLeds(lauf&0x0F);
Kelrath1984 14:0ccc3d5ca8ce 30 if(richtung){
Kelrath1984 14:0ccc3d5ca8ce 31 lauf=lauf<<1;
Kelrath1984 14:0ccc3d5ca8ce 32 if(lauf>8){
Kelrath1984 14:0ccc3d5ca8ce 33 lauf=0x01;
Kelrath1984 14:0ccc3d5ca8ce 34 }
Kelrath1984 12:e4ee1507e722 35 }
Kelrath1984 14:0ccc3d5ca8ce 36 else {
Kelrath1984 14:0ccc3d5ca8ce 37 lauf=lauf>>1;
Kelrath1984 14:0ccc3d5ca8ce 38 if(lauf==0){
Kelrath1984 14:0ccc3d5ca8ce 39 lauf=0x08;
Kelrath1984 14:0ccc3d5ca8ce 40 }
Kelrath1984 14:0ccc3d5ca8ce 41 }
Kelrath1984 14:0ccc3d5ca8ce 42 if(button){
Kelrath1984 14:0ccc3d5ca8ce 43 break;
Kelrath1984 14:0ccc3d5ca8ce 44 }
Kelrath1984 14:0ccc3d5ca8ce 45 wait_ms(time);
Kelrath1984 14:0ccc3d5ca8ce 46 anz++;
Kelrath1984 14:0ccc3d5ca8ce 47 }
Kelrath1984 14:0ccc3d5ca8ce 48 return anz;
Kelrath1984 14:0ccc3d5ca8ce 49
Kelrath1984 13:024d65ed9c26 50 }
Kelrath1984 14:0ccc3d5ca8ce 51
Kelrath1984 14:0ccc3d5ca8ce 52
Kelrath1984 13:024d65ed9c26 53
Kelrath1984 13:024d65ed9c26 54 void nibbleLeds(int value){
Kelrath1984 13:024d65ed9c26 55 myleds=value%16;
Kelrath1984 12:e4ee1507e722 56 }