INFO: Dieses Forum nutzt Cookies...
Cookies sind für den Betrieb des Forums unverzichtbar. Mit der Nutzung des Forums erklärst Du dich damit einverstanden, dass wir Cookies verwenden.

Es wird in jedem Fall ein Cookie gesetzt um diesen Hinweis nicht mehr zu erhalten. Desweiteren setzen wir Google Adsense und Google Analytics ein.

Antwort schreiben 
 
Themabewertung:
  • 1 Bewertungen - 5 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Hilfe bei einer Füllstandsanzeige für eine Zisterne
03.06.2015, 16:20
Beitrag #25
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
Hallo Ihr beiden,
ich stelle den ganzen Sketsch ein
Code:
int pingPin = 12;
          int inPin = 11;
          int ledPin = 10;
    
    
    
    
    /*
    Basic Grafix.ino
     *
     * Created: 9/20/2014 5:09:28 PM
     * Author: BasisV12
     */
    
    //Bus Pins (Arduino digital Pin numbers)
    #define LCD_D0_PIN 8
    #define LCD_D1_PIN 9
    #define LCD_D2_PIN 2
    #define LCD_D3_PIN 3
    #define LCD_D4_PIN 4
    #define LCD_D5_PIN 5
    #define LCD_D6_PIN 6
    #define LCD_D7_PIN 7
    
    //Control Pins (here: Analog pins A0..A4)
    #define LCD_RST    A4
    #define LCD_CS     A3
    #define LCD_RS     A2
    #define LCD_WR     A1
    #define LCD_RD     A0
    
    #define BIT0_MSK_8BIT  B00000001
    #define BIT1_MSK_8BIT  B00000010
    #define BIT2_MSK_8BIT  B00000100
    #define BIT3_MSK_8BIT  B00001000
    #define BIT4_MSK_8BIT  B00010000
    #define BIT5_MSK_8BIT  B00100000
    #define BIT6_MSK_8BIT  B01000000
    #define BIT7_MSK_8BIT  B10000000
    
    #define LCD_RST_LOW()  digitalWrite(LCD_RST, LOW)
    #define LCD_RST_HIGH() digitalWrite(LCD_RST, HIGH)
    
    #define LCD_CS_LOW()  digitalWrite(LCD_CS, LOW)
    #define LCD_CS_HIGH() digitalWrite(LCD_CS, HIGH)
    
    #define LCD_RS_LOW()  digitalWrite(LCD_RS, LOW)
    #define LCD_RS_HIGH() digitalWrite(LCD_RS, HIGH)
    
    #define LCD_WR_LOW()  digitalWrite(LCD_WR, LOW)
    #define LCD_WR_HIGH() digitalWrite(LCD_WR, HIGH)
    
    #define LCD_RD_LOW()  digitalWrite(LCD_RD, LOW)
    #define LCD_RD_HIGH() digitalWrite(LCD_RD, HIGH)
    
    //Basic Colors
    #define    LCD_BLACK                   0x0000
    #define    LCD_BLUE                    0x001F
    #define    LCD_RED                     0xF800
    #define    LCD_GREEN                   0x07E0
    #define LCD_CYAN                    0x07FF
    #define LCD_MAGENTA                 0xF81F
    #define LCD_YELLOW                  0xFFE0
    #define LCD_WHITE                   0xFFFF
        
        
    //Other Colors
    #define LCD_CYAN            0x07ff
    #define LCD_BRIGHT_RED      0xf810
    #define LCD_GRAY1           0x8410
    #define LCD_GRAY2           0x4208
    
    //TFT resolution 240*320
    #define LCD_MIN_X       0
    #define LCD_MIN_Y       0
    #define LCD_MAX_X       240
    #define LCD_MAX_Y       320
    
    
    #define swap_uint16_t(a, b) { uint16_t t = a; a = b; b = t; }
    
    #if 1 //Basics
    
    
    void LCD_BusPinsAsOutput()
    {
         pinMode(LCD_D0_PIN,OUTPUT);
         pinMode(LCD_D1_PIN,OUTPUT);
         pinMode(LCD_D2_PIN,OUTPUT);
         pinMode(LCD_D3_PIN,OUTPUT);
         pinMode(LCD_D4_PIN,OUTPUT);
         pinMode(LCD_D5_PIN,OUTPUT);
         pinMode(LCD_D6_PIN,OUTPUT);
         pinMode(LCD_D7_PIN,OUTPUT);
    }
    
    void LCD_BusPinsAsInput()
    {
        pinMode(LCD_D0_PIN,INPUT);
        pinMode(LCD_D1_PIN,INPUT);
        pinMode(LCD_D2_PIN,INPUT);
        pinMode(LCD_D3_PIN,INPUT);
        pinMode(LCD_D4_PIN,INPUT);
        pinMode(LCD_D5_PIN,INPUT);
        pinMode(LCD_D6_PIN,INPUT);
        pinMode(LCD_D7_PIN,INPUT);
    }
    
    uint8_t LCD_BusWrite(byte byteToWrite)
    {
        LCD_BusPinsAsOutput();
        
        digitalWrite(LCD_D0_PIN,byteToWrite & BIT0_MSK_8BIT);
        digitalWrite(LCD_D1_PIN,byteToWrite & BIT1_MSK_8BIT);
        digitalWrite(LCD_D2_PIN,byteToWrite & BIT2_MSK_8BIT);
        digitalWrite(LCD_D3_PIN,byteToWrite & BIT3_MSK_8BIT);
        digitalWrite(LCD_D4_PIN,byteToWrite & BIT4_MSK_8BIT);
        digitalWrite(LCD_D5_PIN,byteToWrite & BIT5_MSK_8BIT);
        digitalWrite(LCD_D6_PIN,byteToWrite & BIT6_MSK_8BIT);
        digitalWrite(LCD_D7_PIN,byteToWrite & BIT7_MSK_8BIT);
        
        return 0;
    }
    
    uint8_t LCD_BusRead()
    {
        uint8_t data=0;
        
        LCD_BusPinsAsInput();
        delay(100);
        data = digitalRead(LCD_D0_PIN)<<0;
        data |= digitalRead(LCD_D1_PIN)<<1;
        data |= digitalRead(LCD_D2_PIN)<<2;
        data |= digitalRead(LCD_D3_PIN)<<3;
        data |= digitalRead(LCD_D4_PIN)<<4;
        data |= digitalRead(LCD_D5_PIN)<<5;
        data |= digitalRead(LCD_D6_PIN)<<6;
        data |= digitalRead(LCD_D7_PIN)<<7;
        
        return data;
    }
    
    void LCD_WriteData_unsafe(uint16_t data)
    {
        LCD_BusWrite(data>>8);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_BusWrite(data);
        LCD_WR_LOW();
        LCD_WR_HIGH();
    }
    
    void LCD_WriteData(uint16_t data)
    {
        
        LCD_CS_LOW();
        LCD_RS_HIGH();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        LCD_BusPinsAsOutput();
        LCD_WriteData_unsafe(data);
        LCD_CS_HIGH();
    }
    
    uint8_t LCD_WriteCommand(uint16_t  cmd_index)
    {
        LCD_CS_LOW();
        LCD_RS_LOW();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        
        LCD_BusPinsAsOutput();
        LCD_BusWrite(cmd_index>>8);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_BusWrite(cmd_index);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_CS_HIGH();
        
        return 0;    
    }
    
    uint16_t LCD_ReadData()
    {
        uint16_t data=0;
        LCD_CS_LOW();
        LCD_RS_HIGH();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        LCD_BusPinsAsInput();
        LCD_RD_LOW();
        delayMicroseconds(100);
            data=LCD_BusRead();
        data <<=8;
        LCD_RD_HIGH();
            LCD_RD_LOW();
        delayMicroseconds(100);
        data |= LCD_BusRead();
        LCD_RD_HIGH();
        LCD_CS_HIGH();
        return data;
    }
    
    uint16_t LCD_ReadRegister(uint16_t addr)
    {
        LCD_WriteCommand(addr);
        return LCD_ReadData();        
    }
    
    uint16_t LCD_WriteRegister(uint16_t addr, uint16_t data)
    {
        LCD_WriteCommand(addr);
        LCD_WriteData(data);
    }
    
    void LCD_Init()
    {
        LCD_BusPinsAsOutput();
        LCD_BusWrite(0);
        //Reset Pin
        pinMode(LCD_RST,OUTPUT);
        digitalWrite(LCD_RST, HIGH);
        //Chip Select
        pinMode(LCD_CS,OUTPUT);
        digitalWrite(LCD_CS, HIGH);
        //Register Select
        pinMode(LCD_RS,OUTPUT);
        digitalWrite(LCD_RS, HIGH);
        //Write strobe
        pinMode(LCD_WR,OUTPUT);
        digitalWrite(LCD_WR, HIGH);
        //Read strobe
        pinMode(LCD_RD,OUTPUT);
        digitalWrite(LCD_RD, HIGH);
        
        // -Reset--------------------------------------------------------------------------------------
    
        LCD_RST_LOW();
        delay(100);
        LCD_RST_HIGH();
        delay(100); //1000
        /*LCD_WriteData(0);   // resync
        LCD_WriteData(0);
        LCD_WriteData(0);
        LCD_WriteData(0);*/
        
        delayMicroseconds (200);
            
            LCD_WriteCommand(0x00FF);
        LCD_WriteData(0x0001);
            LCD_WriteCommand(0x00F3);
        LCD_WriteData(0x0008);
            LCD_WriteCommand(0xF1);
        LCD_WriteData(0x00F3);
    
    #if 1        
        LCD_WriteCommand(0x0001);
        LCD_WriteData(0x0100);
        LCD_WriteCommand(0x0002);
        LCD_WriteData(0x0700);
        LCD_WriteCommand(0x0003);
        LCD_WriteData(0x1030);
        LCD_WriteCommand(0x0008);
        LCD_WriteData(0x0302);
        LCD_WriteCommand(0x0009);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0011);
        LCD_WriteData(0x0007);
        LCD_WriteCommand(0x0012);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0013);
        LCD_WriteData(0x0000);
        delayMicroseconds(1000); //1000
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x14B0);
        delayMicroseconds(500);
        LCD_WriteCommand(0x0011);
        LCD_WriteData(0x0007);
        delayMicroseconds(500);    
        LCD_WriteCommand(0x0012);
        LCD_WriteData(0x008E);
        LCD_WriteCommand(0x0013);
        LCD_WriteData(0x0C00);
        LCD_WriteCommand(0x0029);
        LCD_WriteData(0x0015);
        delayMicroseconds(500);    
        LCD_WriteCommand(0x0030);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0031);
        LCD_WriteData(0x0107);
        LCD_WriteCommand(0x0032);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0035);
        LCD_WriteData(0x0203);
        LCD_WriteCommand(0x0036);
        LCD_WriteData(0x0402);
        LCD_WriteCommand(0x0037);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0038);
        LCD_WriteData(0x0207);
        LCD_WriteCommand(0x0039);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x003c);
        LCD_WriteData(0x0203);
        LCD_WriteCommand(0x003d);
        LCD_WriteData(0x0403);
        LCD_WriteCommand(0x0050);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0051);
        LCD_WriteData(0x00EF);
        LCD_WriteCommand(0x0052);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0053);
        LCD_WriteData(0x013F);
        LCD_WriteCommand(0x0060);
        LCD_WriteData(0xA700);
        LCD_WriteCommand(0x0061);
        LCD_WriteData(0x0001);
        LCD_WriteCommand(0x0090);
        LCD_WriteData(0x0029);
    
        LCD_WriteCommand(0x0007);
        LCD_WriteData(0x0133);
        delayMicroseconds(500);
        
        LCD_exitStandBy();
        LCD_WriteCommand(0x0022);
    #endif    
        //paint screen black
        //LCD_PaintScreen(LCD_BLACK);
        LCD_fillScreen(LCD_BLACK);
    }
    
    #endif // Basics
    
    #if 1 //Drawing functions COOCOX Driver
    
        #if 1 //Font
            const unsigned char simpleFont[][8] =
            {
                {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
                {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
                {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
                {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
                {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
                {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
                {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
                {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
                {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
                {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
                {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
                {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
                {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
                {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
                {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
                {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
                {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
                {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
                {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
                {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
                {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
                {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
                {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
                {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
                {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
                {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
                {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
                {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
                {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
                {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
                {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
                {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
                {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
                {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
                {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
                {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
                {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
                {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
                {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
                {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
                {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
                {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
                {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
                {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
                {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
                {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
                {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
                {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
                {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
                {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
                {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
                {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
                {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
                {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
                {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
                {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
                {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
                {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
                {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
                {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
                {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
                {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
                {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
                {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
                {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
                {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
                {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
                {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
                {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
                {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
                {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
                {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
                {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
                {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
                {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
            };        
        #endif
    
    // Makrodefinitionen für char Anzeigerichtung
    #define LEFT2RIGHT  0
    #define DOWN2UP     1
    #define RIGHT2LEFT  2
    #define UP2DOWN     3
    
    static unsigned char DisplayDirect = RIGHT2LEFT;
    
    void LCD_SetXY(uint16_t poX, uint16_t poY)
    {
        LCD_WriteCommand(0x0020);//X
        LCD_WriteData(poX);
        LCD_WriteCommand(0x0021);//Y
        LCD_WriteData(poY);
        LCD_WriteCommand(0x0022);//Start, um zu schreiben, um RAM anzuzeigen
    }
    
    void LCD_goHome(void)
    {
      LCD_SetXY(0,0);
    }
    
    void LCD_fillScreen(uint16_t color) {
      LCD_goHome();
      uint32_t i;
      i = 320;
      i *= 240;
      digitalWrite(LCD_CS, LOW);
      digitalWrite(LCD_RS, HIGH);
      digitalWrite(LCD_RD, HIGH);
      digitalWrite(LCD_WR, HIGH);
      //setWriteDir();
      while (i--) {
        LCD_WriteData_unsafe(color);
      }
      digitalWrite(LCD_CS, HIGH);
    }
    
    void LCD_SetPixel(uint16_t poX, uint16_t poY,uint16_t color)
    {
        LCD_SetXY(poX,poY);
        LCD_WriteData(color);
    }
    
    void LCD_DrawCircle(int16_t poX, int16_t poY, int16_t r,uint16_t color)
    {
        int x = -r, y = 0, err = 2-2*r, e2;
        do {
            LCD_SetPixel(poX-x, poY+y,color);
            LCD_SetPixel(poX+x, poY+y,color);
            LCD_SetPixel(poX+x, poY-y,color);
            LCD_SetPixel(poX-x, poY-y,color);
            e2 = err;
            if (e2 <= y) {
                err += ++y*2+1;
                if (-x == y && e2 <= x) e2 = 0;
            }
            if (e2 > x) err += ++x*2+1;
        } while (x <= 0);
    }
    
    void LCD_DrawLine(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t color)
    {
        int x = x1-x0;
        int y = y1-y0;
        int dx = abs(x), sx = x0<x1 ? 1 : -1;
        int dy = -abs(y), sy = y0<y1 ? 1 : -1;
        int err = dx+dy, e2; /* error value e_xy */
        for (;;)
        {
            // loop
            LCD_SetPixel(x0,y0,color);
            e2 = 2*err;
            if (e2 >= dy)
            {
                // e_xy+e_x > 0
                if (x0 == x1) break;
                err += dy; x0 += sx;
            }
            if (e2 <= dx)
            {  
                //e_xy+e_y < 0
                if (y0 == y1) break;
                err += dx; y0 += sy;
            }
        }
    }
    
    void LCD_DrawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
    {
        unsigned int i;
    
        LCD_SetXY(poX,poY);
        LCD_SetOrientation(1);
        if(length+poY>LCD_MAX_Y)
        {
            length=LCD_MAX_Y-poY;
        }
    
        for(i=0;i<length;i++)
        {
            LCD_WriteData(color);
        }
    }
    
    void LCD_DrawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
    {
        unsigned int i;
    
        LCD_SetXY(poX,poY);
        LCD_SetOrientation(0);
        if(length+poX>LCD_MAX_X)
        {
            length=LCD_MAX_X-poX;
        }
        for(i=0;i<length;i++)
        {
            LCD_WriteData(color);
        }
    }
    
    void LCD_DrawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color)
    {
        LCD_DrawHorizontalLine(poX, poY, length, color);
        LCD_DrawHorizontalLine(poX, poY+width, length, color);
    
        LCD_DrawVerticalLine(poX, poY, width,color);
        LCD_DrawVerticalLine(poX + length, poY, width,color);
    }
    
    void LCD_PaintScreen(uint16_t color)
    {
        unsigned int i, f;
        for(i=0; i<320; i++)
        {
            for(f=0; f<240; f++)
            {
                LCD_WriteData(color);
            }
        }
    }
    
    void LCD_FillCircle(int poX, int poY, int r,unsigned int color)
    {
        int x = -r, y = 0, err = 2-2*r, e2;
        do {
            LCD_DrawVerticalLine(poX-x,poY-y,2*y,color);
            LCD_DrawVerticalLine(poX+x,poY-y,2*y,color);
    
            e2 = err;
            if (e2 <= y) {
                err += ++y*2+1;
                if (-x == y && e2 <= x) e2 = 0;
            }
            if (e2 > x) err += ++x*2+1;
        } while (x <= 0);
    }
    
    void LCD_FillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color)
    {
        unsigned int i;
    
        for(i=0;i<width;i++)
        {
            if(DisplayDirect == LEFT2RIGHT)
            LCD_DrawHorizontalLine(poX, poY+i, length, color);
            else if (DisplayDirect ==  DOWN2UP)
            LCD_DrawHorizontalLine(poX, poY-i, length, color);
            else if(DisplayDirect == RIGHT2LEFT)
            LCD_DrawHorizontalLine(poX, poY-i, length, color);
            else if(DisplayDirect == UP2DOWN)
            LCD_DrawHorizontalLine(poX, poY+i, length, color);
    
        }
    }
    
    void LCD_DrawChar(unsigned int poX, unsigned int poY, unsigned char ascii, unsigned int size, unsigned int fgcolor)
    {
        unsigned char i, f, temp = 0;
    
        LCD_SetXY(poX,poY);
    
        if((ascii < 0x20)||(ascii > 0x7e))//Nicht unterstützte Zeichen..
        {
            ascii = '?';
        }
        for(i=0;i<8;i++)
        {
            temp = simpleFont[ascii-0x20][i];
            for(f=0;f<8;f++)
            {
                if((temp>>f)&0x01)
                {
                    if(DisplayDirect == LEFT2RIGHT)
                    LCD_FillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
                    else if(DisplayDirect == DOWN2UP)
                    LCD_FillRectangle(poX+f*size, poY-i*size, size, size, fgcolor);
                    else if(DisplayDirect == RIGHT2LEFT)
                    LCD_FillRectangle(poX-i*size, poY-f*size, size, size, fgcolor);
                    else if(DisplayDirect == UP2DOWN)
                    LCD_FillRectangle(poX-f*size, poY+i*size, size, size, fgcolor);
                }
            }
        }
    }
    
    void LCD_DrawString(unsigned int poX, unsigned int poY, char *string, unsigned int size, unsigned int fgcolor)
    {
        //unsigned char i;
    
        while(*string != '\0')
        {
            
            //for(i=0;i<8;i++)
            {
                LCD_DrawChar(poX, poY, *string, size, fgcolor);
                
            }
            string++;
            //*string++;
            if(DisplayDirect == LEFT2RIGHT){
                if(poX < LCD_MAX_X){
                    poX += 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == DOWN2UP){
                if(poY > 0){
                    poY -= 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == RIGHT2LEFT) {
                if(poX > 0){
                    poX -= 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == UP2DOWN){
                if(poY < LCD_MAX_Y){
                    poY += 8*size; // Cursor nach rechts bewegen
                }
            }
        }
        
    }
    
    void LCD_DrawBmp(unsigned short ulXs, unsigned short ulYs, unsigned short length, unsigned short height, unsigned short *buf)
    {
        unsigned short i, j;
        unsigned short length_null = 0;
    
        if(ulXs + length > LCD_MAX_X){
            length_null = ulXs + length - LCD_MAX_X;
        }
    
        if(ulYs + height > LCD_MAX_Y){
            height -= ulYs + height - LCD_MAX_Y;
        }
    
        for(j = 0; j < height; j++){
            LCD_SetXY(ulXs, ulYs);
            for(i = 0; i < length; i++){
                LCD_WriteData(*buf++);
            }
            ulYs++;
            buf += length_null;
        }
    }
    
    void LCD_exitStandBy(void)
    {
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x14E0);
        delayMicroseconds(100);
        LCD_WriteCommand(0x0007);
        LCD_WriteData(0x0133);
    }
    
    void LCD_SetOrientation(uint16_t HV)//horizontal oder vertical
    {
        LCD_WriteCommand(0x03);
        if(HV==1)//vertical
        {
            LCD_WriteData(0x5038); //5038
        }
        else//horizontal
        {
            LCD_WriteData(0x5030); //5030
        }
        LCD_WriteCommand(0x0022); //Start, um zu schreiben, um RAM anzuzeigen
    }
    
    void LCD_SetDisplayDirect(uint8_t Direction)
    {
        DisplayDirect = Direction;
    }
    
    
    #endif
    
        void setup(){
        
        
        
            //Serial.begin(9600);
            //Serial.println("Display Test..\r\n");
            LCD_Init();
            LCD_SetDisplayDirect(3);
                //LCD_SetOrientation(2);
                //LCD_fillScreen(LCD_GRAY1);
                //LCD_PaintScreen(LCD_BLACK);
            //DisplayDirect = UP2DOWN;
                LCD_DrawString(60,20," cm ",5,LCD_RED);
            LCD_DrawString(20,140," ",5,LCD_BLUE);
            LCD_DrawString(180,40,"Wassertank ",3,LCD_WHITE);
            LCD_DrawString(120,20,"Inhalt in cm ",3,LCD_WHITE);
                
                //LCD_FillRectangle(0,0,239,319,LCD_YELLOW);
            /*
                for(uint8_t x=0;x<200;x++)
            {
                LCD_DrawLine(x,0,x,100,LCD_YELLOW);
            }
                */
            //Read Device ID
            //static uint16_t identifier;
            //uint16_t identifier = LCD_ReadRegister(0x0);
            //Serial.println(identifier,HEX);
        }
        
            
              
        
        
        
        void loop()
      {
      
      // Variablen für Dauer der ping,
          // Und der Abstand Ergebnis in Zoll und Zentimeter:
          long duration, inches, cm;
        
          // Der PING wird mit einem High-Impuls von 2 oder mehr Mikrosekunden ausgelöst.
          // Geben Sie eine kurze LOW Impuls vorher um eine saubere HIGH-Impuls zu gewährleisten:
          pinMode(ledPin, OUTPUT);
          pinMode(pingPin, OUTPUT);
          digitalWrite(pingPin, LOW);
          delayMicroseconds(2);
          digitalWrite(pingPin, HIGH);
          delayMicroseconds(10);
          digitalWrite(pingPin, LOW);
        
          // Der gleiche Ping dient dazu, das Signal von der PING)) zu lesen
          // dessen Dauer ist die Zeit (in Mikrosekunden) vom Senden
          // Die Verbindungsgeschwindigkeit mit dem Empfang sein echo off von dem Objekts.
          pinMode(inPin, INPUT);
          duration = pulseIn(inPin, HIGH);
        
          // Hier wird die Zeit in eine entfernung umgewandelt
          cm = microsecondsToCentimeters(duration);
          
           if(cm > 50)
            {
            digitalWrite(ledPin, LOW);
            }
           else
           {
           digitalWrite(ledPin, HIGH);
           }
          
        
          delay(100);
        }
          
          
          long microsecondsToInches(long microseconds){
            // Nach Parallax das Datenblatt für den PING))), gibt es
            // 73,746 Mikrosekunden pro Zoll (dh Schall bei 1130 Fuß pro
            // Sekunde). Dies gibt die Wegstrecke vom Ping,
            // Und zurück, so dass wir durch 2 teilen, müssen um den Abstand zum Hindernisses zu bekommen.
            return microseconds / 74 / 2;}
          
          long microsecondsToCentimeters(long microseconds){
            // Die Schallgeschwindigkeit beträgt 340 m / s oder 29 Mikrosekunden pro Zentimeter.
            return microseconds / 29 / 2;
      
      }

Die Ausgabe auf den 2,4 TFT bis auf den Wert "cm" wird gemacht
leider mehr nicht.
AlarmPin wird auch richtig ausgelöst.

Danke an euch für die Hilfe. Gruß JörgHuhConfused
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
03.06.2015, 17:13
Beitrag #26
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
(03.06.2015 16:20)jgrothe schrieb:  Die Ausgabe auf den 2,4 TFT bis auf den Wert "cm" wird gemacht
Das ist kein Wunder, Du gibst es ja auch nirgends aus. Du machst nur im setup() Ausgaben auf's Display. Das wird aber nur einmal am Anfang durchlaufen. Du musst es im loop() (oder in einer Funktion, die von dort aufgerufen wird) ausgeben.
Gruß,
Thorsten

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
03.06.2015, 17:40
Beitrag #27
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
Hallo Thorsten habe alles in die loop() verschoben,
aber wie deklariere ich den String für die Ausgabe
in cm (Entfernung)?

Danke JörgUndecided
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
03.06.2015, 18:37
Beitrag #28
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
Hi,
versuch mal String(cm).c_str(). Das ist zwar nicht ganz sauber, könnte aber am schnellsten zum Ziel führen.
Gruß,
Thorsten

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
03.06.2015, 19:10 (Dieser Beitrag wurde zuletzt bearbeitet: 03.06.2015 20:06 von jgrothe.)
Beitrag #29
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
Hallo Thorsten, danke für Hilfe

habe das probiert " numberString = String((int) cm);
String numberString = " ";

ohne Erfolg aber auch ohne Fehler
Dann den Tipp von Dir versucht ging leider auch nicht hat Fehler
ausgegeben.

Hallo, an alle die es noch mal versuchen möchten ich bin am ende angekommen,
leider ich weis nicht mehr weiter.

Code:
int pingPin = 12;
          int inPin = 11;
          int ledPin = 10;
    
    
    const unsigned int messintervall = 100;
    const unsigned int alarmdistanz = 100; // in cm
    String numberString = " ";
     // Entfernungswert
    unsigned long cm;
    
    
    /*
    Basic Grafix.ino
     *
     * Created: 9/20/2014 5:09:28 PM
     * Author: BasisV12
     */
    
    //Bus Pins (Arduino digital Pin numbers)
    #define LCD_D0_PIN 8
    #define LCD_D1_PIN 9
    #define LCD_D2_PIN 2
    #define LCD_D3_PIN 3
    #define LCD_D4_PIN 4
    #define LCD_D5_PIN 5
    #define LCD_D6_PIN 6
    #define LCD_D7_PIN 7
    
    //Control Pins (here: Analog pins A0..A4)
    #define LCD_RST    A4
    #define LCD_CS     A3
    #define LCD_RS     A2
    #define LCD_WR     A1
    #define LCD_RD     A0
    
    #define BIT0_MSK_8BIT  B00000001
    #define BIT1_MSK_8BIT  B00000010
    #define BIT2_MSK_8BIT  B00000100
    #define BIT3_MSK_8BIT  B00001000
    #define BIT4_MSK_8BIT  B00010000
    #define BIT5_MSK_8BIT  B00100000
    #define BIT6_MSK_8BIT  B01000000
    #define BIT7_MSK_8BIT  B10000000
    
    #define LCD_RST_LOW()  digitalWrite(LCD_RST, LOW)
    #define LCD_RST_HIGH() digitalWrite(LCD_RST, HIGH)
    
    #define LCD_CS_LOW()  digitalWrite(LCD_CS, LOW)
    #define LCD_CS_HIGH() digitalWrite(LCD_CS, HIGH)
    
    #define LCD_RS_LOW()  digitalWrite(LCD_RS, LOW)
    #define LCD_RS_HIGH() digitalWrite(LCD_RS, HIGH)
    
    #define LCD_WR_LOW()  digitalWrite(LCD_WR, LOW)
    #define LCD_WR_HIGH() digitalWrite(LCD_WR, HIGH)
    
    #define LCD_RD_LOW()  digitalWrite(LCD_RD, LOW)
    #define LCD_RD_HIGH() digitalWrite(LCD_RD, HIGH)
    
    //Basic Colors
    #define    LCD_BLACK                   0x0000
    #define    LCD_BLUE                    0x001F
    #define    LCD_RED                     0xF800
    #define    LCD_GREEN                   0x07E0
    #define LCD_CYAN                    0x07FF
    #define LCD_MAGENTA                 0xF81F
    #define LCD_YELLOW                  0xFFE0
    #define LCD_WHITE                   0xFFFF
        
        
    //Other Colors
    #define LCD_CYAN            0x07ff
    #define LCD_BRIGHT_RED      0xf810
    #define LCD_GRAY1           0x8410
    #define LCD_GRAY2           0x4208
    
    //TFT resolution 240*320
    #define LCD_MIN_X       0
    #define LCD_MIN_Y       0
    #define LCD_MAX_X       240
    #define LCD_MAX_Y       320
    
    
    #define swap_uint16_t(a, b) { uint16_t t = a; a = b; b = t; }
    
    #if 1 //Basics
    
    
    void LCD_BusPinsAsOutput()
    {
         pinMode(LCD_D0_PIN,OUTPUT);
         pinMode(LCD_D1_PIN,OUTPUT);
         pinMode(LCD_D2_PIN,OUTPUT);
         pinMode(LCD_D3_PIN,OUTPUT);
         pinMode(LCD_D4_PIN,OUTPUT);
         pinMode(LCD_D5_PIN,OUTPUT);
         pinMode(LCD_D6_PIN,OUTPUT);
         pinMode(LCD_D7_PIN,OUTPUT);
    }
    
    void LCD_BusPinsAsInput()
    {
        pinMode(LCD_D0_PIN,INPUT);
        pinMode(LCD_D1_PIN,INPUT);
        pinMode(LCD_D2_PIN,INPUT);
        pinMode(LCD_D3_PIN,INPUT);
        pinMode(LCD_D4_PIN,INPUT);
        pinMode(LCD_D5_PIN,INPUT);
        pinMode(LCD_D6_PIN,INPUT);
        pinMode(LCD_D7_PIN,INPUT);
    }
    
    uint8_t LCD_BusWrite(byte byteToWrite)
    {
        LCD_BusPinsAsOutput();
        
        digitalWrite(LCD_D0_PIN,byteToWrite & BIT0_MSK_8BIT);
        digitalWrite(LCD_D1_PIN,byteToWrite & BIT1_MSK_8BIT);
        digitalWrite(LCD_D2_PIN,byteToWrite & BIT2_MSK_8BIT);
        digitalWrite(LCD_D3_PIN,byteToWrite & BIT3_MSK_8BIT);
        digitalWrite(LCD_D4_PIN,byteToWrite & BIT4_MSK_8BIT);
        digitalWrite(LCD_D5_PIN,byteToWrite & BIT5_MSK_8BIT);
        digitalWrite(LCD_D6_PIN,byteToWrite & BIT6_MSK_8BIT);
        digitalWrite(LCD_D7_PIN,byteToWrite & BIT7_MSK_8BIT);
        
        return 0;
    }
    
    uint8_t LCD_BusRead()
    {
        uint8_t data=0;
        
        LCD_BusPinsAsInput();
        delay(100);
        data = digitalRead(LCD_D0_PIN)<<0;
        data |= digitalRead(LCD_D1_PIN)<<1;
        data |= digitalRead(LCD_D2_PIN)<<2;
        data |= digitalRead(LCD_D3_PIN)<<3;
        data |= digitalRead(LCD_D4_PIN)<<4;
        data |= digitalRead(LCD_D5_PIN)<<5;
        data |= digitalRead(LCD_D6_PIN)<<6;
        data |= digitalRead(LCD_D7_PIN)<<7;
        
        return data;
    }
    
    void LCD_WriteData_unsafe(uint16_t data)
    {
        LCD_BusWrite(data>>8);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_BusWrite(data);
        LCD_WR_LOW();
        LCD_WR_HIGH();
    }
    
    void LCD_WriteData(uint16_t data)
    {
        
        LCD_CS_LOW();
        LCD_RS_HIGH();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        LCD_BusPinsAsOutput();
        LCD_WriteData_unsafe(data);
        LCD_CS_HIGH();
    }
    
    uint8_t LCD_WriteCommand(uint16_t  cmd_index)
    {
        LCD_CS_LOW();
        LCD_RS_LOW();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        
        LCD_BusPinsAsOutput();
        LCD_BusWrite(cmd_index>>8);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_BusWrite(cmd_index);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_CS_HIGH();
        
        return 0;    
    }
    
    uint16_t LCD_ReadData()
    {
        uint16_t data=0;
        LCD_CS_LOW();
        LCD_RS_HIGH();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        LCD_BusPinsAsInput();
        LCD_RD_LOW();
        delayMicroseconds(100);
            data=LCD_BusRead();
        data <<=8;
        LCD_RD_HIGH();
            LCD_RD_LOW();
        delayMicroseconds(100);
        data |= LCD_BusRead();
        LCD_RD_HIGH();
        LCD_CS_HIGH();
        return data;
    }
    
    uint16_t LCD_ReadRegister(uint16_t addr)
    {
        LCD_WriteCommand(addr);
        return LCD_ReadData();        
    }
    
    uint16_t LCD_WriteRegister(uint16_t addr, uint16_t data)
    {
        LCD_WriteCommand(addr);
        LCD_WriteData(data);
    }
    
    void LCD_Init()
    {
        LCD_BusPinsAsOutput();
        LCD_BusWrite(0);
        //Reset Pin
        pinMode(LCD_RST,OUTPUT);
        digitalWrite(LCD_RST, HIGH);
        //Chip Select
        pinMode(LCD_CS,OUTPUT);
        digitalWrite(LCD_CS, HIGH);
        //Register Select
        pinMode(LCD_RS,OUTPUT);
        digitalWrite(LCD_RS, HIGH);
        //Write strobe
        pinMode(LCD_WR,OUTPUT);
        digitalWrite(LCD_WR, HIGH);
        //Read strobe
        pinMode(LCD_RD,OUTPUT);
        digitalWrite(LCD_RD, HIGH);
        
        // -Reset--------------------------------------------------------------------------------------
    
        LCD_RST_LOW();
        delay(100);
        LCD_RST_HIGH();
        delay(100); //1000
        /*LCD_WriteData(0);   // resync
        LCD_WriteData(0);
        LCD_WriteData(0);
        LCD_WriteData(0);*/
        
        delayMicroseconds (200);
            
            LCD_WriteCommand(0x00FF);
        LCD_WriteData(0x0001);
            LCD_WriteCommand(0x00F3);
        LCD_WriteData(0x0008);
            LCD_WriteCommand(0xF1);
        LCD_WriteData(0x00F3);
    
    #if 1        
        LCD_WriteCommand(0x0001);
        LCD_WriteData(0x0100);
        LCD_WriteCommand(0x0002);
        LCD_WriteData(0x0700);
        LCD_WriteCommand(0x0003);
        LCD_WriteData(0x1030);
        LCD_WriteCommand(0x0008);
        LCD_WriteData(0x0302);
        LCD_WriteCommand(0x0009);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0011);
        LCD_WriteData(0x0007);
        LCD_WriteCommand(0x0012);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0013);
        LCD_WriteData(0x0000);
        delayMicroseconds(1000); //1000
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x14B0);
        delayMicroseconds(500);
        LCD_WriteCommand(0x0011);
        LCD_WriteData(0x0007);
        delayMicroseconds(500);    
        LCD_WriteCommand(0x0012);
        LCD_WriteData(0x008E);
        LCD_WriteCommand(0x0013);
        LCD_WriteData(0x0C00);
        LCD_WriteCommand(0x0029);
        LCD_WriteData(0x0015);
        delayMicroseconds(500);    
        LCD_WriteCommand(0x0030);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0031);
        LCD_WriteData(0x0107);
        LCD_WriteCommand(0x0032);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0035);
        LCD_WriteData(0x0203);
        LCD_WriteCommand(0x0036);
        LCD_WriteData(0x0402);
        LCD_WriteCommand(0x0037);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0038);
        LCD_WriteData(0x0207);
        LCD_WriteCommand(0x0039);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x003c);
        LCD_WriteData(0x0203);
        LCD_WriteCommand(0x003d);
        LCD_WriteData(0x0403);
        LCD_WriteCommand(0x0050);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0051);
        LCD_WriteData(0x00EF);
        LCD_WriteCommand(0x0052);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0053);
        LCD_WriteData(0x013F);
        LCD_WriteCommand(0x0060);
        LCD_WriteData(0xA700);
        LCD_WriteCommand(0x0061);
        LCD_WriteData(0x0001);
        LCD_WriteCommand(0x0090);
        LCD_WriteData(0x0029);
    
        LCD_WriteCommand(0x0007);
        LCD_WriteData(0x0133);
        delayMicroseconds(500);
        
        LCD_exitStandBy();
        LCD_WriteCommand(0x0022);
    #endif    
        //paint screen black
        //LCD_PaintScreen(LCD_BLACK);
        LCD_fillScreen(LCD_BLACK);
    }
    
    #endif // Basics
    
    #if 1 //Drawing functions COOCOX Driver
    
        #if 1 //Font
            const unsigned char simpleFont[][8] =
            {
                {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
                {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
                {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
                {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
                {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
                {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
                {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
                {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
                {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
                {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
                {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
                {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
                {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
                {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
                {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
                {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
                {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
                {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
                {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
                {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
                {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
                {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
                {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
                {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
                {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
                {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
                {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
                {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
                {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
                {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
                {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
                {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
                {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
                {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
                {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
                {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
                {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
                {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
                {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
                {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
                {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
                {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
                {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
                {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
                {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
                {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
                {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
                {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
                {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
                {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
                {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
                {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
                {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
                {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
                {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
                {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
                {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
                {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
                {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
                {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
                {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
                {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
                {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
                {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
                {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
                {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
                {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
                {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
                {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
                {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
                {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
                {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
                {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
                {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
                {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
            };        
        #endif
    
    // Makrodefinitionen für char Anzeigerichtung
    #define LEFT2RIGHT  0
    #define DOWN2UP     1
    #define RIGHT2LEFT  2
    #define UP2DOWN     3
    
    static unsigned char DisplayDirect = RIGHT2LEFT;
    
    void LCD_SetXY(uint16_t poX, uint16_t poY)
    {
        LCD_WriteCommand(0x0020);//X
        LCD_WriteData(poX);
        LCD_WriteCommand(0x0021);//Y
        LCD_WriteData(poY);
        LCD_WriteCommand(0x0022);//Start, um zu schreiben, um RAM anzuzeigen
    }
    
    void LCD_goHome(void)
    {
      LCD_SetXY(0,0);
    }
    
    void LCD_fillScreen(uint16_t color) {
      LCD_goHome();
      uint32_t i;
      i = 320;
      i *= 240;
      digitalWrite(LCD_CS, LOW);
      digitalWrite(LCD_RS, HIGH);
      digitalWrite(LCD_RD, HIGH);
      digitalWrite(LCD_WR, HIGH);
      //setWriteDir();
      while (i--) {
        LCD_WriteData_unsafe(color);
      }
      digitalWrite(LCD_CS, HIGH);
    }
    
    void LCD_SetPixel(uint16_t poX, uint16_t poY,uint16_t color)
    {
        LCD_SetXY(poX,poY);
        LCD_WriteData(color);
    }
    
    void LCD_DrawCircle(int16_t poX, int16_t poY, int16_t r,uint16_t color)
    {
        int x = -r, y = 0, err = 2-2*r, e2;
        do {
            LCD_SetPixel(poX-x, poY+y,color);
            LCD_SetPixel(poX+x, poY+y,color);
            LCD_SetPixel(poX+x, poY-y,color);
            LCD_SetPixel(poX-x, poY-y,color);
            e2 = err;
            if (e2 <= y) {
                err += ++y*2+1;
                if (-x == y && e2 <= x) e2 = 0;
            }
            if (e2 > x) err += ++x*2+1;
        } while (x <= 0);
    }
    
    void LCD_DrawLine(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t color)
    {
        int x = x1-x0;
        int y = y1-y0;
        int dx = abs(x), sx = x0<x1 ? 1 : -1;
        int dy = -abs(y), sy = y0<y1 ? 1 : -1;
        int err = dx+dy, e2; /* error value e_xy */
        for (;;)
        {
            // loop
            LCD_SetPixel(x0,y0,color);
            e2 = 2*err;
            if (e2 >= dy)
            {
                // e_xy+e_x > 0
                if (x0 == x1) break;
                err += dy; x0 += sx;
            }
            if (e2 <= dx)
            {  
                //e_xy+e_y < 0
                if (y0 == y1) break;
                err += dx; y0 += sy;
            }
        }
    }
    
    void LCD_DrawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
    {
        unsigned int i;
    
        LCD_SetXY(poX,poY);
        LCD_SetOrientation(1);
        if(length+poY>LCD_MAX_Y)
        {
            length=LCD_MAX_Y-poY;
        }
    
        for(i=0;i<length;i++)
        {
            LCD_WriteData(color);
        }
    }
    
    void LCD_DrawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
    {
        unsigned int i;
    
        LCD_SetXY(poX,poY);
        LCD_SetOrientation(0);
        if(length+poX>LCD_MAX_X)
        {
            length=LCD_MAX_X-poX;
        }
        for(i=0;i<length;i++)
        {
            LCD_WriteData(color);
        }
    }
    
    void LCD_DrawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color)
    {
        LCD_DrawHorizontalLine(poX, poY, length, color);
        LCD_DrawHorizontalLine(poX, poY+width, length, color);
    
        LCD_DrawVerticalLine(poX, poY, width,color);
        LCD_DrawVerticalLine(poX + length, poY, width,color);
    }
    
    void LCD_PaintScreen(uint16_t color)
    {
        unsigned int i, f;
        for(i=0; i<320; i++)
        {
            for(f=0; f<240; f++)
            {
                LCD_WriteData(color);
            }
        }
    }
    
    void LCD_FillCircle(int poX, int poY, int r,unsigned int color)
    {
        int x = -r, y = 0, err = 2-2*r, e2;
        do {
            LCD_DrawVerticalLine(poX-x,poY-y,2*y,color);
            LCD_DrawVerticalLine(poX+x,poY-y,2*y,color);
    
            e2 = err;
            if (e2 <= y) {
                err += ++y*2+1;
                if (-x == y && e2 <= x) e2 = 0;
            }
            if (e2 > x) err += ++x*2+1;
        } while (x <= 0);
    }
    
    void LCD_FillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color)
    {
        unsigned int i;
    
        for(i=0;i<width;i++)
        {
            if(DisplayDirect == LEFT2RIGHT)
            LCD_DrawHorizontalLine(poX, poY+i, length, color);
            else if (DisplayDirect ==  DOWN2UP)
            LCD_DrawHorizontalLine(poX, poY-i, length, color);
            else if(DisplayDirect == RIGHT2LEFT)
            LCD_DrawHorizontalLine(poX, poY-i, length, color);
            else if(DisplayDirect == UP2DOWN)
            LCD_DrawHorizontalLine(poX, poY+i, length, color);
    
        }
    }
    
    void LCD_DrawChar(unsigned int poX, unsigned int poY, unsigned char ascii, unsigned int size, unsigned int fgcolor)
    {
        unsigned char i, f, temp = 0;
    
        LCD_SetXY(poX,poY);
    
        if((ascii < 0x20)||(ascii > 0x7e))//Nicht unterstützte Zeichen..
        {
            ascii = '?';
        }
        for(i=0;i<8;i++)
        {
            temp = simpleFont[ascii-0x20][i];
            for(f=0;f<8;f++)
            {
                if((temp>>f)&0x01)
                {
                    if(DisplayDirect == LEFT2RIGHT)
                    LCD_FillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
                    else if(DisplayDirect == DOWN2UP)
                    LCD_FillRectangle(poX+f*size, poY-i*size, size, size, fgcolor);
                    else if(DisplayDirect == RIGHT2LEFT)
                    LCD_FillRectangle(poX-i*size, poY-f*size, size, size, fgcolor);
                    else if(DisplayDirect == UP2DOWN)
                    LCD_FillRectangle(poX-f*size, poY+i*size, size, size, fgcolor);
                }
            }
        }
    }
    
    void LCD_DrawString(unsigned int poX, unsigned int poY, char *string, unsigned int size, unsigned int fgcolor)
    {
        //unsigned char i;
    
        while(*string != '\0')
        {
            
            //for(i=0;i<8;i++)
            {
                LCD_DrawChar(poX, poY, *string, size, fgcolor);
                
            }
            string++;
            //*string++;
            if(DisplayDirect == LEFT2RIGHT){
                if(poX < LCD_MAX_X){
                    poX += 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == DOWN2UP){
                if(poY > 0){
                    poY -= 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == RIGHT2LEFT) {
                if(poX > 0){
                    poX -= 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == UP2DOWN){
                if(poY < LCD_MAX_Y){
                    poY += 8*size; // Cursor nach rechts bewegen
                }
            }
        }
        
    }
    
    void LCD_DrawBmp(unsigned short ulXs, unsigned short ulYs, unsigned short length, unsigned short height, unsigned short *buf)
    {
        unsigned short i, j;
        unsigned short length_null = 0;
    
        if(ulXs + length > LCD_MAX_X){
            length_null = ulXs + length - LCD_MAX_X;
        }
    
        if(ulYs + height > LCD_MAX_Y){
            height -= ulYs + height - LCD_MAX_Y;
        }
    
        for(j = 0; j < height; j++){
            LCD_SetXY(ulXs, ulYs);
            for(i = 0; i < length; i++){
                LCD_WriteData(*buf++);
            }
            ulYs++;
            buf += length_null;
        }
    }
    
    void LCD_exitStandBy(void)
    {
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x14E0);
        delayMicroseconds(100);
        LCD_WriteCommand(0x0007);
        LCD_WriteData(0x0133);
    }
    
    void LCD_SetOrientation(uint16_t HV)//horizontal oder vertical
    {
        LCD_WriteCommand(0x03);
        if(HV==1)//vertical
        {
            LCD_WriteData(0x5038); //5038
        }
        else//horizontal
        {
            LCD_WriteData(0x5030); //5030
        }
        LCD_WriteCommand(0x0022); //Start, um zu schreiben, um RAM anzuzeigen
    }
    
    void LCD_SetDisplayDirect(uint8_t Direction)
    {
        DisplayDirect = Direction;
    }
    
    
    #endif
        
      
      
      
      
        void setup()
        {
        unsigned long cm;
        
    
          LCD_Init();
          LCD_SetDisplayDirect(3);
             
        }
        
            
              
        
        
        
        void loop()
      {
      
        
        
        
        
          numberString = String((int) cm);
          String numberString = " ";
          //String(cm).c_str().
      
          //LCD.print("Entfernung " + numberString + " cm", CENTER);  
          
                
          LCD_DrawString(60,20," cm ",5,LCD_RED);
          LCD_DrawString(20,140," ",5,LCD_BLUE);
          LCD_DrawString(180,40,"Wassertank ",3,LCD_WHITE);
          LCD_DrawString(120,20,"Inhalt in cm ",3,LCD_WHITE);
                
              
          long duration, cm;
        
          // Der PING wird mit einem High-Impuls von 2 oder mehr Mikrosekunden ausgelöst.
          // Geben Sie eine kurze LOW Impuls vorher um eine saubere HIGH-Impuls zu gewährleisten:
          pinMode(ledPin, OUTPUT);
          pinMode(pingPin, OUTPUT);
          digitalWrite(pingPin, LOW);
          delayMicroseconds(2);
          digitalWrite(pingPin, HIGH);
          delayMicroseconds(10);
          digitalWrite(pingPin, LOW);
        
          // Der gleiche Ping dient dazu, das Signal von der PING)) zu lesen
          // dessen Dauer ist die Zeit (in Mikrosekunden) vom Senden
          // Die Verbindungsgeschwindigkeit mit dem Empfang sein echo off von dem Objekts.
          pinMode(inPin, INPUT);
          duration = pulseIn(inPin, HIGH);
        
          // Hier wird die Zeit in eine entfernung umgewandelt
          cm = microsecondsToCentimeters(duration);
          
           if(cm > 50)
            {
            digitalWrite(ledPin, LOW);
            }
           else
           {
           digitalWrite(ledPin, HIGH);
           }
          
        
          delay(100);
          }
          long microsecondsToCentimeters(long microseconds){
          // Die Schallgeschwindigkeit beträgt 340 m / s oder 29 Mikrosekunden pro Zentimeter.
          return microseconds / 29 / 2;
          }
AngryAngelAngry

wenn dar draußen im weiten WWW noch jemand versuchen möchte Danke
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
03.06.2015, 21:47
Beitrag #30
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
Ich habe mir den Sketch jetzt mal in meine IDE geholt und etwas getestet. Habe festgestellt, dass der Befehl zur Ausgabe als dritten Parameter einen Wert vom Typ char benötigt. Ein String geht an dieser Stelle nicht. Also habe ich mich mal rangesetzt und versucht den Messwert in eine char-Variable zu bekommen. Ist ja nicht so schwierig Wink
Aber auch diesen wollte die IDE nicht schlucken. Meine Lösung ist jetzt folgende:

Code:
char b[4];   //declaring character array
  String str = String(cm); //converting integer into a string
  str.toCharArray(b,4); //passing the value of the string to the character array

  char chrStr[4];
  chrStr[0] = str[1];
  chrStr[1] = str[2];
  chrStr[2] = str[3];
  chrStr[3] = str[4];


  LCD_DrawString(60,20,chrStr,5,LCD_RED);

Und siehe da, die IDE meckert nicht mehrBig Grin

@Jörg: Hier mal der GESAMTE Sketch. Bitte diesen mal in deinen Arduino bringen und testen. Würde mich echt interessieren ob das klappt...Blush

Hier der Sketch:
Code:
int pingPin = 12;
          int inPin = 11;
          int ledPin = 10;
    
    
    
    
    /*
    Basic Grafix.ino
     *
     * Created: 9/20/2014 5:09:28 PM
     * Author: BasisV12
     */
    
    //Bus Pins (Arduino digital Pin numbers)
    #define LCD_D0_PIN 8
    #define LCD_D1_PIN 9
    #define LCD_D2_PIN 2
    #define LCD_D3_PIN 3
    #define LCD_D4_PIN 4
    #define LCD_D5_PIN 5
    #define LCD_D6_PIN 6
    #define LCD_D7_PIN 7
    
    //Control Pins (here: Analog pins A0..A4)
    #define LCD_RST    A4
    #define LCD_CS     A3
    #define LCD_RS     A2
    #define LCD_WR     A1
    #define LCD_RD     A0
    
    #define BIT0_MSK_8BIT  B00000001
    #define BIT1_MSK_8BIT  B00000010
    #define BIT2_MSK_8BIT  B00000100
    #define BIT3_MSK_8BIT  B00001000
    #define BIT4_MSK_8BIT  B00010000
    #define BIT5_MSK_8BIT  B00100000
    #define BIT6_MSK_8BIT  B01000000
    #define BIT7_MSK_8BIT  B10000000
    
    #define LCD_RST_LOW()  digitalWrite(LCD_RST, LOW)
    #define LCD_RST_HIGH() digitalWrite(LCD_RST, HIGH)
    
    #define LCD_CS_LOW()  digitalWrite(LCD_CS, LOW)
    #define LCD_CS_HIGH() digitalWrite(LCD_CS, HIGH)
    
    #define LCD_RS_LOW()  digitalWrite(LCD_RS, LOW)
    #define LCD_RS_HIGH() digitalWrite(LCD_RS, HIGH)
    
    #define LCD_WR_LOW()  digitalWrite(LCD_WR, LOW)
    #define LCD_WR_HIGH() digitalWrite(LCD_WR, HIGH)
    
    #define LCD_RD_LOW()  digitalWrite(LCD_RD, LOW)
    #define LCD_RD_HIGH() digitalWrite(LCD_RD, HIGH)
    
    //Basic Colors
    #define    LCD_BLACK                   0x0000
    #define    LCD_BLUE                    0x001F
    #define    LCD_RED                     0xF800
    #define    LCD_GREEN                   0x07E0
    #define LCD_CYAN                    0x07FF
    #define LCD_MAGENTA                 0xF81F
    #define LCD_YELLOW                  0xFFE0
    #define LCD_WHITE                   0xFFFF
        
        
    //Other Colors
    #define LCD_CYAN            0x07ff
    #define LCD_BRIGHT_RED      0xf810
    #define LCD_GRAY1           0x8410
    #define LCD_GRAY2           0x4208
    
    //TFT resolution 240*320
    #define LCD_MIN_X       0
    #define LCD_MIN_Y       0
    #define LCD_MAX_X       240
    #define LCD_MAX_Y       320
    
    
    #define swap_uint16_t(a, b) { uint16_t t = a; a = b; b = t; }
    
    #if 1 //Basics
    
    
    void LCD_BusPinsAsOutput()
    {
         pinMode(LCD_D0_PIN,OUTPUT);
         pinMode(LCD_D1_PIN,OUTPUT);
         pinMode(LCD_D2_PIN,OUTPUT);
         pinMode(LCD_D3_PIN,OUTPUT);
         pinMode(LCD_D4_PIN,OUTPUT);
         pinMode(LCD_D5_PIN,OUTPUT);
         pinMode(LCD_D6_PIN,OUTPUT);
         pinMode(LCD_D7_PIN,OUTPUT);
    }
    
    void LCD_BusPinsAsInput()
    {
        pinMode(LCD_D0_PIN,INPUT);
        pinMode(LCD_D1_PIN,INPUT);
        pinMode(LCD_D2_PIN,INPUT);
        pinMode(LCD_D3_PIN,INPUT);
        pinMode(LCD_D4_PIN,INPUT);
        pinMode(LCD_D5_PIN,INPUT);
        pinMode(LCD_D6_PIN,INPUT);
        pinMode(LCD_D7_PIN,INPUT);
    }
    
    uint8_t LCD_BusWrite(byte byteToWrite)
    {
        LCD_BusPinsAsOutput();
        
        digitalWrite(LCD_D0_PIN,byteToWrite & BIT0_MSK_8BIT);
        digitalWrite(LCD_D1_PIN,byteToWrite & BIT1_MSK_8BIT);
        digitalWrite(LCD_D2_PIN,byteToWrite & BIT2_MSK_8BIT);
        digitalWrite(LCD_D3_PIN,byteToWrite & BIT3_MSK_8BIT);
        digitalWrite(LCD_D4_PIN,byteToWrite & BIT4_MSK_8BIT);
        digitalWrite(LCD_D5_PIN,byteToWrite & BIT5_MSK_8BIT);
        digitalWrite(LCD_D6_PIN,byteToWrite & BIT6_MSK_8BIT);
        digitalWrite(LCD_D7_PIN,byteToWrite & BIT7_MSK_8BIT);
        
        return 0;
    }
    
    uint8_t LCD_BusRead()
    {
        uint8_t data=0;
        
        LCD_BusPinsAsInput();
        delay(100);
        data = digitalRead(LCD_D0_PIN)<<0;
        data |= digitalRead(LCD_D1_PIN)<<1;
        data |= digitalRead(LCD_D2_PIN)<<2;
        data |= digitalRead(LCD_D3_PIN)<<3;
        data |= digitalRead(LCD_D4_PIN)<<4;
        data |= digitalRead(LCD_D5_PIN)<<5;
        data |= digitalRead(LCD_D6_PIN)<<6;
        data |= digitalRead(LCD_D7_PIN)<<7;
        
        return data;
    }
    
    void LCD_WriteData_unsafe(uint16_t data)
    {
        LCD_BusWrite(data>>8);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_BusWrite(data);
        LCD_WR_LOW();
        LCD_WR_HIGH();
    }
    
    void LCD_WriteData(uint16_t data)
    {
        
        LCD_CS_LOW();
        LCD_RS_HIGH();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        LCD_BusPinsAsOutput();
        LCD_WriteData_unsafe(data);
        LCD_CS_HIGH();
    }
    
    uint8_t LCD_WriteCommand(uint16_t  cmd_index)
    {
        LCD_CS_LOW();
        LCD_RS_LOW();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        
        LCD_BusPinsAsOutput();
        LCD_BusWrite(cmd_index>>8);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_BusWrite(cmd_index);
        LCD_WR_LOW();
        LCD_WR_HIGH();
        LCD_CS_HIGH();
        
        return 0;    
    }
    
    uint16_t LCD_ReadData()
    {
        uint16_t data=0;
        LCD_CS_LOW();
        LCD_RS_HIGH();
        LCD_RD_HIGH();
        LCD_WR_HIGH();
        LCD_BusPinsAsInput();
        LCD_RD_LOW();
        delayMicroseconds(100);
            data=LCD_BusRead();
        data <<=8;
        LCD_RD_HIGH();
            LCD_RD_LOW();
        delayMicroseconds(100);
        data |= LCD_BusRead();
        LCD_RD_HIGH();
        LCD_CS_HIGH();
        return data;
    }
    
    uint16_t LCD_ReadRegister(uint16_t addr)
    {
        LCD_WriteCommand(addr);
        return LCD_ReadData();        
    }
    
    uint16_t LCD_WriteRegister(uint16_t addr, uint16_t data)
    {
        LCD_WriteCommand(addr);
        LCD_WriteData(data);
    }
    
    void LCD_Init()
    {
        LCD_BusPinsAsOutput();
        LCD_BusWrite(0);
        //Reset Pin
        pinMode(LCD_RST,OUTPUT);
        digitalWrite(LCD_RST, HIGH);
        //Chip Select
        pinMode(LCD_CS,OUTPUT);
        digitalWrite(LCD_CS, HIGH);
        //Register Select
        pinMode(LCD_RS,OUTPUT);
        digitalWrite(LCD_RS, HIGH);
        //Write strobe
        pinMode(LCD_WR,OUTPUT);
        digitalWrite(LCD_WR, HIGH);
        //Read strobe
        pinMode(LCD_RD,OUTPUT);
        digitalWrite(LCD_RD, HIGH);
        
        // -Reset--------------------------------------------------------------------------------------
    
        LCD_RST_LOW();
        delay(100);
        LCD_RST_HIGH();
        delay(100); //1000
        /*LCD_WriteData(0);   // resync
        LCD_WriteData(0);
        LCD_WriteData(0);
        LCD_WriteData(0);*/
        
        delayMicroseconds (200);
            
            LCD_WriteCommand(0x00FF);
        LCD_WriteData(0x0001);
            LCD_WriteCommand(0x00F3);
        LCD_WriteData(0x0008);
            LCD_WriteCommand(0xF1);
        LCD_WriteData(0x00F3);
    
    #if 1        
        LCD_WriteCommand(0x0001);
        LCD_WriteData(0x0100);
        LCD_WriteCommand(0x0002);
        LCD_WriteData(0x0700);
        LCD_WriteCommand(0x0003);
        LCD_WriteData(0x1030);
        LCD_WriteCommand(0x0008);
        LCD_WriteData(0x0302);
        LCD_WriteCommand(0x0009);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0011);
        LCD_WriteData(0x0007);
        LCD_WriteCommand(0x0012);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0013);
        LCD_WriteData(0x0000);
        delayMicroseconds(1000); //1000
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x14B0);
        delayMicroseconds(500);
        LCD_WriteCommand(0x0011);
        LCD_WriteData(0x0007);
        delayMicroseconds(500);    
        LCD_WriteCommand(0x0012);
        LCD_WriteData(0x008E);
        LCD_WriteCommand(0x0013);
        LCD_WriteData(0x0C00);
        LCD_WriteCommand(0x0029);
        LCD_WriteData(0x0015);
        delayMicroseconds(500);    
        LCD_WriteCommand(0x0030);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0031);
        LCD_WriteData(0x0107);
        LCD_WriteCommand(0x0032);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0035);
        LCD_WriteData(0x0203);
        LCD_WriteCommand(0x0036);
        LCD_WriteData(0x0402);
        LCD_WriteCommand(0x0037);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0038);
        LCD_WriteData(0x0207);
        LCD_WriteCommand(0x0039);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x003c);
        LCD_WriteData(0x0203);
        LCD_WriteCommand(0x003d);
        LCD_WriteData(0x0403);
        LCD_WriteCommand(0x0050);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0051);
        LCD_WriteData(0x00EF);
        LCD_WriteCommand(0x0052);
        LCD_WriteData(0x0000);
        LCD_WriteCommand(0x0053);
        LCD_WriteData(0x013F);
        LCD_WriteCommand(0x0060);
        LCD_WriteData(0xA700);
        LCD_WriteCommand(0x0061);
        LCD_WriteData(0x0001);
        LCD_WriteCommand(0x0090);
        LCD_WriteData(0x0029);
    
        LCD_WriteCommand(0x0007);
        LCD_WriteData(0x0133);
        delayMicroseconds(500);
        
        LCD_exitStandBy();
        LCD_WriteCommand(0x0022);
    #endif    
        //paint screen black
        //LCD_PaintScreen(LCD_BLACK);
        LCD_fillScreen(LCD_BLACK);
    }
    
    #endif // Basics
    
    #if 1 //Drawing functions COOCOX Driver
    
        #if 1 //Font
            const unsigned char simpleFont[][8] =
            {
                {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
                {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
                {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
                {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
                {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
                {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
                {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
                {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
                {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
                {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
                {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
                {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
                {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
                {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
                {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
                {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
                {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
                {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
                {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
                {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
                {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
                {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
                {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
                {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
                {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
                {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
                {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
                {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
                {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
                {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
                {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
                {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
                {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
                {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
                {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
                {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
                {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
                {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
                {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
                {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
                {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
                {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
                {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
                {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
                {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
                {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
                {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
                {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
                {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
                {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
                {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
                {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
                {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
                {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
                {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
                {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
                {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
                {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
                {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
                {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
                {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
                {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
                {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
                {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
                {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
                {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
                {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
                {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
                {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
                {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
                {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
                {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
                {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
                {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
                {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
                {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
                {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
                {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
                {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
                {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
                {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
            };        
        #endif
    
    // Makrodefinitionen für char Anzeigerichtung
    #define LEFT2RIGHT  0
    #define DOWN2UP     1
    #define RIGHT2LEFT  2
    #define UP2DOWN     3
    
    static unsigned char DisplayDirect = RIGHT2LEFT;
    
    void LCD_SetXY(uint16_t poX, uint16_t poY)
    {
        LCD_WriteCommand(0x0020);//X
        LCD_WriteData(poX);
        LCD_WriteCommand(0x0021);//Y
        LCD_WriteData(poY);
        LCD_WriteCommand(0x0022);//Start, um zu schreiben, um RAM anzuzeigen
    }
    
    void LCD_goHome(void)
    {
      LCD_SetXY(0,0);
    }
    
    void LCD_fillScreen(uint16_t color) {
      LCD_goHome();
      uint32_t i;
      i = 320;
      i *= 240;
      digitalWrite(LCD_CS, LOW);
      digitalWrite(LCD_RS, HIGH);
      digitalWrite(LCD_RD, HIGH);
      digitalWrite(LCD_WR, HIGH);
      //setWriteDir();
      while (i--) {
        LCD_WriteData_unsafe(color);
      }
      digitalWrite(LCD_CS, HIGH);
    }
    
    void LCD_SetPixel(uint16_t poX, uint16_t poY,uint16_t color)
    {
        LCD_SetXY(poX,poY);
        LCD_WriteData(color);
    }
    
    void LCD_DrawCircle(int16_t poX, int16_t poY, int16_t r,uint16_t color)
    {
        int x = -r, y = 0, err = 2-2*r, e2;
        do {
            LCD_SetPixel(poX-x, poY+y,color);
            LCD_SetPixel(poX+x, poY+y,color);
            LCD_SetPixel(poX+x, poY-y,color);
            LCD_SetPixel(poX-x, poY-y,color);
            e2 = err;
            if (e2 <= y) {
                err += ++y*2+1;
                if (-x == y && e2 <= x) e2 = 0;
            }
            if (e2 > x) err += ++x*2+1;
        } while (x <= 0);
    }
    
    void LCD_DrawLine(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t color)
    {
        int x = x1-x0;
        int y = y1-y0;
        int dx = abs(x), sx = x0<x1 ? 1 : -1;
        int dy = -abs(y), sy = y0<y1 ? 1 : -1;
        int err = dx+dy, e2; /* error value e_xy */
        for (;;)
        {
            // loop
            LCD_SetPixel(x0,y0,color);
            e2 = 2*err;
            if (e2 >= dy)
            {
                // e_xy+e_x > 0
                if (x0 == x1) break;
                err += dy; x0 += sx;
            }
            if (e2 <= dx)
            {  
                //e_xy+e_y < 0
                if (y0 == y1) break;
                err += dx; y0 += sy;
            }
        }
    }
    
    void LCD_DrawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
    {
        unsigned int i;
    
        LCD_SetXY(poX,poY);
        LCD_SetOrientation(1);
        if(length+poY>LCD_MAX_Y)
        {
            length=LCD_MAX_Y-poY;
        }
    
        for(i=0;i<length;i++)
        {
            LCD_WriteData(color);
        }
    }
    
    void LCD_DrawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
    {
        unsigned int i;
    
        LCD_SetXY(poX,poY);
        LCD_SetOrientation(0);
        if(length+poX>LCD_MAX_X)
        {
            length=LCD_MAX_X-poX;
        }
        for(i=0;i<length;i++)
        {
            LCD_WriteData(color);
        }
    }
    
    void LCD_DrawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color)
    {
        LCD_DrawHorizontalLine(poX, poY, length, color);
        LCD_DrawHorizontalLine(poX, poY+width, length, color);
    
        LCD_DrawVerticalLine(poX, poY, width,color);
        LCD_DrawVerticalLine(poX + length, poY, width,color);
    }
    
    void LCD_PaintScreen(uint16_t color)
    {
        unsigned int i, f;
        for(i=0; i<320; i++)
        {
            for(f=0; f<240; f++)
            {
                LCD_WriteData(color);
            }
        }
    }
    
    void LCD_FillCircle(int poX, int poY, int r,unsigned int color)
    {
        int x = -r, y = 0, err = 2-2*r, e2;
        do {
            LCD_DrawVerticalLine(poX-x,poY-y,2*y,color);
            LCD_DrawVerticalLine(poX+x,poY-y,2*y,color);
    
            e2 = err;
            if (e2 <= y) {
                err += ++y*2+1;
                if (-x == y && e2 <= x) e2 = 0;
            }
            if (e2 > x) err += ++x*2+1;
        } while (x <= 0);
    }
    
    void LCD_FillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color)
    {
        unsigned int i;
    
        for(i=0;i<width;i++)
        {
            if(DisplayDirect == LEFT2RIGHT)
            LCD_DrawHorizontalLine(poX, poY+i, length, color);
            else if (DisplayDirect ==  DOWN2UP)
            LCD_DrawHorizontalLine(poX, poY-i, length, color);
            else if(DisplayDirect == RIGHT2LEFT)
            LCD_DrawHorizontalLine(poX, poY-i, length, color);
            else if(DisplayDirect == UP2DOWN)
            LCD_DrawHorizontalLine(poX, poY+i, length, color);
    
        }
    }
    
    void LCD_DrawChar(unsigned int poX, unsigned int poY, unsigned char ascii, unsigned int size, unsigned int fgcolor)
    {
        unsigned char i, f, temp = 0;
    
        LCD_SetXY(poX,poY);
    
        if((ascii < 0x20)||(ascii > 0x7e))//Nicht unterstützte Zeichen..
        {
            ascii = '?';
        }
        for(i=0;i<8;i++)
        {
            temp = simpleFont[ascii-0x20][i];
            for(f=0;f<8;f++)
            {
                if((temp>>f)&0x01)
                {
                    if(DisplayDirect == LEFT2RIGHT)
                    LCD_FillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
                    else if(DisplayDirect == DOWN2UP)
                    LCD_FillRectangle(poX+f*size, poY-i*size, size, size, fgcolor);
                    else if(DisplayDirect == RIGHT2LEFT)
                    LCD_FillRectangle(poX-i*size, poY-f*size, size, size, fgcolor);
                    else if(DisplayDirect == UP2DOWN)
                    LCD_FillRectangle(poX-f*size, poY+i*size, size, size, fgcolor);
                }
            }
        }
    }
    
    void LCD_DrawString(unsigned int poX, unsigned int poY, char *string, unsigned int size, unsigned int fgcolor)
    {
        //unsigned char i;
    
        while(*string != '\0')
        {
            
            //for(i=0;i<8;i++)
            {
                LCD_DrawChar(poX, poY, *string, size, fgcolor);
                
            }
            string++;
            //*string++;
            if(DisplayDirect == LEFT2RIGHT){
                if(poX < LCD_MAX_X){
                    poX += 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == DOWN2UP){
                if(poY > 0){
                    poY -= 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == RIGHT2LEFT) {
                if(poX > 0){
                    poX -= 8*size; // Cursor nach rechts bewegen
                }
            } else if(DisplayDirect == UP2DOWN){
                if(poY < LCD_MAX_Y){
                    poY += 8*size; // Cursor nach rechts bewegen
                }
            }
        }
        
    }
    
    void LCD_DrawBmp(unsigned short ulXs, unsigned short ulYs, unsigned short length, unsigned short height, unsigned short *buf)
    {
        unsigned short i, j;
        unsigned short length_null = 0;
    
        if(ulXs + length > LCD_MAX_X){
            length_null = ulXs + length - LCD_MAX_X;
        }
    
        if(ulYs + height > LCD_MAX_Y){
            height -= ulYs + height - LCD_MAX_Y;
        }
    
        for(j = 0; j < height; j++){
            LCD_SetXY(ulXs, ulYs);
            for(i = 0; i < length; i++){
                LCD_WriteData(*buf++);
            }
            ulYs++;
            buf += length_null;
        }
    }
    
    void LCD_exitStandBy(void)
    {
        LCD_WriteCommand(0x0010);
        LCD_WriteData(0x14E0);
        delayMicroseconds(100);
        LCD_WriteCommand(0x0007);
        LCD_WriteData(0x0133);
    }
    
    void LCD_SetOrientation(uint16_t HV)//horizontal oder vertical
    {
        LCD_WriteCommand(0x03);
        if(HV==1)//vertical
        {
            LCD_WriteData(0x5038); //5038
        }
        else//horizontal
        {
            LCD_WriteData(0x5030); //5030
        }
        LCD_WriteCommand(0x0022); //Start, um zu schreiben, um RAM anzuzeigen
    }
    
    void LCD_SetDisplayDirect(uint8_t Direction)
    {
        DisplayDirect = Direction;
    }
    
    
    #endif
    
        void setup(){
        
        
        
            //Serial.begin(9600);
            //Serial.println("Display Test..\r\n");
            LCD_Init();
            LCD_SetDisplayDirect(3);
                //LCD_SetOrientation(2);
                //LCD_fillScreen(LCD_GRAY1);
                //LCD_PaintScreen(LCD_BLACK);
            //DisplayDirect = UP2DOWN;
            LCD_DrawString(20,140," ",5,LCD_BLUE);
            //LCD_DrawString(60,20," cm ",5,LCD_RED);
            LCD_DrawString(120,20,"Inhalt in cm ",3,LCD_WHITE);
            LCD_DrawString(180,40,"Wassertank ",3,LCD_WHITE);
            

                //LCD_FillRectangle(0,0,239,319,LCD_YELLOW);
            /*
                for(uint8_t x=0;x<200;x++)
            {
                LCD_DrawLine(x,0,x,100,LCD_YELLOW);
            }
                */
            //Read Device ID
            //static uint16_t identifier;
            //uint16_t identifier = LCD_ReadRegister(0x0);
            //Serial.println(identifier,HEX);
        }
        
            
              
        
        
        
        void loop()
      {
      
      // Variablen für Dauer der ping,
          // Und der Abstand Ergebnis in Zoll und Zentimeter:
          long duration, inches, cm;

          
          // Der PING wird mit einem High-Impuls von 2 oder mehr Mikrosekunden ausgelöst.
          // Geben Sie eine kurze LOW Impuls vorher um eine saubere HIGH-Impuls zu gewährleisten:
          pinMode(ledPin, OUTPUT);
          pinMode(pingPin, OUTPUT);
          digitalWrite(pingPin, LOW);
          delayMicroseconds(2);
          digitalWrite(pingPin, HIGH);
          delayMicroseconds(10);
          digitalWrite(pingPin, LOW);
        
          // Der gleiche Ping dient dazu, das Signal von der PING)) zu lesen
          // dessen Dauer ist die Zeit (in Mikrosekunden) vom Senden
          // Die Verbindungsgeschwindigkeit mit dem Empfang sein echo off von dem Objekts.
          pinMode(inPin, INPUT);
          duration = pulseIn(inPin, HIGH);
        
          // Hier wird die Zeit in eine entfernung umgewandelt
          cm = microsecondsToCentimeters(duration);

  char b[4];   //character array erzeugen
  String str = String(cm); //convertiert den Messwert vom Typ long in ein String
  str.toCharArray(b,4); //passing the value of the string to the character array

  char chrStr[4];
  chrStr[0] = str[1];
  chrStr[1] = str[2];
  chrStr[2] = str[3];
  chrStr[3] = str[4];


  LCD_DrawString(60,20,chrStr,5,LCD_RED); //hier sollte jetzt der Messwert ausgegeben werden...
          
           if(cm > 50)
            {
            digitalWrite(ledPin, LOW);
            }
           else
           {
           digitalWrite(ledPin, HIGH);
           }
          
        
          delay(100);
        }
          
          
          long microsecondsToInches(long microseconds){
            // Nach Parallax das Datenblatt für den PING))), gibt es
            // 73,746 Mikrosekunden pro Zoll (dh Schall bei 1130 Fuß pro
            // Sekunde). Dies gibt die Wegstrecke vom Ping,
            // Und zurück, so dass wir durch 2 teilen, müssen um den Abstand zum Hindernisses zu bekommen.
            return microseconds / 74 / 2;}
          
          long microsecondsToCentimeters(long microseconds){
            // Die Schallgeschwindigkeit beträgt 340 m / s oder 29 Mikrosekunden pro Zentimeter.
            return microseconds / 29 / 2;
      
      }

Viele Grüße
Torsten
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
03.06.2015, 22:30
Beitrag #31
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
(03.06.2015 19:10)jgrothe schrieb:  wenn dar draußen im weiten WWW noch jemand versuchen möchte Danke
Wenn Du versuchst, die cm auszugeben bevor sie ermittelt werden, dann kann das ja nicht gehen.

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
05.06.2015, 08:03
Beitrag #32
RE: Hilfe bei einer Füllstandsanzeige für eine Zisterne
Hallo Torsten,

Vielen Dank es wird nun endlich die Entfernung aus gegeben,
habe es gestern nur Kurtz testen könne.
Eine Kleinigkeit muss noch behoben werden,
wenn die Zahl sich ändert wird sie nicht
gelöscht sonder nur überschrieben.
Es entsteht dann ein Rotes Viereck nach einiger Zeit,
aber was wichtig ist es wird die Zahl ausgegeben.
Danke für deine Mühe Gruß Jörg.SmileSmileShy
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
  Ausschaltverzögerung bei einer PV Heizung Hans_Maulwurf 27 732 29.11.2016 23:38
Letzter Beitrag: georg01
  Hilfe: IR Remote Steuerung, MSGEQ7 + RGB-LED Streifen dastob 1 122 14.10.2016 21:40
Letzter Beitrag: hotsystems
Sad Ich brauche Hilfe Prosac 4 235 09.10.2016 18:39
Letzter Beitrag: Prosac
  at24c256 Hilfe Gandalf 6 249 29.08.2016 18:59
Letzter Beitrag: MKc
Smile Progammier Neuling Codeschloss bittet um Hilfe Donalonso 2 286 27.08.2016 18:23
Letzter Beitrag: Binatone
  Hilfe gesucht. Webserver Statsiche und Dynamische HTMl Seite b3ta 11 452 22.08.2016 08:07
Letzter Beitrag: b3ta
  Hilfe: Mega2560 - ENC 28J60 - MYSQL Gandalf 1 181 28.07.2016 16:30
Letzter Beitrag: Gandalf
  Innenwiderstand einer Batterie (Rundzelle 1,5V) Einsteiger94 2 206 24.07.2016 11:42
Letzter Beitrag: SkobyMobil
  Selbstfahrender Roboter Programm änderung hilfe ? arekklone 11 543 06.07.2016 14:59
Letzter Beitrag: Binatone
  Fehlermeldung das eine reimundko 3 307 08.06.2016 08:56
Letzter Beitrag: hotsystems

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste