Go Down

Topic: button html for esp8266 and neopixel (Read 74 times) previous topic - next topic

met98

hi, I wanted to create an html page in my esp8266 to manage 2 neopixel LEDs, but I don't understand how I can create a "white" button to set the string
strip1.setPixelColor(i, strip1.Color( 255, 255, 255 ) );

Code: [Select]

#include <Adafruit_NeoPixel.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#define LED_PIN1    5 //D1
#define LED_COUNT1  8 //numero led
#define LED_PIN2    4 //D2
#define LED_COUNT2  8 //numero led
#define APSSID "wifi_home"
#define APPSK  "testtest"
////#define APSSID "ESPHelm"         // disabilitare per abilitare collegamento a router
////#define APPSK  "12345678"        // disabilitare per abilitare collegamento a router
////IPAddress    myIP(99, 99, 99, 99);
int brightness1 = 10;  //luminosità 150 è il max
int brightness2 = 10;  //luminosità 150 è il max

const char *ssid = APSSID;
const char *password = APPSK;

ESP8266WebServer server ( 80 );

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(LED_COUNT1, LED_PIN1, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(LED_COUNT2, LED_PIN2, NEO_RGB + NEO_KHZ800);
const int led = 13;

void setup ( void ) {
  Serial.begin ( 115200 );
  strip1.setBrightness(brightness1);
  strip1.begin();
  strip1.show();
  strip2.setBrightness(brightness2);
  strip2.begin();
  strip2.show();
  delay(50);
  pinMode ( led, OUTPUT );
  digitalWrite ( led, 0 );
  ////WiFi.mode(WIFI_AP_STA);                                     // disabilitare per abilitare collegamento a router
  ////WiFi.softAPConfig(myIP, myIP, IPAddress(255, 255, 255, 0)); // disabilitare per abilitare collegamento a router
  ////WiFi.softAP(ssid, password);                                // disabilitare per abilitare collegamento a router
  ////IPAddress myIP = WiFi.softAPIP();                           // disabilitare per abilitare collegamento a router
  WiFi.begin ( ssid, password );
  server.on ( "/", handleRoot );
  server.begin();
}

void loop ( void ) {
  server.handleClient();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void handleRoot() {
  digitalWrite ( led, 1 );
  String color = server.arg("c");
 
  // setting the color to the strip
  Colorvar(color);

  // building a website
  char temp[5000];
  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;
  char clr [7];
  color.toCharArray(clr, 7);
  snprintf ( temp, 5000,

"<!DOCTYPE html>\n<html>\n\
  <head>\n\
    <title>Esp8266 Controler</title>\n\
    <style>\
      body { background-color: #cccccc; font-family: Arial; Color: #008; }\
    </style>\n\
    <meta name=\"viewport\" content=\"width=device-width, height=device-height, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0\" />\n\
  </head>\n\
  <body>\n\
    <h1>Esp8266 Controler Neopixel</h1>\n\
    <p>Acceso da: %02d:%02d:%02d</p>\n\
    \n\
    <form action=\"\" name=\"pick\" method=\"post\">\n\
    <input type=\"color\" name=\"c\" value=\"%02d\" onchange=\"document.forms['pick'].submit();\" />\n\
    <input type=\"submit\" name=\"c\" value=\"white\" onclick=\"Color1();\"  />\n\
    <a href=\"/?on\" target=\"inlineframe\">ON</a>
    </form>\n\
    \n\
  </body>\
</html>",
 
    hr, min % 60, sec % 60, clr
  );
  server.send ( 200, "text/html", temp );
  digitalWrite ( led, 0 );
}

void Colorvar(String value){

    int number = (int) strtol( &value[1], NULL, 16);
    int r = number >> 16;
    int g = number >> 8 & 0xFF;
    int b = number & 0xFF;

   for(int i=0; i < LED_COUNT1; i++) {
      strip1.setPixelColor(i, strip1.Color( g, r, b ) );
    }
    strip1.show();
}

void Color1(String value){

   for(int i=0; i < LED_COUNT1; i++) {
      strip1.setPixelColor(i, strip1.Color( 255, 255, 255 ) );
    }
    strip1.show();
}

Go Up