Advertisement
RaspBar

ESP8266_IP_MAC-ST7735

Jul 6th, 2022 (edited)
723
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_ST7735.h>
  5.  
  6. const char* ssid = "mySSID";
  7. const char* password = "myPassword";
  8.  
  9. //LED Setup
  10. int LEDrot = D0;
  11. int LEDblau = D3;
  12.  
  13. // ST7735 TFT Verbindungen
  14. #define TFT_RST   -1
  15. #define TFT_CS    D8
  16. #define TFT_DC    D4
  17.  
  18. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
  19.  
  20. byte mac[6];
  21. IPAddress ip;
  22.  
  23. void setup() {
  24.   //LED initialisieren -> LED aus
  25.   pinMode(LEDrot, OUTPUT);
  26.   pinMode(LEDblau,OUTPUT);
  27.   digitalWrite(LEDrot, LOW);
  28.   digitalWrite(LEDblau, LOW);
  29.  
  30.   tft.initR(INITR_BLACKTAB);
  31.   tft.fillScreen(ST7735_BLACK);
  32.  
  33.   // statische Anzeige
  34.   tft.drawFastHLine(0, 50,  tft.width(), ST7735_WHITE);
  35.   tft.drawFastHLine(0, 106,  tft.width(), ST7735_WHITE);
  36.   tft.setTextColor(ST7735_ORANGE, ST7735_BLACK);
  37.   tft.setTextSize(1);
  38.   tft.setCursor(4, 16);   tft.print("ESP8266 + ST7735 TFT");
  39.   tft.setCursor(12, 33);  tft.print("IP- & MAC-Adresse");
  40.   tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  41.   tft.setCursor(32, 61);  tft.print("IP-Adresse");
  42.   tft.setCursor(30, 118); tft.print("MAC-Adresse");
  43.  
  44.   WiFi.mode(WIFI_STA);
  45.   WiFi.begin(ssid, password);  
  46.  
  47.   while (WiFi.status() != WL_CONNECTED) {
  48.     delay(1000);
  49.   }
  50.  
  51.   ip = WiFi.localIP();
  52.   WiFi.macAddress(mac);
  53.  
  54. }
  55.  
  56. void loop() {
  57.   // Anzeige IP-Adresse
  58.   tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
  59.   tft.setCursor(19, 82);  tft.print(ip);
  60.  
  61.   // Anzeige MAC-Adresse
  62.   tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);  
  63.   tft.setCursor(14, 140); tft.print(mac[0],HEX); tft.print(":");
  64.   tft.print(mac[1],HEX);  tft.print(":");
  65.   tft.print(mac[2],HEX);  tft.print(":");
  66.   tft.print(mac[3],HEX);  tft.print(":");
  67.   tft.print(mac[4],HEX);  tft.print(":");
  68.   tft.print(mac[5],HEX);
  69. }
  70.  
Advertisement
RAW Paste Data Copied
Advertisement