Wemos D1 with Mosfet support
To get my couch led runnung a wemos d1 udp client with support for pwm is created. also made changes to the ws2812b version
This commit is contained in:
parent
48e955df17
commit
a768cbb781
13
clients/strip-wemosd1-udp-mosfet-pwm-2/settings.example.h
Normal file
13
clients/strip-wemosd1-udp-mosfet-pwm-2/settings.example.h
Normal file
@ -0,0 +1,13 @@
|
||||
const char* ssid = "master";
|
||||
const char* password = "master";
|
||||
|
||||
//RecipientIP is overridden after wl connect, getting localip and set last octet to 255 (Broadcast)
|
||||
//this will only work for /24 networks. If you want to set an other BC or a sinle IP adress set overriderecipient to true
|
||||
overriderecipient = false;
|
||||
RecipientIP = IPAddress(0, 0, 0, 0);
|
||||
RecipientPort = 8002;
|
||||
|
||||
RGBStrip rgbStrips[] = {
|
||||
RGBStrip("Couch links", 20, 21, 22),
|
||||
RGBStrip("Couch rechts", 19, 18, 17),
|
||||
};
|
@ -0,0 +1,123 @@
|
||||
|
||||
//#define FASTLED_ALLOW_INTERRUPTS 0
|
||||
//#define FASTLED_INTERRUPT_RETRY_COUNT 0
|
||||
//#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266_ASYNC
|
||||
#define UDP_TX_PACKET_MAX_SIZE = 50*12+1;
|
||||
|
||||
#include <FastLED.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
class RGBStrip {
|
||||
private:
|
||||
// buffers for receiving and sending data
|
||||
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
|
||||
WiFiUDP _udp;
|
||||
String _name;
|
||||
int _pin_red;
|
||||
int _pin_green;
|
||||
int _pin_blue;
|
||||
int _col_red = 0;
|
||||
int _col_green = 0;
|
||||
int _col_blue = 0;
|
||||
int _getledvalue(int startpoint){
|
||||
return 100 * int(packetBuffer[startpoint] - '0') + 10 * int(packetBuffer[startpoint+1] - '0') + int(packetBuffer[startpoint+2] - '0');
|
||||
}
|
||||
public:
|
||||
IPAddress _RecipientIP = IPAddress(0, 0, 0, 0);
|
||||
unsigned int _RecipientPort = 8002;
|
||||
RGBStrip(String name, int pin_red, int pin_green, int pin_blue){
|
||||
_name = name;
|
||||
_pin_red = pin_red;
|
||||
_pin_green = pin_green;
|
||||
_pin_blue = pin_blue;
|
||||
|
||||
pinMode(_pin_red, OUTPUT);
|
||||
pinMode(_pin_green, OUTPUT);
|
||||
pinMode(_pin_blue, OUTPUT);
|
||||
analogWrite(_pin_red,_col_red);
|
||||
analogWrite(_pin_green,_col_green);
|
||||
analogWrite(_pin_blue,_col_blue);
|
||||
_udp.begin(random(5000,5499));
|
||||
}
|
||||
void sendUDP(String text){
|
||||
//Serial.println(text);
|
||||
_udp.beginPacket(_RecipientIP, _RecipientPort);
|
||||
_udp.print(text);
|
||||
_udp.endPacket();
|
||||
}
|
||||
void loop(){
|
||||
int packetSize = _udp.parsePacket();
|
||||
if(packetSize)
|
||||
{
|
||||
// read the packet into packetBufffer
|
||||
_udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
|
||||
if(packetBuffer[0] == 's' && packetBuffer[1] == 'r'){
|
||||
sendUDP("r:1:"+_name+":"+String(1)+":0");
|
||||
}
|
||||
if(packetBuffer[0] == 's' && packetBuffer[1] == 'u'){
|
||||
analogWrite(_pin_red, _col_red);
|
||||
analogWrite(_pin_green, _col_green);
|
||||
analogWrite(_pin_blue, _col_blue);
|
||||
//Serial.println("SU:"+_name+" "+String(_pin_red)+":"+String(_col_red)+" "+String(_pin_blue)+":"+String(_col_green)+" "+String(_pin_blue)+":"+String(_col_blue));
|
||||
}
|
||||
// d001255255255
|
||||
// d LED RED GRE BLU
|
||||
if(packetBuffer[0] == 'd'){
|
||||
_col_red = _getledvalue(4);
|
||||
_col_green = _getledvalue(7);
|
||||
_col_blue = _getledvalue(10);
|
||||
// Serial.println("D:"+_name+":"+String(_col_red)+":"+String(_col_green)+":"+String(_col_blue));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#include "settings.h"
|
||||
|
||||
WiFiClient client;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
analogWriteRange(255);
|
||||
analogWriteFreq(50);
|
||||
//Serial.begin(115200);
|
||||
wdt_enable(WDTO_4S); // Watchdog auf 4 s stellen
|
||||
WiFi.softAPdisconnect (true);
|
||||
for (int i = 0; i < (sizeof(rgbStrips) / sizeof(rgbStrips[0])); i++) {
|
||||
rgbStrips[i]._RecipientPort = RecipientPort;
|
||||
rgbStrips[i]._RecipientIP = RecipientIP;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
EVERY_N_MILLISECONDS( 250 ) {
|
||||
for (int i = 0; i < (sizeof(rgbStrips) / sizeof(rgbStrips[0])); i++) {
|
||||
rgbStrips[i].sendUDP(String("s:ping"));
|
||||
}
|
||||
}
|
||||
EVERY_N_MILLISECONDS( 15 ) {
|
||||
for (int i = 0; i < (sizeof(rgbStrips) / sizeof(rgbStrips[0])); i++) {
|
||||
rgbStrips[i].loop();
|
||||
}
|
||||
wdt_reset();
|
||||
if (WiFi.status() != WL_CONNECTED) { // FIX FOR USING 2.3.0 CORE (only .begin if not connected)
|
||||
WiFi.begin(ssid, password); // connect to the network
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
}
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
// Start UDP
|
||||
//Serial.println("start udp");
|
||||
if(!overriderecipient){
|
||||
RecipientIP = WiFi.localIP();
|
||||
RecipientIP[3] = 255;
|
||||
for (int i = 0; i < (sizeof(rgbStrips) / sizeof(rgbStrips[0])); i++) {
|
||||
rgbStrips[i]._RecipientIP = RecipientIP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -61,8 +61,11 @@ void loop() {
|
||||
int packetSize = Udp.parsePacket();
|
||||
if(packetSize)
|
||||
{
|
||||
for( int i = 0; i < sizeof(packetBuffer); ++i )
|
||||
packetBuffer[i] = (char)0;
|
||||
// read the packet into packetBufffer
|
||||
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
|
||||
Serial.println(packetBuffer);
|
||||
if(packetBuffer[0] == 's' && packetBuffer[1] == 'r'){
|
||||
sendUDP("r:1:"+StripName+":"+String(NUM_LEDS)+":0");
|
||||
}
|
||||
@ -86,7 +89,7 @@ int getledvalue(int startpoint){
|
||||
// Function to send UDP packets
|
||||
void sendUDP(String text)
|
||||
{
|
||||
//Serial.println(text);
|
||||
Serial.println(text);
|
||||
Udp.beginPacket(RecipientIP, RecipientPort);
|
||||
Udp.print(text);
|
||||
Udp.endPacket();
|
||||
|
Loading…
x
Reference in New Issue
Block a user