Alfred Jeson
Published © GPL3+

Adverse

No boring screens! street ads that surprise with your step. High-impact moments, boosted engagement, and most of all making it memorable

BeginnerFull instructions provided1 hour78
Adverse

Things used in this project

Hardware components

Seeed Studio XIAO ESP32S3 Sense
Seeed Studio XIAO ESP32S3 Sense
×1
micro limit switch
×1
KCD1-102-SPDT Rocker Switch-3Pin
×1
400mAh 3.7V Single Cell Rechargeable LiPo Battery
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Design

Schematics

Circuit

Code

Code

C/C++
#include <WiFi.h>
#include <WebServer.h>

const char* ssid       = "vivo Y22";
const char* password   = "abc456###";
const int   buttonPin  = D1;  // Make sure D1 maps correctly on your ESP32 board

WebServer server(80);

bool        showImage    = false;
unsigned long releaseTime = 0;
bool        lastState    = HIGH;

String getPage() {
  String ip           = WiFi.localIP().toString();
  String wifiStatus   = (WiFi.status() == WL_CONNECTED) ? "Connected" : "Disconnected";
  String buttonStatus = showImage ? "VISIBLE" : "HIDDEN";

  // Choose display property based on showImage
  String display = showImage ? "block" : "none";

  return R"rawliteral(
<!DOCTYPE html>
<html>
<head>
  <title>ESP32 Full-Screen Image</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="refresh" content="1">
  <style>
    html, body {
      margin: 0;
      padding: 0;
      width: 100vw;
      height: 100vh;
      background: black;
      overflow: hidden;
    }
    #image {
      position: absolute;
      top: 0; left: 0;
      width: 100vw;
      height: 100vh;
      object-fit: cover;
      display: )rawliteral"
      + display +
     R"rawliteral(;
    }
    .status {
      position: absolute;
      bottom: 10px;
      left: 10px;
      color: white;
      font-family: sans-serif;
      font-size: 1rem;
      background: rgba(0,0,0,0.5);
      padding: 5px 10px;
      border-radius: 4px;
    }
  </style>
</head>
<body>
  <img id="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSnyECOT9jFcgZ_TzeGFTA98etZiq-VDvepGQ&s" />

</body>
</html>
)rawliteral";
}

void handleRoot() {
  server.send(200, "text/html", getPage());
}

void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP);

  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");
  int retries = 0;
  while (WiFi.status() != WL_CONNECTED && retries < 20) {
    delay(500);
    Serial.print(".");
    retries++;
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("\nConnected, IP: " + WiFi.localIP().toString());
  } else {
    Serial.println("\nFailed to connect.");
  }

  server.on("/", handleRoot);
  server.begin();
  Serial.println("Web server started.");
}

void loop() {
  server.handleClient();

  bool currentState = digitalRead(buttonPin);

  // Button just released?
  if (lastState == LOW && currentState == HIGH) {
    releaseTime = millis();     // start 5s timer
    showImage   = true;         // show immediately on release
  }

  // Hide after 5 seconds
  if (showImage && (millis() - releaseTime > 5000)) {
    showImage = false;
  }

  // If button held down, keep image visible
  if (currentState == LOW) {
    showImage = true;
  }

  lastState = currentState;
}

Credits

Alfred Jeson
1 project • 1 follower

Comments