Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
- #include <SPI.h>
- #include <SD.h>
- /* pins definitions */
- #define TFT_CS 16
- #define TFT_DC 17
- #define TFT_RESET 4
- File myFile;
- #define SD_CS 5
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RESET);
- boolean insertSD = false;
- boolean pressed = false;
- int Menuoption = 1;
- const int buttonPin = 32;
- void setup() {
- Serial.begin(9600);
- Serial.println(F("Hello! ST77xx TFT Test"));
- pinMode(buttonPin, INPUT);
- // TFT display initialization
- tft.initR(INITR_BLACKTAB);
- Serial.println(F("TFT Initialized"));
- tft.fillScreen(ST77XX_BLACK);
- tft.setTextColor(ST77XX_RED);
- tft.setTextWrap(false);
- tft.setCursor(1,5);
- tft.print("Initialisierung");
- delay(1000);
- tft.print(".");
- delay(1000);
- tft.print(".");
- delay(1000);
- tft.print(".");
- delay(250);
- // SD card initialization+
- if (!SD.begin(SD_CS)) {
- Serial.println("Keine SD-Karte eingelegt oder Initialisierung fehlgeschlagen!");
- janein("Nein", "SD-Karte",2,23);
- insertSD = false;
- } else {
- Serial.println("SD-Karte eingelegt und Initialisierung erfolgreich");
- janein("Ja", "SD-Karte",2,23);
- insertSD = true;
- }
- File myFile = SD.open("test.txt", FILE_WRITE); //----------------------------------------------------------------------------
- myFile.close();
- delay(1000);
- //MENU
- Menu(1);
- delay(2000);
- down();
- delay(500);
- }
- void loop() {
- }
- void down() {
- cross(10, 28 + 10 * Menuoption, ST77XX_BLACK); // Hier wird deine Funktion ausgeführt
- Menuoption++;
- delay(100);
- cross(10, 28 + 10 * Menuoption, ST77XX_RED);
- Serial.println("test");
- File myFile = SD.open("test.txt", FILE_WRITE); //----------------------------------------------------------------------------
- myFile.close();
- }
- void Menu(int Menuoption){
- tft.fillScreen(ST77XX_BLACK);
- tft.drawFastHLine(5, 25,118, ST77XX_RED);
- tft.setTextColor(ST77XX_WHITE);
- tft.setCursor(15, 8);
- tft.setTextSize(2);
- tft.print("-Q-Menu-");
- tft.setTextSize(1);
- tft.setCursor(15, 35);
- delay(200);
- tft.print("Transmit Radio");
- tft.setCursor(15, 45);
- delay(200);
- tft.print("Infrared");
- tft.setCursor(15, 55);
- delay(200);
- tft.setCursor(15, 55);
- tft.print("Wlan");
- cross(10, 28 + 10 * Menuoption, ST77XX_RED); //55
- }
- void cross(int crossx, int crossy, uint16_t color) {
- tft.drawPixel(crossx, crossy, color);
- tft.drawPixel(crossx -1, crossy - 1, color);
- tft.drawPixel(crossx - 1, crossy - 0, color);
- tft.drawPixel(crossx - 1, crossy +1, color);
- tft.drawPixel(crossx - 2, crossy + 0, color);
- tft.drawPixel(crossx - 2, crossy - 1, color);
- tft.drawPixel(crossx - 2, crossy - 2, color);
- tft.drawPixel(crossx - 2, crossy + 1, color);
- tft.drawPixel(crossx - 2, crossy + 2, color);
- tft.drawPixel(crossx - 3, crossy - 0, color);
- tft.drawPixel(crossx - 4, crossy - 0, color);
- tft.drawPixel(crossx - 5, crossy - 0, color);
- }
- void janein(String jaOderNein, String zusatzString, int Xjn, int Yjn) {
- // Überprüfe, ob der Eingabetext "Ja" oder "ja" lautet
- if (jaOderNein.equalsIgnoreCase("Ja")) {
- tft.setCursor(Xjn, Yjn);
- tft.setTextColor(ST77XX_WHITE);
- tft.setTextSize(1);
- tft.print("(");
- tft.setTextColor(ST77XX_GREEN);
- tft.print("Ok");
- tft.setTextColor(ST77XX_WHITE);
- tft.print(")" + zusatzString);
- }
- // Überprüfe, ob der Eingabetext "Nein" oder "nein" lautet
- else if (jaOderNein.equalsIgnoreCase("Nein")) {
- tft.setCursor(Xjn, Yjn);
- tft.setTextColor(ST77XX_WHITE);
- tft.setTextSize(1);
- tft.print("(");
- tft.setTextColor(ST77XX_RED);
- tft.print("No");
- tft.setTextColor(ST77XX_WHITE);
- tft.print(")" + zusatzString);
- }
- // Wenn der Eingabetext weder "Ja" noch "Nein" entspricht
- else {
- Serial.println("Ungültige Eingabe. Bitte antworte mit 'Ja' oder 'Nein'.");
- }
- }
- void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
- Serial.printf("Listing directory: %s\n", dirname);
- File root = fs.open(dirname);
- if(!root){
- Serial.println("Failed to open directory");
- return;
- }
- if(!root.isDirectory()){
- Serial.println("Not a directory");
- return;
- }
- File file = root.openNextFile();
- while(file){
- if(file.isDirectory()){
- Serial.print(" DIR : ");
- Serial.println(file.name());
- if(levels){
- listDir(fs, file.path(), levels -1);
- }
- } else {
- Serial.print(" FILE: ");
- Serial.print(file.name());
- Serial.print(" SIZE: ");
- Serial.println(file.size());
- }
- file = root.openNextFile();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement