I'm trying to execute programs on my arduino based on values received via bluetooth. Although I've experimented a lot, I'm unable to get the code to work.
I have build a simple android app with three buttons that sends either value "11", "21" or "31" to the arduino over bluetooth, which should trigger the code to operate a DIY wake-up-light (ESP32 + NeoPixels). Can anyone tell me what I'm doing wrong? Thanks in advance!
#include "BluetoothSerial.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
// init Class:
BluetoothSerial ESP_BT;
#define LED_PIN 5
#define LED_COUNT 7
Adafruit_NeoPixel matrix = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
matrix.begin();
matrix.show(); // Initialize all pixels to 'off'
Serial.begin(19200);
ESP_BT.begin("Wake_Up_Light"); //Name of Bluetooth interface
}
int led_pin_1 = 5;
int incoming;
void loop() {
// ------------ call wakeup program or gotosleep program ----------------
if (ESP_BT.available())
{
incoming = ESP_BT.read(); //Read what we receive
int rnumber = incoming;
switch (rnumber) {
case 1:
Serial.print("11"); //----- Activate wake-up light after 6 hours -----
6hours();
wakeup();
ledsoff();
break;
case 2:
Serial.print("21"); //----- Activate go-to-sleep mode -----
gotosleep();
break;
case 3:
Serial.print("31"); //----- Activate powernap mode -----
gotosleep();
wakeupdelay();
wakeup();
ledsoff();
break;
}
}
}
void wakeup() {
uint16_t i, j;
for (j = 1; j < 10; j++) {
for (i = 0; i <LED_COUNT; i++) {
matrix.setBrightness(255);
matrix.setPixelColor(i, 3, j, j);
}
matrix.show();
delay(18000); //-------- 180.000ms (3 minutes) / 10 steps = 18.000 ---------
}
}
void gotosleep() {
uint16_t i, j;
for (j = 10; j > 0; j--) {
for (i = 0; i <LED_COUNT; i++) {
matrix.setBrightness(255);
matrix.setPixelColor(i, 3, j, j);
}
matrix.show();
delay(16363); // ---- 180000ms (3 minutes) / 11 steps = 16363 --------
}
matrix.setBrightness(0);
delay(40000); // ---- 40 seconds delay
}
void wakeupdelay() {
delay(1200000);
}
void ledsoff() {
matrix.setBrightness(0);
}
void 6hours() {
delay(21600000)
}