Dependencies:   TextLCD mbed

Fork of Mbed-Mensch-1 by Projekte_werkstatt

Committer:
ladner
Date:
Thu Jan 21 13:10:55 2016 +0000
Revision:
0:e97a6a69fe4b
Child:
1:0eaa7682f7e1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ladner 0:e97a6a69fe4b 1 #include "mbed.h"
ladner 0:e97a6a69fe4b 2
ladner 0:e97a6a69fe4b 3 I2C i2c(P0_5,P0_4);
ladner 0:e97a6a69fe4b 4 Serial port(P0_19,P0_18);
ladner 0:e97a6a69fe4b 5 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);
ladner 0:e97a6a69fe4b 6 AnalogIn ldr(P0_12);
ladner 0:e97a6a69fe4b 7 AnalogIn poti(P0_11);
ladner 0:e97a6a69fe4b 8 BusOut rgb(P0_9,P1_15,P0_21);
ladner 0:e97a6a69fe4b 9 BusIn btn(P1_16,P0_23,P0_10,P0_15);
ladner 0:e97a6a69fe4b 10 DigitalOut test (P0_13);
ladner 0:e97a6a69fe4b 11 InterruptIn Button1(P1_16);
ladner 0:e97a6a69fe4b 12 InterruptIn Button2(P0_23);
ladner 0:e97a6a69fe4b 13
ladner 0:e97a6a69fe4b 14 uint32_t ledbuffer[100];
ladner 0:e97a6a69fe4b 15 uint32_t colourbuf[100];
ladner 0:e97a6a69fe4b 16 char Index = 0;
ladner 0:e97a6a69fe4b 17 char length = 60;
ladner 0:e97a6a69fe4b 18 void writeled(uint32_t leddata); // Prototyp
ladner 0:e97a6a69fe4b 19 void writeledbit(char wert);
ladner 0:e97a6a69fe4b 20 void next();
ladner 0:e97a6a69fe4b 21 void last();
ladner 0:e97a6a69fe4b 22 void output();
ladner 0:e97a6a69fe4b 23 int main()
ladner 0:e97a6a69fe4b 24 {
ladner 0:e97a6a69fe4b 25 Button1.rise(&next);
ladner 0:e97a6a69fe4b 26 Button2.rise(&last);
ladner 0:e97a6a69fe4b 27 rgb = 7;
ladner 0:e97a6a69fe4b 28 colourbuf[0]=0x0000FF;//Grün
ladner 0:e97a6a69fe4b 29 colourbuf[1]=0x00FF00;//Rot
ladner 0:e97a6a69fe4b 30 colourbuf[2]=0xFF0000;//Blau
ladner 0:e97a6a69fe4b 31 colourbuf[3]=0x00FFFF;//Gelb
ladner 0:e97a6a69fe4b 32 colourbuf[4]=0x000000;//Aus
ladner 0:e97a6a69fe4b 33 output();
ladner 0:e97a6a69fe4b 34 while(1) ;
ladner 0:e97a6a69fe4b 35 while(1)
ladner 0:e97a6a69fe4b 36 {
ladner 0:e97a6a69fe4b 37 writeled(0);
ladner 0:e97a6a69fe4b 38 test=0;
ladner 0:e97a6a69fe4b 39 wait(1);
ladner 0:e97a6a69fe4b 40 }
ladner 0:e97a6a69fe4b 41 }
ladner 0:e97a6a69fe4b 42
ladner 0:e97a6a69fe4b 43 void output()
ladner 0:e97a6a69fe4b 44 {
ladner 0:e97a6a69fe4b 45 for(char i = 0;i<Index;i++)
ladner 0:e97a6a69fe4b 46 writeled(0);
ladner 0:e97a6a69fe4b 47 writeled(colourbuf[3]);
ladner 0:e97a6a69fe4b 48 for(char i = Index;i<length-1;i++)
ladner 0:e97a6a69fe4b 49 writeled(0);
ladner 0:e97a6a69fe4b 50 }
ladner 0:e97a6a69fe4b 51
ladner 0:e97a6a69fe4b 52 void next()
ladner 0:e97a6a69fe4b 53 {
ladner 0:e97a6a69fe4b 54 if(Index<(length-1))
ladner 0:e97a6a69fe4b 55 Index++;
ladner 0:e97a6a69fe4b 56 output();
ladner 0:e97a6a69fe4b 57 }
ladner 0:e97a6a69fe4b 58
ladner 0:e97a6a69fe4b 59 void last()
ladner 0:e97a6a69fe4b 60 {
ladner 0:e97a6a69fe4b 61 if(Index>=0)
ladner 0:e97a6a69fe4b 62 Index--;
ladner 0:e97a6a69fe4b 63 output();
ladner 0:e97a6a69fe4b 64 }
ladner 0:e97a6a69fe4b 65 void writeled(uint32_t leddata)
ladner 0:e97a6a69fe4b 66 { int i;
ladner 0:e97a6a69fe4b 67 for(i=0;i<24;i++)
ladner 0:e97a6a69fe4b 68 {
ladner 0:e97a6a69fe4b 69
ladner 0:e97a6a69fe4b 70 writeledbit(((leddata>>i)&0x000001)==0x000001);
ladner 0:e97a6a69fe4b 71 }
ladner 0:e97a6a69fe4b 72 }
ladner 0:e97a6a69fe4b 73 void writeledbit(char wert) // Funktion schreibe bit
ladner 0:e97a6a69fe4b 74 {
ladner 0:e97a6a69fe4b 75 int j;
ladner 0:e97a6a69fe4b 76 if(wert)
ladner 0:e97a6a69fe4b 77 {
ladner 0:e97a6a69fe4b 78 test=1; // data 1
ladner 0:e97a6a69fe4b 79 for(j=0;j<5;j++)
ladner 0:e97a6a69fe4b 80 {
ladner 0:e97a6a69fe4b 81 __nop();
ladner 0:e97a6a69fe4b 82 }
ladner 0:e97a6a69fe4b 83 test=0;
ladner 0:e97a6a69fe4b 84 for(j=0;j<1;j++)
ladner 0:e97a6a69fe4b 85 {
ladner 0:e97a6a69fe4b 86 __nop();
ladner 0:e97a6a69fe4b 87 }
ladner 0:e97a6a69fe4b 88 }
ladner 0:e97a6a69fe4b 89 else
ladner 0:e97a6a69fe4b 90 {
ladner 0:e97a6a69fe4b 91 test=1; // data 0
ladner 0:e97a6a69fe4b 92 for(j=0;j<1;j++)
ladner 0:e97a6a69fe4b 93 {
ladner 0:e97a6a69fe4b 94 __nop();
ladner 0:e97a6a69fe4b 95 }
ladner 0:e97a6a69fe4b 96 test=0;
ladner 0:e97a6a69fe4b 97 for(j=0;j<5;j++)
ladner 0:e97a6a69fe4b 98 {
ladner 0:e97a6a69fe4b 99 __nop();
ladner 0:e97a6a69fe4b 100 }
ladner 0:e97a6a69fe4b 101 }
ladner 0:e97a6a69fe4b 102 }