The program is a Lightchaser which is controlled via shift registers and interrupts. As you can see in my code, the interrupt and millis are used. I tryed it with a Nano and ESP controller. The code works well without the blynk commands. What is missing to bring the thing to work with blynk? Thanx!
#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
char auth[] = "YourAuthToken";
#include "ShiftRegisterPWM.h"
ShiftRegisterPWM sr(1, 16);
void setup()
{ //Serial.begin(9600);
Blynk.begin(auth);
pinMode(2, OUTPUT); // sr data pin
pinMode(3, OUTPUT); // sr clock pin
pinMode(4, OUTPUT); // sr latch pin
sr.interrupt(ShiftRegisterPWM::UpdateFrequency::VeryFast);
}
void loop()
{ Blynk.run();
for (uint8_t i = 0; i < 8; i++) {
uint8_t val = (uint8_t)(((float)sin(millis() / 150.0 + i / 8.0 * 2.0 * PI) + 1) * 128);
sr.set(i, val);
}}
i tryed something different …maybe you could help me with this.
To analyse my problem i left Blynk and tryed the following code.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
#include "ShiftRegisterPWM.h"
ShiftRegisterPWM sr(1, 16);
int c;
float brightness = 90;
float rate = 1000.0;
float sinus = 12.0;
void setup()
{Serial.begin(9600);
mySerial.begin(9600);
pinMode(2, OUTPUT); // sr data pin
pinMode(3, OUTPUT); // sr clock pin
pinMode(4, OUTPUT); // sr latch pin
sr.interrupt(ShiftRegisterPWM::UpdateFrequency::VerySlow);
stopp();
}
void loop()
{
c = mySerial.read();
if(c==49){ //delete this and the program works as it should! ...but without control
welle();
}
if (c == 48){
stopp();
} }
void welle(){
for (uint8_t i = 0; i < 8; i++) {
uint8_t val = (uint8_t)(((float)sin(millis() / rate - i / sinus * 2.0 * PI) + 1) * brightness);
sr.set(i, val);
Serial.println(millis());
} }
void stopp(){
for (uint8_t i = 0; i < 8; i++) {
uint8_t val = 0;
sr.set(i, val);
}}
With this code, the movement of the light wave is frozen. In the terminal I got 8 numbers for the millis () and the program stops.
if the command “if (c == 49)” is deleted, then the wave moves as it should (without Bluetooth control). The millis continue to run as well in the terminal.
Would be great if someone could help me out here. i think if i know the failure in this code maybe i could get it to work with blynk also.