Advertisement
Guest User

Untitled

a guest
Apr 14th, 2024
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. #include <Adafruit_GFX.h> // Core graphics library
  2. #include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
  3. #include <SPI.h>
  4. #include <SD.h>
  5.  
  6. /* pins definitions */
  7. #define TFT_CS 16
  8. #define TFT_DC 17
  9. #define TFT_RESET 4
  10. File myFile;
  11. #define SD_CS 5
  12.  
  13. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RESET);
  14. boolean insertSD = false;
  15. boolean pressed = false;
  16. int Menuoption = 1;
  17.  
  18. const int buttonPin = 32;
  19.  
  20. void setup() {
  21. Serial.begin(9600);
  22. Serial.println(F("Hello! ST77xx TFT Test"));
  23. pinMode(buttonPin, INPUT);
  24.  
  25. // TFT display initialization
  26. tft.initR(INITR_BLACKTAB);
  27. Serial.println(F("TFT Initialized"));
  28. tft.fillScreen(ST77XX_BLACK);
  29. tft.setTextColor(ST77XX_RED);
  30. tft.setTextWrap(false);
  31. tft.setCursor(1,5);
  32. tft.print("Initialisierung");
  33. delay(1000);
  34. tft.print(".");
  35. delay(1000);
  36. tft.print(".");
  37. delay(1000);
  38. tft.print(".");
  39. delay(250);
  40.  
  41. // SD card initialization+
  42. if (!SD.begin(SD_CS)) {
  43. Serial.println("Keine SD-Karte eingelegt oder Initialisierung fehlgeschlagen!");
  44. janein("Nein", "SD-Karte",2,23);
  45. insertSD = false;
  46. } else {
  47. Serial.println("SD-Karte eingelegt und Initialisierung erfolgreich");
  48. janein("Ja", "SD-Karte",2,23);
  49. insertSD = true;
  50. }
  51.  
  52. File myFile = SD.open("test.txt", FILE_WRITE); //----------------------------------------------------------------------------
  53. myFile.close();
  54.  
  55. delay(1000);
  56. //MENU
  57. Menu(1);
  58. delay(2000);
  59. down();
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. delay(500);
  67. }
  68.  
  69. void loop() {
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76. void down() {
  77. cross(10, 28 + 10 * Menuoption, ST77XX_BLACK); // Hier wird deine Funktion ausgeführt
  78. Menuoption++;
  79. delay(100);
  80. cross(10, 28 + 10 * Menuoption, ST77XX_RED);
  81. Serial.println("test");
  82. File myFile = SD.open("test.txt", FILE_WRITE); //----------------------------------------------------------------------------
  83. myFile.close();
  84. }
  85.  
  86. void Menu(int Menuoption){
  87. tft.fillScreen(ST77XX_BLACK);
  88. tft.drawFastHLine(5, 25,118, ST77XX_RED);
  89. tft.setTextColor(ST77XX_WHITE);
  90. tft.setCursor(15, 8);
  91. tft.setTextSize(2);
  92. tft.print("-Q-Menu-");
  93. tft.setTextSize(1);
  94. tft.setCursor(15, 35);
  95. delay(200);
  96. tft.print("Transmit Radio");
  97. tft.setCursor(15, 45);
  98. delay(200);
  99. tft.print("Infrared");
  100. tft.setCursor(15, 55);
  101. delay(200);
  102. tft.setCursor(15, 55);
  103. tft.print("Wlan");
  104. cross(10, 28 + 10 * Menuoption, ST77XX_RED); //55
  105.  
  106.  
  107. }
  108.  
  109. void cross(int crossx, int crossy, uint16_t color) {
  110. tft.drawPixel(crossx, crossy, color);
  111. tft.drawPixel(crossx -1, crossy - 1, color);
  112. tft.drawPixel(crossx - 1, crossy - 0, color);
  113. tft.drawPixel(crossx - 1, crossy +1, color);
  114. tft.drawPixel(crossx - 2, crossy + 0, color);
  115. tft.drawPixel(crossx - 2, crossy - 1, color);
  116. tft.drawPixel(crossx - 2, crossy - 2, color);
  117. tft.drawPixel(crossx - 2, crossy + 1, color);
  118. tft.drawPixel(crossx - 2, crossy + 2, color);
  119. tft.drawPixel(crossx - 3, crossy - 0, color);
  120. tft.drawPixel(crossx - 4, crossy - 0, color);
  121. tft.drawPixel(crossx - 5, crossy - 0, color);
  122.  
  123. }
  124.  
  125. void janein(String jaOderNein, String zusatzString, int Xjn, int Yjn) {
  126. // Überprüfe, ob der Eingabetext "Ja" oder "ja" lautet
  127. if (jaOderNein.equalsIgnoreCase("Ja")) {
  128. tft.setCursor(Xjn, Yjn);
  129. tft.setTextColor(ST77XX_WHITE);
  130. tft.setTextSize(1);
  131. tft.print("(");
  132. tft.setTextColor(ST77XX_GREEN);
  133. tft.print("Ok");
  134. tft.setTextColor(ST77XX_WHITE);
  135. tft.print(")" + zusatzString);
  136. }
  137. // Überprüfe, ob der Eingabetext "Nein" oder "nein" lautet
  138. else if (jaOderNein.equalsIgnoreCase("Nein")) {
  139. tft.setCursor(Xjn, Yjn);
  140. tft.setTextColor(ST77XX_WHITE);
  141. tft.setTextSize(1);
  142. tft.print("(");
  143. tft.setTextColor(ST77XX_RED);
  144. tft.print("No");
  145. tft.setTextColor(ST77XX_WHITE);
  146. tft.print(")" + zusatzString);
  147. }
  148. // Wenn der Eingabetext weder "Ja" noch "Nein" entspricht
  149. else {
  150. Serial.println("Ungültige Eingabe. Bitte antworte mit 'Ja' oder 'Nein'.");
  151. }
  152. }
  153.  
  154.  
  155. void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
  156. Serial.printf("Listing directory: %s\n", dirname);
  157.  
  158. File root = fs.open(dirname);
  159. if(!root){
  160. Serial.println("Failed to open directory");
  161. return;
  162. }
  163. if(!root.isDirectory()){
  164. Serial.println("Not a directory");
  165. return;
  166. }
  167.  
  168. File file = root.openNextFile();
  169. while(file){
  170. if(file.isDirectory()){
  171. Serial.print(" DIR : ");
  172. Serial.println(file.name());
  173. if(levels){
  174. listDir(fs, file.path(), levels -1);
  175. }
  176. } else {
  177. Serial.print(" FILE: ");
  178. Serial.print(file.name());
  179. Serial.print(" SIZE: ");
  180. Serial.println(file.size());
  181. }
  182. file = root.openNextFile();
  183. }
  184. }
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement