Prototype

Dependencies:   mbed ButtonEventDemo

Committer:
Kelrath1984
Date:
Mon Jan 13 17:48:21 2020 +0000
Revision:
15:b7025faf0571
Parent:
14:0ccc3d5ca8ce
Child:
16:acf89f757b1b
Debugged Lauflicht

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