First time posting so if i need to change anything please let me know, and kinda new to C++/coding.
I am using the ESP32 and I would like my FastLED effect to play with a BlueTooth command and keep playing until I send a new command with the new effect. I am able to connect to the bluetooth and switch cases no problem.
My problem is I cant figure out how to "repeat" the void command until a new button is pressed. I feel like I have danced around it for days now, and its time to ask for help from people smarter than myself. This is the original idea for the code, figured simple was better here. And thank you in advance for any help getting this working.
#include "BluetoothSerial.h"
#include <FastLED.h>
#define NUM_LEDs 50 //The number of LED using
#define LED_PIN 21 // LED pin,
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
int received;
char receivedChar;
int g_Brightness = 200;
const char turnON = 'a';
const char turnOFF = 'b';
CRGB leds[NUM_LEDs] = {0};
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32Banana"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
Serial.println("Turn ON send: a");
Serial.println("Turn OFF send: b");
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDs);
FastLED.setBrightness(g_Brightness);
}
void loop()
{
receivedChar = (char)SerialBT.read();
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
if (SerialBT.available())
{
SerialBT.print("Gottcha:");
SerialBT.println(receivedChar);
Serial.print("Gottcha:");
Serial.println(receivedChar);
switch (receivedChar)
{
case turnON:
NightRider();
break;
case turnOFF:
Off();
break;
}
}
delay(20);
}
void Off ()
{
fadeToBlackBy(leds, NUM_LEDs, 3);
FastLED.show();
}
void NightRider()
{
uint8_t sinBeat = map(beat8(50, 0), 0, 255, 0, NUM_LEDs - 1);
leds[sinBeat] = CRGB::Red;
fadeToBlackBy(leds, NUM_LEDs, 10);
FastLED.show();
}
Thank you, I have been looking around for ideas and I noticed a common first comment was "read the rules" so I did a quick glance at them before posting.
Good idea but sadly still only calls the void command once. I played around with a toggle state but it got stuck and I couldn't get out.
I think this is what you mean, please correct me if I am wrong but this, change the last serial.btprintln to just serial.btprint? If so I gave that a test run and same problem.
If not what command should I send thru the phone other than "a". Or if you could send me a link of different syntax's that would be perfect.
if (SerialBT.available()) {
receivedChar = (char)SerialBT.read();
//Serial.write(SerialBT.read());
//echo back to monitor and phone
Serial.print("Gottcha:");
Serial.print(receivedChar);
SerialBT.print("Gottcha:");
SerialBT.print(receivedChar);
}
It was as simple as turning off one setting in the phone app.....Thank you so much. I would have never thought of that. tips hat in respect to the smartest person here