WS2812b + Wemos D1

Masz pomysł na funkcjonalność lub koncepcję na rozwój projektu. Opisz wszystko tutaj.
Post Reply
LWww
Posts: 1
Joined: Sun Mar 17, 2019 4:49 pm

Sun Mar 17, 2019 5:10 pm

Hej.
W zwiazku, ze nie znalazlem nigdzie kodu do diod WS2812b by sterowac nimi przy uzyciu Wemos D1 i NodeMCU, przy pomocy kodu Komar000 i niewielu zmianach udalo mi sie zmusic to polaczenie do dzialania.
Kolejny etap to dodanie obslugi konfiguracji z poziomu AP Wemosa identycznie jak w przy innych modulach.
Moze ktos z was bylby zainteresowany i mial chwile wolnego by wprowadzic odpowiednie zmiany?
*przy konfiguracji pomocnym bylaby opcja podania ilosci diod

Pozdr

Kod wklejam bo nie moge dodac pliku.

Code: Select all


/**
* Supla.org NodeMCU WiFi minimal example
* Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>
* Edited by L.Wika
* 
* 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>
#include <FastLED.h>

#define PIN D5
#define LICZBADIOD 120 //zmienic na ilosc diod ktora posiadamy, nie wymagane jesli mamy mniej niz 120 diod

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LICZBADIOD, PIN, NEO_GRB + NEO_KHZ800);
WiFiClient client;

const char* ssid     = "nazwa_wifi"; //(edytowac!)
const char* password = "haslo_wifi"; //(edytowac!)

unsigned char _red = 0;
unsigned char _green = 0;
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(10);
}

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) {
   Serial.println("brightness");
   Serial.println(brightness);
    _brightness = brightness;
   Serial.println("color_brightness");
   Serial.println(color_brightness);
    _color_brightness= color_brightness;
   Serial.println("red");
   Serial.println(red_r);
    _red = red_r;
   Serial.println("green");
   Serial.println(green_r);
    _green = green_r;
   Serial.println("blue");
   Serial.println(blue_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] = {pobierz_nowy_guid_i_wpisz_tu}; //(edytowac!)
  // 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
                    "nazwa_serwera",  // SUPLA server address (edytowac!)
                    nazwa_lokaliacji,               // Location ID  (edytowac!)
                    "haslo");  // Location Password (edytowac!)
}

void loop() {
  SuplaDevice.iterate();

   delay(10);

    for(int i=0; i<LICZBADIOD; i++)
      {
      pixels.setBrightness(_color_brightness*2);
      pixels.setPixelColor(i, _red, _green, _blue);
      }
 
   
   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();
}

Post Reply