Hello!
I have a neopixel led strip and my goal is to make it bluetooth connected but this led to a problem where the effects (specifically the built-in "rainbow effect") makes it change after the rainbow effect is done(multiple seconds), not when it recieves the bluetooth input.
I've managed to make it able to change between static colors but whats the meaning of using the neopixel if i cant have dank effects right? so my question is if i can use either the input of the bluetooth module to somehow interrupt everything and in that case how or should i rewrite the rainbow function? my guess is it some sort of delay is making it queue the input and after that switch the effect.
im at the point now where i tried to remove the checking of the bluetooth input in the "void loop" and instead made it into a void BLINPUT as i didnt know if two of the same functions would disturb one another. in short, it doesnt work now
Also, i removed the delay on the original rainbow effect and replaced it with a code i found on the forum for testing purposes to try and see if it worked, the "delay" worked but the problem with the interrupt still persists
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3);
#define pixelpin 6
#define ledcount 4
#define brightness 100
Adafruit_NeoPixel strip(ledcount, pixelpin, NEO_GRB + NEO_KHZ800);
char value;
void BLINPUT() {
if(BT.available()) {
value = BT.read();
BT.print(value);
}
}
void setup() {
attachInterrupt(digitalPinToInterrupt(3), BLINPUT, CHANGE);
BT.begin(9600);
BT.print("Ready");
strip.setBrightness(brightness);
strip.begin();
strip.show();
}
void loop() {
// put your main code here, to run repeatedly:
//if(BT.available()) {
//value = BT.read();
//BT.print(value);
if (value=='a') {
for(int i = 0; i<strip.numPixels(); i++){
strip.setPixelColor(i, 255, 0, 0);
}
strip.show();
}
if (value=='b'){
for(int i = 0; i<strip.numPixels(); i++){
strip.setPixelColor(i, 0, 255, 0);
}
strip.show();
}
if (value=='c') {
for(int i = 0; i<strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 255);
}
strip.show();
}
if (value=='d') {
rainbow(50);
}
}
void altdelay(int del) {
unsigned long myPrevMillis = millis();
while (millis()- myPrevMillis <= del);
}
void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
// Offset pixel hue by an amount to make one full revolution of the
// color wheel (range of 65536) along the length of the strip
// (strip.numPixels() steps):
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
// optionally add saturation and value (brightness) (each 0 to 255).
// Here we're using just the single-argument hue variant. The result
// is passed through strip.gamma32() to provide 'truer' colors
// before assigning to each pixel:
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
altdelay(50); // Pause for a moment
}
}
Im doing all this with an Arduino Uno, HC-06 module and a led strip of 4 neopixel if its important!
Thanks!