Hello!
I built an artwork made of glass and want to illuminate this with several LEDs in the background. For this I got the pca9685 pwm module to drive enough leds with my esp8266. then I wrote a program out of the pca9685 -demofile and want to turn on the light with a switch.
This formula is used:
val = (((float) sin (millis () / y + i / x * 2.0 * PI) + 1) * z);
The formula controls the LEDs in a kind of wave. The 3 variables x, y and z change the wave in terms of illuminance, length and peaks ā¦
The problem I have is, that the pca9685-demo program actually works well without the inclusion of cayenne (of course without the ability to set the variables). Now, with the involvement of Cayenne, the program works, but always only ONE value is written out on all 16 pwm outputs, then the values stuck and after a short brake the next value is written on all 16 outputs (eg value1= 0, value2= 0, value3= 0, value4= 0, ā¦ value16= 0) instead of describing a wave (it should be like this ā value1:= 0, value2= 100, value3= 500, value4= 1000, ā¦ value8= 2000, value9= 1500, value10= 1000 ā¦ value16= 0)
I hope that I have described my problem so that people can understand what i mean and ask for any help to realize my project.
Thank you!
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
char ssid[] = "";
char wifiPassword[] = "";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define VIRTUAL_CHANNEL 1
#define VIRTUAL_CHANNELx 2
#define VIRTUAL_CHANNELy 3
#define VIRTUAL_CHANNELz 4
int switch1=0;
int x=8;
int y=900;
int z=2048;
void setup() {
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
Serial.println("16 channel PWM test!");
pwm.begin();
pwm.setPWMFreq(1600); // This is the maximum PWM frequency
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
// some i2c devices dont like this so much so if you're sharing the bus, watch
// out for this!
Wire.setClock(400000);
}
void loop() {
Cayenne.loop();
Serial.println(switch1);
if (switch1==1){
for (uint8_t i = 0; i < 16; i++) {
int val = (((float)sin(millis() / y + i / x * 2.0 * PI) + 1) * z);
val = map(val,0,500, 0, 300); //max min Wert festlegen
val = map(val,501,4096, 301, 4096);
pwm.setPWM(i, 0, val);
Serial.println(val);
Serial.println(x);
Serial.println(y);
Serial.println(z);
}
#ifdef ESP8266
yield(); // take a breather, required for ESP8266
#endif
}
else{Serial.println("Stop");
for (uint8_t i = 0; i < 16; i++) {
pwm.setPWM(i, 0, LOW);
}
}
}
CAYENNE_IN(VIRTUAL_CHANNEL)
{
switch1 = getValue.asInt();
}
CAYENNE_IN(VIRTUAL_CHANNELx)
{
x = getValue.asInt();
}
CAYENNE_IN(VIRTUAL_CHANNELy)
{
y = getValue.asInt();
}
CAYENNE_IN(VIRTUAL_CHANNELz)
{
z = getValue.asInt();
}