#define SD_CS 4 // Chip select line for SD card #define TFT_PIN_CS 10 // Arduino-Pin an Display CS #define TFT_PIN_DC 9 // Arduino-Pin an A0 #define TFT_PIN_RST 8 // Arduino Reset-Pin #include #include // Adafruit Grafik-Bibliothek #include // Adafruit ST7735-Bibliothek //#include Adafruit_ST7735 tft = Adafruit_ST7735(TFT_PIN_CS, TFT_PIN_DC, TFT_PIN_RST); // Display-Bibliothek Setup //verschiedene Variablen int start = 0; //int fehler = 0; int menuepunkt = 1; int anschlagverz = 50; int x = 0; //dieses Array beinhaltet die Werte und soll später mal beim Start durch Auslesen der SD-Karte befüllt werden int variable[9]={0,0,0,0,0,0,0,0,0}; //diese Variablen stehen für die Ascii-Werte der Tastatureingaben //über den Serial Monitor oder Putty(w, y, a, d) int cursorhoch = 121; int cursorrunter = 119; int cursorlinks = 100; int cursorrechts = 97; // die Eingänge am Arduino um richtige Taster anzuschließen // die müssen dann eventuell nach Masse "pull-downt" werden int hoch = 2; int runter = 3; int links = 6; int rechts = 7; //diese Variablen sind zur rechtsbündigen Positionierung der Werte auf dem TFT //hier müsste noch eine Schleife hin, die die Werte aus dem Arry ausliest und //die z-Werte entsprechend setzt //die z-Variablen müssen auch noch in ein Array int z1 = 105; int z2 = 105; int z3 = 105; int z4 = 105; int z5 = 105; int z6 = 105; int z7 = 105; int z8 = 105; void setup(void) { tft.initR(INITR_BLACKTAB); // ST7735-Chip initialisieren Serial.begin(9600); pinMode(hoch, INPUT); pinMode(runter, INPUT); pinMode(links, INPUT); pinMode(rechts, INPUT); } void loop() { ////////////// Bildschirm einrichten /////////// if(start == 0){ // Bildschirm mit Farbe fuellen // fillScreen(farbe); tft.fillScreen(ST7735_BLACK); // Fontgroesse setzen // setTextSize(groesse); tft.setTextSize(1); // Schrift umbrechen? // setTextWrap(true); true=Ja, false=Nein tft.setTextWrap(true); // Textposition setzen // setCursor(x,y); tft.setCursor(1,1); // Textfarbe setzen // setTextColor(farbe); tft.setTextColor(ST7735_WHITE); // Text ausgeben // print(text); tft.print("Fernbedienung 0.1"); // Linie zeichnen // drawLine(x_start,y_start,x_ende,y_ende,farbe); tft.drawLine(1,12,126,12,ST7735_GREEN); ////////////// Menuepunkt 1 ///////////////////////// tft.fillRoundRect(4,16,15,15,5,ST7735_RED); tft.setCursor(24,18); tft.print("Punkt1 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z1,18); tft.print(variable[1]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 2 ///////////////////////// tft.drawRoundRect(4,34,15,15,5,ST7735_RED); tft.setCursor(24,36); tft.print("Punkt2 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z2,36); tft.print(variable[2]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 3 ///////////////////////// tft.drawRoundRect(4,52,15,15,5,ST7735_RED); tft.setCursor(24,54); tft.print("Punkt3 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z3,54); tft.print(variable[3]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 4 ///////////////////////// tft.drawRoundRect(4,70,15,15,5,ST7735_RED); tft.setCursor(24,72); tft.print("Punkt4 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z4,72); tft.print(variable[4]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 5 ///////////////////////// tft.drawRoundRect(4,88,15,15,5,ST7735_RED); tft.setCursor(24,90); tft.print("Punkt5 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z5,90); tft.print(variable[5]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 6 ///////////////////////// tft.drawRoundRect(4,106,15,15,5,ST7735_RED); tft.setCursor(24,108); tft.print("Punkt6 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z6,108); tft.print(variable[6]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 7 ///////////////////////// tft.drawRoundRect(4,124,15,15,5,ST7735_RED); tft.setCursor(24,126); tft.print("Punkt7 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z7,126); tft.print(variable[7]); tft.setTextColor(ST7735_WHITE); ////////////// Menuepunkt 8 ///////////////////////// tft.drawRoundRect(4,142,15,15,5,ST7735_RED); tft.setCursor(24,144); tft.print("Punkt8 Wert: "); tft.setTextColor(ST7735_GREEN); tft.setCursor(z8,144); tft.print(variable[8]); // tft.setTextColor(ST7735_WHITE); start = 1; } ////////////// Bildschirm einrichten ende /////////// // die digitalen Eingänge werden abgefragt und simulieren dann // hier eine Tastatureingabe über den Serial Monitor (die Ascii-Werte) if (digitalRead(hoch)== HIGH){delay(anschlagverz); x = cursorhoch;} else if(digitalRead(runter)== HIGH){delay(anschlagverz); x = cursorrunter;} else if(digitalRead(links)== HIGH){delay(anschlagverz); x = cursorlinks;} else if(digitalRead(rechts)== HIGH){delay(anschlagverz); x = cursorrechts;} else{x=0;} //hier wird nach Tastatureingaben über den Serial Monitor gefragt //der Serial Monitor überschreibt ein von den Eingängen gesetztes x if(Serial.available()){ x = Serial.read(); Serial.println(x); } ////////////// Navigation Links Rechts /////////// if(x == cursorlinks || x == cursorrechts){ switch (menuepunkt) { case 1: if(x == cursorlinks){variable[1]++;} if(x == cursorrechts){variable[1]--;} z1 = 110; tft.fillRect(95,16,35,15,ST7735_RED); if(variable[1] < 10 || variable[1] > -1){z1 = 120;} if(variable[1] > 9 || variable[1] < 0){z1 = 115;} if(variable[1] > 99 || variable[1] < -9){z1 = 110;} if(variable[1] > 999 || variable[1] < -99){z1 = 104;} tft.setCursor(z1,18); tft.print(variable[1]); break; case 2: if(x == cursorlinks){variable[2]++;} if(x == cursorrechts){variable[2]--;} z2 = 105; tft.fillRect(95,34,35,15,ST7735_RED); if(variable[2] < 10 || variable[2] > -1){z2 = 120;} if(variable[2] > 9 || variable[2] < 0){z2 = 115;} if(variable[2] > 99 || variable[2] < -9){z2 = 110;} if(variable[2] > 999 || variable[2] < -99){z2 = 104;} tft.setCursor(z2,36); tft.print(variable[2]); break; case 3: if(x == cursorlinks){variable[3]++;} if(x == cursorrechts){variable[3]--;} z3 = 105; tft.fillRect(95,52,35,15,ST7735_RED); if(variable[3] < 10 || variable[3] > -1){z3 = 120;} if(variable[3] > 9 || variable[3] < 0){z3 = 115;} if(variable[3] > 99 || variable[3] < -9){z3 = 110;} if(variable[3] > 999 || variable[3] < -99){z3 = 104;} tft.setCursor(z3,54); tft.print(variable[3]); break; case 4: if(x == cursorlinks){variable[4]++;} if(x == cursorrechts){variable[4]--;} z4 = 105; tft.fillRect(95,70,35,15,ST7735_RED); if(variable[4] < 10 || variable[4] > -1){z4 = 120;} if(variable[4] > 9 || variable[4] < 0){z4 = 115;} if(variable[4] > 99 || variable[4] < -9){z4 = 110;} if(variable[4] > 999 || variable[4] < -99){z4 = 104;} tft.setCursor(z4,72); tft.print(variable[4]); break; case 5: if(x == cursorlinks){variable[5]++;} if(x == cursorrechts){variable[5]--;} z5 = 105; tft.fillRect(95,88,35,15,ST7735_RED); if(variable[5] < 10 || variable[5] > -1){z5 = 120;} if(variable[5] > 9 || variable[5] < 0){z5 = 115;} if(variable[5] > 99 || variable[5] < -9){z5 = 110;} if(variable[5] > 999 || variable[5] < -99){z5 = 104;} tft.setCursor(z5,90); tft.print(variable[5]); break; case 6: if(x == cursorlinks){variable[6]++;} if(x == cursorrechts){variable[6]--;} z6 = 105; tft.fillRect(95,106,35,15,ST7735_RED); if(variable[6] < 10 || variable[6] > -1){z6 = 120;} if(variable[6] > 9 || variable[6] < 0){z6 = 115;} if(variable[6] > 99 || variable[6] < -9){z6 = 110;} if(variable[6] > 999 || variable[6] < -99){z6 = 104;} tft.setCursor(z6,108); tft.print(variable[6]); break; case 7: if(x == cursorlinks){variable[7]++;} if(x == cursorrechts){variable[7]--;} z7 = 105; tft.fillRect(95,124,35,15,ST7735_RED); if(variable[7] < 10 || variable[7] > -1){z7 = 120;} if(variable[7] > 9 || variable[7] < 0){z7 = 115;} if(variable[7] > 99 || variable[7] < -9){z7 = 110;} if(variable[7] > 999 || variable[7] < -99){z7 = 104;} tft.setCursor(z7,126); tft.print(variable[7]); break; case 8: if(x == cursorlinks){variable[8]++;} if(x == cursorrechts){variable[8]--;} z8 = 105; tft.fillRect(95,142,35,15,ST7735_RED); if(variable[8] < 10 || variable[8] > -1){z8 = 120;} if(variable[8] > 9 || variable[8] < 0){z8 = 115;} if(variable[8] > 99 || variable[8] < -9){z8 = 110;} if(variable[8] > 999 || variable[8] < -99){z8 = 104;} tft.setCursor(z8,144); tft.print(variable[8]); break; } }//Ende von if links rechts ////////////// Navigation Hoch Runter /////////// if(x == cursorhoch || x == cursorrunter){ //alten Menüpunkt aufräumen: 2 mal schwarzer Hintergrund, roter Kreis, Wert drüberschreiben switch (menuepunkt) { case 1: tft.fillRoundRect(4,16,15,15,5,ST7735_BLACK); //1 tft.drawRoundRect(4,16,15,15,5,ST7735_RED); //1 tft.fillRect(95,16,35,15,ST7735_BLACK); tft.setCursor(z1,18); tft.print(variable[1]); break; case 2: tft.fillRoundRect(4,34,15,15,5,ST7735_BLACK); //2 tft.drawRoundRect(4,34,15,15,5,ST7735_RED); //2 tft.fillRect(95,34,35,15,ST7735_BLACK); tft.setCursor(z2,36); tft.print(variable[2]); break; case 3: tft.fillRoundRect(4,52,15,15,5,ST7735_BLACK); //3 tft.drawRoundRect(4,52,15,15,5,ST7735_RED); //3 tft.fillRect(95,52,35,15,ST7735_BLACK); tft.setCursor(z3,54); tft.print(variable[3]); break; case 4: tft.fillRoundRect(4,70,15,15,5,ST7735_BLACK); //4 tft.drawRoundRect(4,70,15,15,5,ST7735_RED); //4 tft.fillRect(95,70,35,15,ST7735_BLACK); tft.setCursor(z4,72); tft.print(variable[4]); break; case 5: tft.fillRoundRect(4,88,15,15,5,ST7735_BLACK); //5 tft.drawRoundRect(4,88,15,15,5,ST7735_RED); //5 tft.fillRect(95,88,35,15,ST7735_BLACK); tft.setCursor(z5,90); tft.print(variable[5]); break; case 6: tft.fillRoundRect(4,106,15,15,5,ST7735_BLACK);//6 tft.drawRoundRect(4,106,15,15,5,ST7735_RED);//6 tft.fillRect(95,106,35,15,ST7735_BLACK); tft.setCursor(z6,108); tft.print(variable[6]); break; case 7: tft.fillRoundRect(4,124,15,15,5,ST7735_BLACK);//7 tft.drawRoundRect(4,124,15,15,5,ST7735_RED);//7 tft.fillRect(95,124,35,15,ST7735_BLACK); tft.setCursor(z7,126); tft.print(variable[7]); break; case 8: tft.fillRoundRect(4,142,15,15,5,ST7735_BLACK);//8 tft.drawRoundRect(4,142,15,15,5,ST7735_RED);//8 tft.fillRect(95,142,35,15,ST7735_BLACK); tft.setCursor(z8,144); tft.print(variable[8]); break; } if(x ==cursorhoch){if( menuepunkt < 8){menuepunkt++;}else{menuepunkt = 1;}}// runter if(x == cursorrunter){if(menuepunkt > 1){menuepunkt--;}else {menuepunkt = 8;}} // hoch //neuen Menüpunkt Vollrot machen switch (menuepunkt) { case 1: tft.fillRoundRect(4,16,15,15,5,ST7735_RED); break; case 2: tft.fillRoundRect(4,34,15,15,5,ST7735_RED); break; case 3: tft.fillRoundRect(4,52,15,15,5,ST7735_RED); break; case 4: tft.fillRoundRect(4,70,15,15,5,ST7735_RED); break; case 5: tft.fillRoundRect(4,88,15,15,5,ST7735_RED); break; case 6: tft.fillRoundRect(4,106,15,15,5,ST7735_RED); break; case 7: tft.fillRoundRect(4,124,15,15,5,ST7735_RED); break; case 8: tft.fillRoundRect(4,142,15,15,5,ST7735_RED); break; } } //ende von if hoch-runter }//Ende Loop