I have made a simple sketch that sets the colour of a single neoPixel and allows the user to change it’s colour using the zeRGBa control in the Blynk app.
The hardware works and if I use different code with a terminal application I can change the colour of the neoPixel and interact with the project as expected.
The issue is when I add Blynk integration the project soes not behave as expected. Sometimes Blynk won’t connect, other times it will but wont change the colour and other times it will work really well.
If I send data from my project to the Blynk app the code on the Arduino will hang after connection.
It looks like the Blynk library could contain errors but i’m not sure. I have pasted my code below incase I have made any mistakes.
Many Thanks,
#define BLYNK_USE_DIRECT_CONNECT
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
#include <BlynkSimpleSerialBLE.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#include <EEPROM.h>
char auth[] = "YOURAUTH HERE"; //deleted for this forum post
int RED = 0;
int GREEN = 0;
int BLUE = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, 4, NEO_RGB + NEO_KHZ800);
boolean toLight = true;
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
BTSerial.begin(57600);
pixels.begin();
delay(100);
RED = int(EEPROM.read(0));
GREEN = int(EEPROM.read(1));
BLUE = int(EEPROM.read(2));
pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
pixels.show();
Blynk.begin(BTSerial, auth);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run(); //Listen for blynk commands
pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
pixels.show();
}
BLYNK_WRITE(V0) // zeRGBa assigned to V0
{
// get a RED channel value
RED = param[0].asInt();
// get a GREEN channel value
GREEN = param[1].asInt();
// get a BLUE channel value
BLUE = param[2].asInt();
EEPROM.write(0, RED);
EEPROM.write(1, GREEN);
EEPROM.write(2, BLUE);
pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
pixels.show();
}