Mumin Hadzic / Mbed 2 deprecated TINF_TestProgramm

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #define BUTTON1 p14 
00003 //#define BUTTON1 A1
00004 
00005 int lauflicht(bool richtung,int time, int &anz);
00006 int modifyBit(int x, unsigned char position, bool State);
00007 void nibbleLeds(int value);
00008 void printb(uint8_t x);
00009 
00010 BusOut myleds(LED1,LED2,LED3,LED4);
00011 DigitalIn button(BUTTON1);
00012 
00013 const int INIT = 0x03;
00014 
00015 //**************************************************************
00016 int main() {
00017     int anzahl ,anz;
00018     uint8_t value = INIT;
00019     
00020     anzahl = lauflicht (true,400,anz=0);
00021     printf("anzahl=%d\n",anzahl);
00022 
00023 nibbleLeds(value);
00024 printb(value);
00025 value= modifyBit (value,2,1);
00026 printb(myleds);
00027 printb(modifyBit (INIT,3,1));
00028 wait(0.1);
00029 
00030 
00031 }
00032 //**************************************************************
00033 
00034 void nibbleLeds(int value) {
00035 myleds= value%16;
00036 }
00037 
00038 void printb(uint8_t x){
00039 for(int i=sizeof(x)<<3;i;i--)
00040     putchar('0'+((x>>(i-1))&1));
00041     printf("\n");
00042 
00043 }
00044 
00045 int lauflicht(bool richtung,int time, int &anz){
00046     int i;
00047     uint8_t lauf =0x01;
00048     
00049 if (!richtung)
00050 lauf =0x08;
00051 while(1){
00052     nibbleLeds(lauf&0x0F);
00053     if(richtung){
00054         lauf = lauf<<1;
00055         if(lauf>8)
00056         lauf = 0x01;
00057         }
00058     else {
00059         lauf=lauf >> 1;
00060         if(lauf == 0)
00061         lauf=0x08;
00062         }
00063     if(button)
00064         break;
00065     wait_ms(time);
00066     anz++;
00067     }
00068     
00069    return anz; 
00070     
00071     }
00072     int modifyBit(int x, unsigned char position, bool State) {
00073     
00074     int mask=1<< position;
00075     int state = int(State);
00076     return(x & ~mask) | ((state<<position)& mask);
00077     
00078     
00079     }