Old Code pasted
This commit is contained in:
19
platformio.ini
Normal file
19
platformio.ini
Normal file
@@ -0,0 +1,19 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp01_1m]
|
||||
platform = espressif8266
|
||||
board = esp01_1m
|
||||
framework = arduino
|
||||
|
||||
|
||||
lib_deps =
|
||||
rstephan/ArtnetWifi @ ^1.6.1
|
||||
fastled/FastLED @ ^3.9.17
|
||||
158
src/main.cpp
Normal file
158
src/main.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
This example will receive multiple universes via Art-Net and control a strip of
|
||||
WS2812 LEDs via the FastLED library: https://github.com/FastLED/FastLED
|
||||
This example may be copied under the terms of the MIT license, see the LICENSE file for details
|
||||
*/
|
||||
#include <ArtnetWifi.h>
|
||||
#include <Arduino.h>
|
||||
#include <FastLED.h>
|
||||
|
||||
|
||||
|
||||
const int numLeds = 120; // CHANGE FOR YOUR SETUP
|
||||
// Wifi settings
|
||||
const char* ssid = "Fahnenlan";
|
||||
const char* password = "Fahnenschlaeger";
|
||||
IPAddress local_IP(192, 168, 1, 109);
|
||||
const int startUniverse = 9; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
|
||||
|
||||
|
||||
|
||||
IPAddress gateway(192,168,1,1);
|
||||
IPAddress subnet(255,255,255,0);
|
||||
|
||||
// LED settings
|
||||
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
|
||||
const byte dataPin = 3;
|
||||
CRGB leds[numLeds];
|
||||
|
||||
// Art-Net settings
|
||||
ArtnetWifi artnet;
|
||||
|
||||
// Check if we got all universes
|
||||
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
|
||||
bool universesReceived[maxUniverses];
|
||||
bool sendFrame = 1;
|
||||
|
||||
|
||||
// connect to wifi – returns true if successful or false if not
|
||||
bool ConnectWifi(void)
|
||||
{
|
||||
bool state = true;
|
||||
int i = 0;
|
||||
|
||||
WiFi.config(local_IP,gateway,subnet);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
|
||||
if (i > 20)
|
||||
{
|
||||
state = false;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void initTest()
|
||||
{
|
||||
for (int i = 0 ; i < numLeds ; i++)
|
||||
{
|
||||
leds[i] = CRGB(127, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
delay(500);
|
||||
for (int i = 0 ; i < numLeds ; i++)
|
||||
{
|
||||
leds[i] = CRGB(0, 127, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
delay(500);
|
||||
for (int i = 0 ; i < numLeds ; i++)
|
||||
{
|
||||
leds[i] = CRGB(0, 0, 127);
|
||||
}
|
||||
FastLED.show();
|
||||
delay(500);
|
||||
for (int i = 0 ; i < numLeds ; i++)
|
||||
{
|
||||
leds[i] = CRGB(0, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
|
||||
{
|
||||
sendFrame = 1;
|
||||
// set brightness of the whole strip
|
||||
if (universe == 15)
|
||||
{
|
||||
FastLED.setBrightness(data[0]);
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
// range check
|
||||
if (universe < startUniverse)
|
||||
{
|
||||
return;
|
||||
}
|
||||
uint8_t index = universe - startUniverse;
|
||||
if (index >= maxUniverses)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Store which universe has got in
|
||||
universesReceived[index] = true;
|
||||
|
||||
for (int i = 0 ; i < maxUniverses ; i++)
|
||||
{
|
||||
if (!universesReceived[i])
|
||||
{
|
||||
sendFrame = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// read universe and put into the right part of the display buffer
|
||||
for (int i = 0; i < length / 3; i++)
|
||||
{
|
||||
int led = i + (index * 170);
|
||||
if (led < numLeds)
|
||||
{
|
||||
leds[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sendFrame)
|
||||
{
|
||||
FastLED.show();
|
||||
// Reset universeReceived to 0
|
||||
memset(universesReceived, 0, maxUniverses);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
ConnectWifi();
|
||||
artnet.begin();
|
||||
FastLED.addLeds<WS2812, dataPin, GRB>(leds, numLeds);
|
||||
delay(500);
|
||||
initTest();
|
||||
|
||||
memset(universesReceived, 0, maxUniverses);
|
||||
// this will be called for each packet received
|
||||
artnet.setArtDmxCallback(onDmxFrame);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// we call the read function inside the loop
|
||||
artnet.read();
|
||||
}
|
||||
Reference in New Issue
Block a user