From 49092901173ee37bb592ffc5e12ba61361b8d4c6 Mon Sep 17 00:00:00 2001 From: dragonchaser Date: Thu, 17 Jul 2025 14:07:24 +0200 Subject: [PATCH] final tuning of amulett Signed-off-by: dragonchaser --- btcontrol.ino | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/btcontrol.ino b/btcontrol.ino index 0f9b2bb..342a702 100644 --- a/btcontrol.ino +++ b/btcontrol.ino @@ -31,9 +31,9 @@ void Vibrate(); // LED configuration #define LED_TYPE WS2812B -#define LED_DATA_PIN 1 // use 1 for GPIO 1 and 21 for builtin +#define LED_DATA_PIN 21 // use 1 for GPIO 1 and 21 for builtin #define LED_NUM_LEDS 7 // use 1 for builtin and whatever your count is for extern -#define LED_COLOR_ORDER RGB // USE GRB for the onboard led and RGB for the chain +#define LED_COLOR_ORDER GRB // USE GRB for the onboard led and RGB for the chain #define LED_BRIGHTNESS 96 #define LED_BRIGHTNESS_DIMM 16 @@ -44,9 +44,8 @@ void Vibrate(); // VIBRATION MOTOR configuration #define VIBRO_PIN 2 -#define VIBRO_REPEAT 3 -#define VIBRO_SMALL_DELAY 100 -#define VIBRO_BIG_DELAY 500 +#define VIBRO_REPEAT 10 +#define VIBRO_DELAY 250 // DATA maintenance configuration #define UPDATE_INTERVAL 10000 // how often do we update de database? @@ -61,7 +60,7 @@ void Vibrate(); #define MIN_RSSI_POWER -50 // Use Serial interface for debugging true|false -#define USE_SERIAL false +#define USE_SERIAL true // CONSTS static const PROGMEM std::map overrideColors = { @@ -77,7 +76,7 @@ static const PROGMEM std::map blackList = { #define DEVICE_TYPE_PRIVATE_LAMP 3 #define DEVICE_TYPE_AMULETT 4 -#define DEVICE_TYPE DEVICE_TYPE_PUBLIC_LAMP +#define DEVICE_TYPE DEVICE_TYPE_AMULETT #ifndef DEVICE_TYPE // WE DO NOT HAVE A DEVICETYPE, so we do not have any variables here @@ -145,6 +144,8 @@ volatile uint8_t stepSegments; TimerEvent updateTimer; +uint8_t vibrationCount = 0; + class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice advertisedDevice) { if (advertisedDevice.getRSSI() > MIN_RSSI_POWER) { @@ -184,8 +185,8 @@ class AdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { // when the device is not in the database yet, vibrate on first connect if (useVibro) { auto it = deviceDatabase.find(color); - if (it != deviceDatabase.end()) { - Vibrate(); + if (it == deviceDatabase.end()) { + vibrationCount = VIBRO_REPEAT; } } @@ -267,6 +268,10 @@ void loop() { } FillLEDsFromPaletteColors((startindex++) % LED_PALETTE_SIZE); FastLED.show(); + if (useVibro && vibrationCount > 0) { + Vibrate(); + vibrationCount--; + } FastLED.delay(1000/LED_FRAMES_PER_SECOND); } @@ -327,13 +332,9 @@ void UpdatePalette() { // Causes the vibration motor to vibrate void Vibrate() { - for (int i = 0; i < VIBRO_REPEAT; i++) { - for (int j = 0; j < 3; j++) { - delay(VIBRO_SMALL_DELAY); - digitalWrite(VIBRO_PIN, HIGH); - delay(VIBRO_SMALL_DELAY); - digitalWrite(VIBRO_PIN, LOW); - } - delay(VIBRO_BIG_DELAY); + for (int j = 0; j < 3; j++) { + digitalWrite(VIBRO_PIN, HIGH); + delay(VIBRO_DELAY); + digitalWrite(VIBRO_PIN, LOW); } }