Skip to content

Instantly share code, notes, and snippets.

@gallirohik
Created August 22, 2018 02:21
Show Gist options
  • Select an option

  • Save gallirohik/196482131d758981bc10ba9b3b18deed to your computer and use it in GitHub Desktop.

Select an option

Save gallirohik/196482131d758981bc10ba9b3b18deed to your computer and use it in GitHub Desktop.
IOT project (Phillips hue)
#include<ESP8266WiFi.h>
#include<Adafruit_NeoPixel.h>
#include<ESP8266WebServer.h>
#define SSID "Rohik"
#define SSID_PASSWORD "rohik@999"
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 12, NEO_GRB + NEO_KHZ800);
ESP8266WebServer server(80);
void red()
{
uint32_t redColor;
redColor = strip.Color(255, 0, 0);
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, redColor);
}
strip.show();
}
void redmin()
{
uint32_t color;
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
Serial.println("Entered redmin");
int j = 255;
while (j > 0)
{
color = strip.Color(j, 0, 0);
strip.setPixelColor(i, color);
strip.show();
delay(200);
color = strip.Color(0,j, 0);
strip.setPixelColor(i, color);
strip.show();
delay(200);
color = strip.Color(0,0,j);
strip.setPixelColor(i, color);
strip.show();
j = j / 5;
Serial.print("Entered while loop");
Serial.println(j);
}
}
int j=255;
while(j>0)
{
color = strip.Color(j,0,0);
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, color);
strip.show();
}
j=j-5;
}
delay(500);
j=255;
while(j>0)
{
color = strip.Color(0,j,0);
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, color);
strip.show();
}
j=j-5;
}
delay(500);
j=255;
while(j>0)
{
color = strip.Color(0,0,j);
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, color);
strip.show();
}
j=j-5;
}
delay(500);
}
void green()
{
uint32_t greenColor;
greenColor = strip.Color(0, 255, 0);
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, greenColor);
}
strip.show();
}
void blue()
{
uint32_t blueColor;
blueColor = strip.Color(0, 0, 255);
for (uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, blueColor);
}
strip.show();
}
void light()
{
if (server.arg("state") == "red")
{
red();
server.send(200, "text/plain", "red is on");
Serial.println("request is for red color");
}
if (server.arg("state") == "green")
{
green();
server.send(200, "text/plain", "green is on");
Serial.println("request is for green color");
}
if (server.arg("state") == "blue")
{
blue();
server.send(200, "text/plain", "blue is on");
Serial.println("request is for blue color");
}
if (server.arg("state") == "redmin")
{
server.send(200, "text/plain", "redmin is on");
redmin();
Serial.println("request is for redmin color");
}
}
void setup()
{
// put your setup code here, to run once:
WiFi.begin(SSID, SSID_PASSWORD);
Serial.begin(115200);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
//print local ip address of this HDK
Serial.print("IP address:");
Serial.println(WiFi.localIP());
server.begin();
server.on("/light", light);
//server.onNotFound(handleNotfound);
strip.begin();
}
void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment