Dependencies:   Led-libary TextLCD mbed

main.cpp

Committer:
ladner
Date:
2016-01-21
Revision:
0:e97a6a69fe4b
Child:
1:0eaa7682f7e1

File content as of revision 0:e97a6a69fe4b:

#include "mbed.h"

I2C i2c(P0_5,P0_4);
Serial port(P0_19,P0_18);
BusOut myled(P1_8,P1_9,P1_10,P1_11,P1_0,P1_1,P1_3,P1_4,P1_6,P1_7,P1_12,P1_13);
AnalogIn ldr(P0_12);
AnalogIn poti(P0_11);
BusOut rgb(P0_9,P1_15,P0_21);
BusIn btn(P1_16,P0_23,P0_10,P0_15);
DigitalOut test (P0_13);
InterruptIn Button1(P1_16);
InterruptIn Button2(P0_23);

uint32_t ledbuffer[100];
uint32_t colourbuf[100];
char Index = 0;
char length = 60;
void writeled(uint32_t leddata); // Prototyp 
void writeledbit(char wert);
void next();
void last();
void output();
int main() 
{
    Button1.rise(&next);
    Button2.rise(&last);
    rgb = 7;
    colourbuf[0]=0x0000FF;//Grün
    colourbuf[1]=0x00FF00;//Rot
    colourbuf[2]=0xFF0000;//Blau
    colourbuf[3]=0x00FFFF;//Gelb
    colourbuf[4]=0x000000;//Aus
    output();
    while(1) ;
    while(1) 
    {
     writeled(0);
     test=0;
     wait(1);
    }
}

void output()
{
    for(char i = 0;i<Index;i++)
        writeled(0);
    writeled(colourbuf[3]);
    for(char i = Index;i<length-1;i++)
        writeled(0);
}

void next()
{
    if(Index<(length-1))
        Index++;
    output();
}

void last()
{
    if(Index>=0)
        Index--;
    output();
}
void writeled(uint32_t leddata)
{ int i;
       for(i=0;i<24;i++)
       {
       
         writeledbit(((leddata>>i)&0x000001)==0x000001);
       }
}
void writeledbit(char wert)  // Funktion schreibe bit
{
    int j;
    if(wert)
    {
        test=1; // data 1
        for(j=0;j<5;j++) 
        {
        __nop();    
        }
        test=0;
        for(j=0;j<1;j++)
        {
        __nop();   
        }
    }
    else
    {
        test=1; // data 0
        for(j=0;j<1;j++) 
        {
        __nop();    
        }
        test=0;
        for(j=0;j<5;j++)
        {
        __nop();   
        }
    }           
}