Bo poległem na podlinkowaniu pliku....
Code: Select all
/**
* Supla.org NodeMCU WiFi minimal example
* Author: Programistyk - Kamil Kaminski <[email protected]>
*
* This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
*/
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>
#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
#include <Adafruit_NeoPixel.h>
#define PIN D5
#define LICZBADIOD 50
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LICZBADIOD, PIN, NEO_RGB + NEO_KHZ400);
WiFiClient client;
const char* ssid = "siec";
const char* password = "haslo_do_sieci";
unsigned char _red = 0;
unsigned char _green = 255;
unsigned char _blue = 0;
unsigned char _color_brightness = 0;
unsigned char _brightness = 0;
int _rr = 0;
int _rg = 0;
int _rb = 0;
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int jj = 0;
void get_rgbw_value(int channelNumber, unsigned char *red_r, unsigned char *green_r, unsigned char *blue_r, unsigned char *color_brightness, unsigned char *brightness) {
*brightness = _brightness;
*color_brightness= _color_brightness;
*red_r = _red;
*green_r = _green;
*blue_r = _blue;
}
void set_rgbw() {
_rr = map(_color_brightness, 0, 100, 0, 7);
pixels.setBrightness(100);
}
void set_rgbw_value(int channelNumber, unsigned char red_r, unsigned char green_r, unsigned char blue_r, unsigned char color_brightness, unsigned char brightness) {
_brightness = brightness;
_color_brightness= color_brightness;
_red = red_r;
_green = green_r;
_blue = blue_r;
set_rgbw();
}
void setup() {
pixels.begin();
Serial.begin(115200);
delay(10);
set_rgbw();
SuplaDevice.setRGBWCallbacks(&get_rgbw_value, &set_rgbw_value);
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
// Ethernet MAC address
uint8_t mac[6] = {0x02, 0x03, 0x05, 0x07, 0x09, 0x09};
SuplaDevice.addRgbController();
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"svrx.supla.org", // SUPLA server address
000, // Location ID
"haslo_dostepu"); // Location Password
}
void loop() {
SuplaDevice.iterate();
switch (_rr) {
case 0:
for(int i=0; i<LICZBADIOD; i++)
{
pixels.setPixelColor(i, 0, 0, 0);
}
break;
case 1:
CylonBounce(0xff, 0, 0, 4, 10, 50);
break;
case 2:
SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
break;
case 3:
colorWipe(0x00,0xff,0x00, 50);
break;
case 4:
Sparkle(0xff, 0xff, 0xff, 0);
break;
case 5:
RunningLights(0xff,0xff,0xff, 50); // white
break;
case 6:
theaterChase(0xff,0,0,50);
break;
default:
for(int i=0; i<LICZBADIOD; i++)
{
pixels.setPixelColor(i, 0, 0, 0);
}
break;
}
pixels.show();
}
// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
_supla_int_t size = client.available();
if ( size > 0 ) {
if ( size > count ) size = count;
return client.read((uint8_t *)buf, size);
};
return -1;
};
int supla_arduino_tcp_write(void *buf, int count) {
return client.write((const uint8_t *)buf, count);
};
bool supla_arduino_svr_connect(const char *server, int port) {
return client.connect(server, 2015);
}
bool supla_arduino_svr_connected(void) {
return client.connected();
}
void supla_arduino_svr_disconnect(void) {
client.stop();
}
void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {
// Serial.println("WiFi init");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
}
//Serial.print("\nlocalIP: ");
//Serial.println(WiFi.localIP());
//Serial.print("subnetMask: ");
//Serial.println(WiFi.subnetMask());
//Serial.print("gatewayIP: ");
//Serial.println(WiFi.gatewayIP());
}
SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
SuplaDeviceCallbacks cb;
cb.tcp_read = &supla_arduino_tcp_read;
cb.tcp_write = &supla_arduino_tcp_write;
cb.eth_setup = &supla_arduino_eth_setup;
cb.svr_connected = &supla_arduino_svr_connected;
cb.svr_connect = &supla_arduino_svr_connect;
cb.svr_disconnect = &supla_arduino_svr_disconnect;
cb.get_temperature = NULL;
cb.get_temperature_and_humidity = NULL;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
return cb;
}
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
pixels.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
pixels.setPixelColor(Pixel, pixels.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < LICZBADIOD; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
//========================================= efekty z https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
for(int i = 0; i < LICZBADIOD-EyeSize-2; i++) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int jj = 1; jj <= EyeSize; jj++) {
setPixel(i+jj, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
for(int i = LICZBADIOD-EyeSize-2; i > 0; i--) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int jj = 1; jj <= EyeSize; jj++) {
setPixel(i+jj, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
//=========================================
void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
setAll(red,green,blue);
int Pixel = random(LICZBADIOD);
setPixel(Pixel,0xff,0xff,0xff);
showStrip();
delay(SparkleDelay);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
}
//=========================================
void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
for(uint16_t i=0; i<LICZBADIOD; i++) {
setPixel(i, red, green, blue);
showStrip();
delay(SpeedDelay);
}
}
//=========================================
void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
int Position=0;
for(int jj=0; jj<LICZBADIOD*2; jj++)
{
Position++; // = 0; //Position + Rate;
for(int i=0; i<LICZBADIOD; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
//float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}
showStrip();
delay(WaveDelay);
}
}
//=========================================
void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
for (int jj=0; jj<10; jj++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < LICZBADIOD; i=i+3) {
setPixel(i+q, red, green, blue); //turn every third pixel on
}
showStrip();
delay(SpeedDelay);
for (int i=0; i < LICZBADIOD; i=i+3) {
setPixel(i+q, 0,0,0); //turn every third pixel off
}
}
}
}
//=========================================
void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(LICZBADIOD);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
setPixel(Pixel,0,0,0);
}
//=========================================
1.
2.
3.
4. ładowarka telefoniczna USB
Schemat połączeń elektrycznych postaram się pokazać później, ale opisowo jest tak:
1. łańcuch LED zasilam z zasilacza LED: niebieski przewód podłączony do GND łańcucha, brązowy do + łańcucha
2. nodemcu zasilany jest z ładowarki telefonicznej
3. pin GND nodemcu połączony z przewodem niebieskim zasilacza LED
4. pin D5 nodemcu połączony ze złączem sygnałowym łańcucha.