Endless loop

Hi, I am making an RGB strip that is controllable over wifi and that will go on when it is dark and go off when it is light. So I am trying to make an endless loop so that the Arduino will “scan” if it is light or dark and then automatically go on/off depending on the readings of the light resistor. Currently, I have it working that the light resistor will “scan” the light conditions and then make the RGB lights burn of not but this all has to be done manually and I want to make it automatically. So can someone please explain to me how I to do this.

This is the function I am talking about

void warm(uint8_t wait) {

  int sensorValue = analogRead(sensorPin);


  if (sensorValue < lowThreshold){
    
    for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(255,147,28)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware
    delay(delayval); // Delay for a period of time (in milliseconds).
    delay(100);}}
  else  
    for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).
    delay(100);
  
  }
}

This is the full code

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Adafruit_NeoPixel.h>
#define PIN D4
#define NUMPIXELS      7
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(15, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
int sensorPin = 0;

int lightState = 0;
int lowThreshold = 200;
int highTreshold = 250;
const char* ssid = "SECRET";
const char* password = "SECRET";

ESP8266WebServer server(80);
const int led = 13;

void handleRoot() {
  server.send(200, "text/plain", "usage:\n/warm");

}

void handleNotFound(){
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}
void warm(uint8_t wait) {

  int sensorValue = analogRead(sensorPin);


  if (sensorValue < lowThreshold){
    
    for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(255,147,28)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware
    delay(delayval); // Delay for a period of time (in milliseconds).
    delay(100);}}
  else  
    for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).
    delay(100);
  
  }
}


uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void setup(void){
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/warm", [](){
    server.send(200, "text/plain", "warm");
    warm(20); 
  });

 
  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
  
    strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

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

I am trying to make an endless loop so that the Arduino will "scan" if it is light or dark and then automatically go on/off depending on the readings of the light resistor

You mean something like the loop() function ?

Try to put a call to "void warm(..)" in "void loop()". And try to avoid cut'n paste "programming" ;)

What part does the ESP8266 play in the operation of this project ?

I am using a wemos d1 mini basically an Arduino with an esp8266 built in. The esp8266 creates a local server and I can access that by an IP address that is printed in the serial monitor. So if I connect to the local server then I can type /warm and then the RGB strip will go on if there is not enough light.

If I replace the void warm to void loop than "warm" is not declared in code before that.

Making a call to a method does not mean to copy the method into another method :-/

Kawouterplop: I am using a wemos d1 mini basically an Arduino with an esp8266 built in. The esp8266 creates a local server and I can access that by an IP address that is printed in the serial monitor. So if I connect to the local server then I can type /warm and then the RGB strip will go on if there is not enough light.

OK, I get that. What do you want it to do instead ?

UKHeliBob: OK, I get that. What do you want it to do instead ?

He wants to put a call to "warm" inside "loop", but apparently he does not know (how to do) it ;)

Kawouterplop: I am using a wemos d1 mini basically an Arduino with an esp8266 built in. The esp8266 creates a local server and I can access that by an IP address that is printed in the serial monitor. So if I connect to the local server then I can type /warm and then the RGB strip will go on if there is not enough light.

Kawouterplop: I am using a wemos d1 mini basically an Arduino with an esp8266 built in. The esp8266 creates a local server and I can access that by an IP address that is printed in the serial monitor. So if I connect to the local server then I can type /warm and then the RGB strip will go on if there is not enough light.

Do you want to remove the web server functionality and just have the strip work when the light level is above (or below) a specified level ? What do you want to happen when it is light and when it is dark ?