Hello Guys, i've got this new groove led strip driver wich as the name suggests drives an led strip (4pin 12v led strip). I tested it with my Arduino uno and the recomended code of the website and it works fine. Now I want to control my led strip wirelessly so i bought an esp32. When I tried the same code (I changed the pins obviously) with it, the led's don't work anymore and just blink in random colors at random intervalls. I think this has to do with the driver and the esp32 not beeing in sync with one another but I dont now. Thanks for any advice, you can find my code below
DemoLedStrip.ino
#include "RGBdriver.h"
#define CLK 18//pins definitions for the driver
#define DIO 19
RGBdriver Driver(CLK,DIO);
void setup()
{
}
void loop()
{
unsigned int i;
while(1){
for(i = 0;i < 256;i ++)
{
Driver.begin(); // begin
Driver.SetColor(i,i,i); //Green. First node data. SetColor(B,R,G)
Driver.end();
delay(10);
}
delay(10000);
for(i = 255;i > 0;i --)
{
Driver.begin(); // begin
Driver.SetColor(i,i,i); //Green. first node data
Driver.end();
delay(10);
}
}
}
RGBdriver.cpp
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// Modified Record:
/***************************************************************************/
#include "RGBdriver.h"
RGBdriver::RGBdriver(uint8_t Clk, uint8_t Data)
{
Clkpin = Clk;
Datapin = Data;
pinMode(Datapin, OUTPUT);
pinMode(Clkpin, OUTPUT);
}
void RGBdriver::begin(void)
{
Send32Zero();
}
void RGBdriver::end(void)
{
Send32Zero();
}
void RGBdriver::ClkRise(void)
{
digitalWrite(Clkpin, LOW);
delayMicroseconds(20);
digitalWrite(Clkpin, HIGH);
delayMicroseconds(20);
}
void RGBdriver::Send32Zero(void)
{
unsigned char i;
for (i=0; i<32; i++)
{
digitalWrite(Datapin, LOW);
ClkRise();
}
}
uint8_t RGBdriver::TakeAntiCode(uint8_t dat)
{
uint8_t tmp = 0;
if ((dat & 0x80) == 0)
{
tmp |= 0x02;
}
if ((dat & 0x40) == 0)
{
tmp |= 0x01;
}
return tmp;
}
// gray data
void RGBdriver::DatSend(uint32_t dx)
{
uint8_t i;
for (i=0; i<32; i++)
{
if ((dx & 0x80000000) != 0)
{
digitalWrite(Datapin, HIGH);
}
else
{
digitalWrite(Datapin, LOW);
}
dx <<= 1;
ClkRise();
}
}
// Set color
void RGBdriver::SetColor(uint8_t Red,uint8_t Green,uint8_t Blue)
{
uint32_t dx = 0;
dx |= (uint32_t)0x03 << 30; // highest two bits 1,flag bits
dx |= (uint32_t)TakeAntiCode(Blue) << 28;
dx |= (uint32_t)TakeAntiCode(Green) << 26;
dx |= (uint32_t)TakeAntiCode(Red) << 24;
dx |= (uint32_t)Blue << 16;
dx |= (uint32_t)Green << 8;
dx |= Red;
DatSend(dx);
}
RGBdriver.h
#ifndef RGB_DRIVER_H
#define RGB_DRIVER_H
//#include <inttypes.h>
#include <Arduino.h>
class RGBdriver
{
public:
RGBdriver(uint8_t, uint8_t);
void begin(void);
void end(void);
void ClkRise(void);
void Send32Zero(void);
uint8_t TakeAntiCode(uint8_t dat);
void DatSend(uint32_t dx);
void SetColor(uint8_t Red,uint8_t Green,uint8_t Blue);
private:
uint8_t Clkpin;
uint8_t Datapin;
};
#endif