From 02aea42207469c430f94b924cbf6de2f4d2d94a6 Mon Sep 17 00:00:00 2001 From: Thomas Schmid Date: Sun, 26 Jun 2022 00:23:50 +0200 Subject: [PATCH] add acceleration sensor Signed-off-by: Thomas Schmid --- firmware/include/zauberstab.h | 11 +++++++++-- firmware/platformio.ini | 4 +++- firmware/src/zauberstab.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/firmware/include/zauberstab.h b/firmware/include/zauberstab.h index 57a875b..ae449e2 100644 --- a/firmware/include/zauberstab.h +++ b/firmware/include/zauberstab.h @@ -2,12 +2,19 @@ #include "Arduino.h" #include +#include +#include + +#define ADXL345_I2CADDR 0x53 // 0x1D if SDO = HIGH #define LED_PIN 12 -#define NUM_LEDS 144 +#define NUM_LEDS 48 #define MIC_PIN 15 extern CRGB leds[NUM_LEDS]; +extern ADXL345_WE myAcc; int zauberstab_init(); -float get_sample(); \ No newline at end of file +float get_sample(); +void switch_app(); +bool acc_has_event(); \ No newline at end of file diff --git a/firmware/platformio.ini b/firmware/platformio.ini index 22305b5..ad2ded7 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -10,7 +10,9 @@ [env] framework = arduino -lib_deps = fastled/FastLED @ ^3.5.0 +lib_deps = + fastled/FastLED @ ^3.5.0 + wollewald/ADXL345_WE @ ^2.1.4 [env:esp32doit-devkit-v1] platform = espressif32 diff --git a/firmware/src/zauberstab.cpp b/firmware/src/zauberstab.cpp index 51a3489..c65e1bb 100644 --- a/firmware/src/zauberstab.cpp +++ b/firmware/src/zauberstab.cpp @@ -4,16 +4,42 @@ DcCancelation dc_blocker{0.95}; CRGB leds[NUM_LEDS]; static int16_t mic_offset = 0; +static bool acc_event = false; +ADXL345_WE myAcc = ADXL345_WE(ADXL345_I2CADDR); static uint16_t read_mic() { return analogRead(MIC_PIN); } +void double_tab_int() { + acc_event = true; +} + +bool acc_has_event() { + return acc_event; +} + int zauberstab_init() { FastLED.addLeds(leds, NUM_LEDS); + FastLED.addLeds(leds, NUM_LEDS); + FastLED.addLeds(leds, NUM_LEDS); // FastLED.setMaxPowerInVoltsAndMilliamps(5, 300); + + Wire.begin(); + if (!myAcc.init()){ + Serial.println("Ooops, no ADXL345 detected ... Check your wiring!"); + return -1; + } + + myAcc.setDataRate(ADXL345_DATA_RATE_200); + myAcc.setRange(ADXL345_RANGE_8G); + myAcc.setGeneralTapParameters(ADXL345_XY0, 3.0, 30, 100.0); + myAcc.setAdditionalDoubleTapParameters(false, 250); + myAcc.setInterrupt(ADXL345_DOUBLE_TAP, INT_PIN_1); + attachInterrupt(digitalPinToInterrupt(4), double_tab_int, RISING); + return 0; }