Currently have an html which on a button click, sends a variable to xml.
That variable sets the blink delay level and sets another variable for use in another function.
On its own, the blink works perfectly on the one or more LEDS.
However, introducing the neopixel to start up seems to kill the LED blink.
Also, the start of the neo pixel light up function will continue without being reset by a new button and variable change and seems to continue to end, then reloop, regardless of new inputs. It's almost like a new variable (from button) needs to stop the LED function, then restart to latest function variable. It's likely that the neopixel function call should not be in Loop() so it only runs once, but the function (server.handleClien() ) that receives the variable from html is in the loop, continuously listening. Unsure how to break them up.
So:
Q1: why would neopixels starting stop the regular LEDs?
Q2: how to trigger a new neopixel function call from button changes?
some of the code:
// initiates the pins to be used
pinMode(LED_BUILTIN, OUTPUT); // LED #1
pinMode(PIN, OUTPUT); //LED #2 , note that neopixel strip is on D2, addressed in header, works and its #1 and #1 that turn off when the neopixel come on
strip.begin();
strip.show();
}
void loop() {
server.handleClient();
if(blinkDelay > 0){
blinkLed(); /blinks the LEDS with the current buttonvalue, changes as button changes
blinkLed2();
}
if (minutes > 0){ //added to see if this would help
strip.show();
timer(minutes); function to run which can't be interruppted, uses the first button value, loops continuously
}
}
Neopixel strip on turns off other LEDs
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Neopixel strip on turns off other LEDs
Post your entire code so we can see what is happening. Please use
Code: Select all
tags when posting code or logs to the forums by clicking the </> button above the reply box and pasting your code between the tags created. Also explain your connections to everything and how you are powering them.
- scotch1
- Posts: 246
- Joined: Mon Nov 26, 2012 12:13 am
Re: Neopixel strip on turns off other LEDs
connect an led to D1 and 8 piece neopixel to D2.
Note that there is what looks to be a lot of unused code, but the xml section gets the inputs from a small html page after connecting to the esp's wireless (michalemax). The html (code after Arduino and needs to be uploaded to the ESP) buttons are supposed to generate a minute value which is used to call a timer(minutes) function and cycle through.
Note that there is what looks to be a lot of unused code, but the xml section gets the inputs from a small html page after connecting to the esp's wireless (michalemax). The html (code after Arduino and needs to be uploaded to the ESP) buttons are supposed to generate a minute value which is used to call a timer(minutes) function and cycle through.
Code: Select all
/* Create a WiFi access point and provide a web server on it. */
/* Create a WiFi access point and provide a web server on it. */
/* Once data file is uploaded... access at 192.168.4.1/index.html */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#include <Adafruit_NeoPixel.h> // for neopixels
/* Set these to your desired credentials. */
const char *ssid = "michaelmax";
const char *password = "";
ESP8266WebServer server(80);
#define PIN D1 // for the LED light on off
#define PIN2 D2 // for the LED strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN2, NEO_GRB + NEO_KHZ800);
File fsUploadFile;
// added variable for the later functions
int x , y, z;
int blinkDelay = 0;
int minutes; // initialize the time to nothing
int flash = 50;
int p1 = 0; //led to light up
int p2 = 7; //led to light up
int p3 = 3; //led to light up
int bright = 100; // brightness level and controls the entire light anc olor level get input
//format bytes
String formatBytes(size_t bytes){
if (bytes < 1024){
return String(bytes)+"B";
} else if(bytes < (1024 * 1024)){
return String(bytes/1024.0)+"KB";
} else if(bytes < (1024 * 1024 * 1024)){
return String(bytes/1024.0/1024.0)+"MB";
} else {
return String(bytes/1024.0/1024.0/1024.0)+"GB";
}
}
String getContentType(String filename){
if(server.hasArg("download")) return "application/octet-stream";
else if(filename.endsWith(".htm")) return "text/html";
else if(filename.endsWith(".html")) return "text/html";
else if(filename.endsWith(".css")) return "text/css";
else if(filename.endsWith(".js")) return "application/javascript";
else if(filename.endsWith(".png")) return "image/png";
else if(filename.endsWith(".gif")) return "image/gif";
else if(filename.endsWith(".jpg")) return "image/jpeg";
else if(filename.endsWith(".ico")) return "image/x-icon";
else if(filename.endsWith(".xml")) return "text/xml";
else if(filename.endsWith(".pdf")) return "application/x-pdf";
else if(filename.endsWith(".zip")) return "application/x-zip";
else if(filename.endsWith(".gz")) return "application/x-gzip";
return "text/plain";
}
bool handleFileRead(String path){
Serial.println("handleFileRead: " + path);
//**************************** XML buttons to control the function
if(path == "/5"){ // was 1000
Serial.println("blink delay is 1000");
blinkDelay = 1000;
minutes = 5;
strip.show();
}
if(path == "/1"){ //was 500
Serial.println("blink delay is 500");
blinkDelay = 500;
minutes = 1;
strip.show();
}
if(path == "/4"){ //was 100
Serial.println("blink delay is 100");
blinkDelay = 100;
minutes = 4;
strip.show();
}
if(path == "/6"){ //was 50 if 6 is reported blink at 50 milis
Serial.println("blink delay is 50");
blinkDelay = 50;
minutes = 6;
strip.show();
}
/* if(path == "/p0"){
Serial.print("~p0R");
turnOnLed();
}
if(path == "/p20"){
Serial.print("~p20R");
turnOffLed();
}
if(path == "/p40"){
Serial.print("~p40R");
}
if(path == "/p60"){
Serial.print("~p60R");
}
if(path == "/p80"){
Serial.print("~p80R");
}
if(path == "/p99"){
Serial.print("~p99R");
}
if(path == "/collision"){
Serial.print("~collisionR");
}
if(path == "/pastelSparkles"){
Serial.print("~pastelSparklesR");
}
if(path == "/rainbowClumps"){
Serial.print("~rainbowClumpsR");
}
if(path == "/colorExplosion"){
Serial.print("~colorExplosionR");
}
*/
//removed the functions to leave 4 buttons
if(path.endsWith("/")) path += "index.htm";
String contentType = getContentType(path);
String pathWithGz = path + ".gz";
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){
if(SPIFFS.exists(pathWithGz))
path += ".gz";
File file = SPIFFS.open(path, "r");
size_t sent = server.streamFile(file, contentType);
file.close();
return true;
}
return false;
}
void handleFileUpload(){
if(server.uri() != "/edit") return;
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
String filename = upload.filename;
if(!filename.startsWith("/")) filename = "/"+filename;
Serial.print("handleFileUpload Name: "); Serial.println(filename);
fsUploadFile = SPIFFS.open(filename, "w");
filename = String();
} else if(upload.status == UPLOAD_FILE_WRITE){
//Serial.print("handleFileUpload Data: "); Serial.println(upload.currentSize);
if(fsUploadFile)
fsUploadFile.write(upload.buf, upload.currentSize);
} else if(upload.status == UPLOAD_FILE_END){
if(fsUploadFile)
fsUploadFile.close();
Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize);
}
}
void handleFileDelete(){
if(server.args() == 0) return server.send(500, "text/plain", "BAD ARGS");
String path = server.arg(0);
Serial.println("handleFileDelete: " + path);
if(path == "/")
return server.send(500, "text/plain", "BAD PATH");
if(!SPIFFS.exists(path))
return server.send(404, "text/plain", "FileNotFound");
SPIFFS.remove(path);
server.send(200, "text/plain", "");
path = String();
}
void handleFileCreate(){
if(server.args() == 0)
return server.send(500, "text/plain", "BAD ARGS");
String path = server.arg(0);
Serial.println("handleFileCreate: " + path);
if(path == "/")
return server.send(500, "text/plain", "BAD PATH");
if(SPIFFS.exists(path))
return server.send(500, "text/plain", "FILE EXISTS");
File file = SPIFFS.open(path, "w");
if(file)
file.close();
else
return server.send(500, "text/plain", "CREATE FAILED");
server.send(200, "text/plain", "");
path = String();
}
void handleFileList() {
if(!server.hasArg("dir")) {server.send(500, "text/plain", "BAD ARGS"); return;}
https://forums.adafruit.com/posting.php?mode=reply&f=47&t=110401
String path = server.arg("dir");
Serial.println("handleFileList: " + path);
Dir dir = SPIFFS.openDir(path);
path = String();
String output = "[";
while(dir.next()){
File entry = dir.openFile("r");
if (output != "[") output += ',';
bool isDir = false;
output += "{\"type\":\"";
output += (isDir)?"dir":"file";
output += "\",\"name\":\"";
output += String(entry.name()).substring(1);
output += "\"}";
entry.close();
}
output += "]";
server.send(200, "text/json", output);
}
/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
server.send(200, "text/html", "<h1>You are connected</h1>");
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
//server.on("/", handleRoot);
//server.begin();
//Serial.println("HTTP server started");
SPIFFS.begin();
{
Dir dir = SPIFFS.openDir("/");
while (dir.next()) {
String fileName = dir.fileName();
size_t fileSize = dir.fileSize();
Serial.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
}
Serial.printf("\n");
}
//SERVER INIT
//list directory
server.on("/list", HTTP_GET, handleFileList);
//load editor
server.on("/edit", HTTP_GET, [](){
if(!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound");
});
//create file
server.on("/edit", HTTP_PUT, handleFileCreate);
//delete file
server.on("/edit", HTTP_DELETE, handleFileDelete);
//first callback is called after the request has ended with all parsed arguments
//second callback handles file uploads at that location
server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload);
//called when the url is not defined here
//use it to load content from SPIFFS
server.onNotFound([](){
if(!handleFileRead(server.uri()))
server.send(404, "text/plain", "FileNotFound");
});
//get heap status, analog input value and all GPIO statuses in one json call
server.on("/all", HTTP_GET, [](){
String json = "{";
json += "\"heap\":"+String(ESP.getFreeHeap());
json += ", \"analog\":"+String(analogRead(A0));
json += ", \"gpio\":"+String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
json += "}";
server.send(200, "text/json", json);
json = String();
});
server.begin();
Serial.println("HTTP server started");
// initiates the pins to be used
pinMode(LED_BUILTIN, OUTPUT); //LED pin on ESP8266 Sparkfun dev board
pinMode(PIN, OUTPUT);
strip.begin();
strip.show();
}
void loop() {
server.handleClient();
if(blinkDelay > 0){
blinkLed();
blinkLed2();
}
if (minutes > 0){
strip.show();
timer(minutes);
}
}
void blinkLed(){
digitalWrite(LED_BUILTIN, HIGH); // LED on
delay(blinkDelay);
digitalWrite(LED_BUILTIN, LOW); // LED off
delay(blinkDelay);
}
void blinkLed2(){
digitalWrite(PIN, HIGH); // LED on
delay(blinkDelay);
digitalWrite(PIN, LOW); // LED off
delay(blinkDelay);
}
void BlinkDigitalLed(int minutes,int x,int y,int z) {
for (int blink = 0; blink < minutes; blink++) {
strip.setPixelColor(p1,x,y,z);
strip.show();
strip.setPixelColor(p2,x,y,z);
strip.show();
strip.setPixelColor(p3,x,y,z);
strip.show();
delay(flash);//on
strip.setPixelColor(p1,0,0,0);
strip.show();
strip.setPixelColor(p2,0,0,0);
strip.show();
strip.setPixelColor(p3,0,0,0);
strip.show();
delay(flash); // off
}
}
/*
void turnOnLed(){
digitalWrite(LED_BUILTIN,HIGH);
}
void turnOffLed(){
digitalWrite(LED_BUILTIN,LOW);
}
*/
void timer(int minutes){
//call the timer function and place the minutes into it
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(bright);
BlinkLed(minutes,bright,bright,bright);//michaels function to blink the light
pres(bright,bright,bright);
fadewhite(bright);
BlinkLed(minutes,0,bright,0); //greeen blinks
mincount(0,bright,0); // green on for a minute
fadegreen(bright);
BlinkLed(minutes,bright,bright,bright/10); // yellow starts to blink
mincount(bright,bright,bright/10); //yello on for a minute
fadeyellow(bright);
BlinkLed(minutes,bright,0,0); // red starts to blink
mincount(bright,0,0); //red on for a minute
fadered(bright);
}
void BlinkLed(int minutes,int x,int y,int z) {
for (int blink = 0; blink < minutes; blink++) {
strip.setPixelColor(p1,x,y,z);
strip.show();
strip.setPixelColor(p2,x,y,z);
strip.show();
strip.setPixelColor(p3,x,y,z);
strip.show();
delay(flash);//on
strip.setPixelColor(p1,0,0,0);
strip.show();
strip.setPixelColor(p2,0,0,0);
strip.show();
strip.setPixelColor(p3,0,0,0);
strip.show();
delay(flash); // off
}
}
void fadewhite(int d){
for (int i = d; i > 0; i--)
{
strip.setPixelColor(p1, i, i, i );
strip.show();
strip.setPixelColor(p2, i, i, i );
strip.show();
strip.setPixelColor(p3, i, i,i );
strip.show();
delay(10);
}
}
void fadegreen(int d){
for (int i = d; i > 0; i--)
{
strip.setPixelColor(p1, 0, i, 0 );
strip.show();
strip.setPixelColor(p2, 0, i, 0 );
strip.show();
strip.setPixelColor(p3, 0, i, 0 );
strip.show();
delay(10);
}
}
void fadeyellow(int d){
for (int i = d; i > 0; i--)
{
strip.setPixelColor(p1, i, i, i/10 );
strip.show();
strip.setPixelColor(p2, i, i, i/10 );
strip.show();
strip.setPixelColor(p3, i, i, i/10 );
strip.show();
delay(10);
}
}
void fadered(int d){
for (int i = d; i > 0; i--)
{
strip.setPixelColor(p1, i, 0, 0 );
strip.show();
strip.setPixelColor(p2, i, 0, 0 );
strip.show();
strip.setPixelColor(p3, i, 0, 0 );
strip.show();
delay(10);
}
}
void pres(int a, int b, int c){
strip.setPixelColor(p1,a,b,c);//red
strip.show();
strip.setPixelColor(p2,a,b,c);//white
strip.show();
strip.setPixelColor(p3,a,b,c);//blue
strip.show();
delay(minutes * 60000);
//turn off after the timer limit to green (n minutes)
strip.setPixelColor(p1,0,0,0);
strip.show();
strip.setPixelColor(p2,0,0,0);
strip.show();
strip.setPixelColor(p3,0,0,0);
strip.show();
}
void mincount(int e, int f, int g){
strip.setPixelColor(p1,e,f,g);//red
strip.show();
strip.setPixelColor(p2,e,f,g);//white
strip.show();
strip.setPixelColor(p3,e,f,g);//blue
strip.show();
delay(60000);//modify 1 to 60 for a minute
//turn off after the timer limit to green (n minutes)
strip.setPixelColor(p1,0,0,0);
strip.show();
strip.setPixelColor(p2,0,0,0);
strip.show();
strip.setPixelColor(p3,0,0,0);
strip.show();
}
Code: Select all
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function getFive(){
var xhttp1 = new XMLHttpRequest();
xhttp1.open("GET", "5", true);
xhttp1.send();}
function getOne(){
var xhttp2 = new XMLHttpRequest();
xhttp2.open("GET", "1", true);
xhttp2.send()}
function getFour(){
var xhttp3 = new XMLHttpRequest();
xhttp3.open("GET", "4", true);
xhttp3.send()}
function getSix(){
var xhttp4 = new XMLHttpRequest();
xhttp4.open("GET", "6", true);
xhttp4.send()}
</script>
<style>
.a{font-family: Helvetica; background-color:#555555; text-decoration:none; border:none; color:black; padding:10px100px; text-align:center; display:inline-block; font-size:50px; margin:4px2px; cursor:pointer; border-radius:16px; box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);}
.button1 {background-color:#008CBA;}
.button2 {background-color:#4CAF50;}
.button3 {background-color:#008CBA;}
.button4 {background-color:#e7e7e7;}
h1{font-family: Helvetica; font-size:25px;}
h2{font-family: Helvetica; font-size:80px;}
</style>
</head>
<body>
<h1>Choose The Timer Function!!!</h1>
<button class="a button1" onclick="getFive()"> 5 minute timer </button><br><br>
<button class="a button2" onclick="getOne()"> 1 minute timer </button><br><br>
<button class="a button3" onclick="getFour()"> 4 minute timer</button><br><br>
<button class="a button5" onclick="getSix()"> 6 minute timer</button><br><br>
</body>
</html>
- scotch1
- Posts: 246
- Joined: Mon Nov 26, 2012 12:13 am
Re: Neopixel strip on turns off other LEDs
The Serial Port shows new values of "minutes" and "blinkDelay" as the html buttons are pushed.
As in: Part of code:
The problem seems to be related to the start and stop of the Neopixel Strip since the LEDS will blink with new values of blinkDelay from the html buttons.
Thinking that is must be due to how the neopixel function is called. Can it be located and called in the same if statment above in loop? Maybe code like that for button cycler is needed to check the new value of pushed HTML button (I.e. minutes= new value) if new, causes some sort of termination of the neopixel function, turn off, then restart a new fucntion with the new minutes value?
Seems so simple, but not. :(
As in: Part of code:
Code: Select all
bool handleFileRead(String path){
Serial.println("handleFileRead: " + path);
//**************************** XML buttons
if(path == "/5"){ // was 1000
Serial.println("blink delay is 1000");
blinkDelay = 1000;
minutes = 5;
Serial.print("minutes is: ");
Serial.println(minutes);
Code: Select all
void loop() {
server.handleClient();
if(blinkDelay > 0){
blinkLed();
blinkLed2();
}
}
Thinking that is must be due to how the neopixel function is called. Can it be located and called in the same if statment above in loop? Maybe code like that for button cycler is needed to check the new value of pushed HTML button (I.e. minutes= new value) if new, causes some sort of termination of the neopixel function, turn off, then restart a new fucntion with the new minutes value?
Seems so simple, but not. :(
Please be positive and constructive with your questions and comments.