Hey every one ,
i am trying to program my ESP32 in the way i can send 1 bit input (a number) from Bluetooth Serial to play some effects on my NeoPixel strip but it seems that i am getting a wrong input and don't know what is exactly the problem .
maybe someone can help me
thanx in advance
P.S. : that is my try till now
#include "BluetoothSerial.h"
#include <Adafruit_NeoPixel.h>
BluetoothSerial BT;
#define PIXEL_PIN1 22
const int LEDpin = 23;
#define PIXEL_COUNT 420
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN1, NEO_GRB + NEO_KHZ800);
int showType = 0;
int a;
uint32_t c;
int b[8][3] = {(0, 0, 0), (255, 0, 0),(0, 255, 0), (0, 0, 255), (255, 255, 255), (209, 181, 255), (217, 160, 255), (140, 231, 120)};
void setup() {
Serial.begin(115200);
BT.begin("ESP32test"); //Bluetooth device name
strip.begin();
color(strip.Color(209, 181, 255));
delay(100);
}
void loop() {
// might be time consuming
if (BT.available())
{
a = (int)BT.read();
for (int i = 0 ; i < 3; i++)
Serial.println(b[a][i]);
color(strip.Color(b[a][0], b[a][1], b[a][2]));
if (a == 8)
{
rainbowCycle();
}
}
}
void color(uint32_t c) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.fill(c, i);
strip.show();
}
}
void rainbowCycle() {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}