I send OSC message with an LFO. (I send a float from 0.0 to 1.0)
I can see in the monitor of IDE Arduino, that message is not perfectly received
So the light of build in is not synchronized too.
I use my USB port as power supply. My esp32 is the Heltec Wifi 32 V3
I'm quite sure that I managed once to have a regular flashing...
Thank for trying to give me a direction
Here my code with fastLed library
/*---------------------------------------------------------------------------------------------
Open Sound Control (OSC) library for the ESP8266/ESP32
Example for receiving open sound control (OSC) messages on the ESP8266/ESP32
Send integers '0' or '1' to the address "/led" to turn on/off the built-in LED of the esp8266.
This example code is in the public domain.
--------------------------------------------------------------------------------------------- */
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>
//char ssid[] = "Iphone de ben"; // your network SSID (name)
//char pass[] = "cacaprout"; // your network password
char ssid[] = "Bbox-E69F0626"; // your network SSID (name)
char pass[] = "NKg5Ad1m3mXFgx142p"; // your network password
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//const IPAddress outIp(10,40,10,105); // remote IP (not needed for receive)
const IPAddress outIp(192,168,1,77);
const unsigned int outPort = 9999; // remote port (not needed for receive)
const unsigned int localPort = 8000; // local port to listen for UDP packets (here's where we send the packets)
OSCErrorCode error;
unsigned int ledState = LOW; // LOW means led is *on*
#ifndef BUILTIN_LED
#ifdef LED_BUILTIN
#define BUILTIN_LED LED_BUILTIN
#else
#define BUILTIN_LED 13
#endif
#endif
// control LED with FastLed
#include <FastLED.h>
#define NUM_LEDS 8
#define LED_PIN 1
CRGB leds[NUM_LEDS];
float count;
//---------------------
void setup() {
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, ledState); // turn *on* led
Serial.begin(115200);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
#ifdef ESP32
Serial.print("LocalportESP32: ");
Serial.println(localPort);
#else
Serial.println(Udp.localPort());
#endif
// control LED with FastLed
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 300); // 500 is max?
FastLED.setBrightness(10); //255 is max
count = 0.0;
//--------------------- TURN OFF LIGHT
for (int i = 0; i <= NUM_LEDS; i++) {
// leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
leds[i] = CRGB ( 0,0,0);
delay(10);
FastLED.show();
delay(10);
}
}
void led(OSCMessage &msg) {
ledState = msg.getFloat(0);
digitalWrite(BUILTIN_LED, ledState);
if (ledState==true) {
count+=1.0;
// Serial.print("/led: ");
// Serial.println(ledState);
// Serial.print(" chek 240 data/min : " );
Serial.println(count);
for (int i = 0; i <= 7; i++)
{
leds[i] = CRGB ( 2*i,255-(2*i), 255-(2*i));
leds[moduloD] = CRGB ( (moduloC+1)*(2),255/((moduloD+1)*(i+1)), 127);
FastLED.show();
}
}
}
void loop() {
OSCMessage msg;
int size = Udp.parsePacket();
if (size > 0) {
while (size--) {
msg.fill(Udp.read());
}
if (!msg.hasError()) {
msg.dispatch("/led", led);
} else {
error = msg.getError();
Serial.print("error: ");
Serial.println(error);
}
}
}