add acceleration sensor

Signed-off-by: Thomas Schmid <tom@binary-kitchen.de>
This commit is contained in:
Thomas 2022-06-26 00:23:50 +02:00
parent 73a43f00cd
commit 02aea42207
3 changed files with 38 additions and 3 deletions

View File

@ -2,12 +2,19 @@
#include "Arduino.h" #include "Arduino.h"
#include <FastLED.h> #include <FastLED.h>
#include<Wire.h>
#include<ADXL345_WE.h>
#define ADXL345_I2CADDR 0x53 // 0x1D if SDO = HIGH
#define LED_PIN 12 #define LED_PIN 12
#define NUM_LEDS 144 #define NUM_LEDS 48
#define MIC_PIN 15 #define MIC_PIN 15
extern CRGB leds[NUM_LEDS]; extern CRGB leds[NUM_LEDS];
extern ADXL345_WE myAcc;
int zauberstab_init(); int zauberstab_init();
float get_sample(); float get_sample();
void switch_app();
bool acc_has_event();

View File

@ -10,7 +10,9 @@
[env] [env]
framework = arduino 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] [env:esp32doit-devkit-v1]
platform = espressif32 platform = espressif32

View File

@ -4,16 +4,42 @@
DcCancelation<float> dc_blocker{0.95}; DcCancelation<float> dc_blocker{0.95};
CRGB leds[NUM_LEDS]; CRGB leds[NUM_LEDS];
static int16_t mic_offset = 0; static int16_t mic_offset = 0;
static bool acc_event = false;
ADXL345_WE myAcc = ADXL345_WE(ADXL345_I2CADDR);
static uint16_t read_mic() static uint16_t read_mic()
{ {
return analogRead(MIC_PIN); return analogRead(MIC_PIN);
} }
void double_tab_int() {
acc_event = true;
}
bool acc_has_event() {
return acc_event;
}
int zauberstab_init() int zauberstab_init()
{ {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, 14, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, 27, GRB>(leds, NUM_LEDS);
// FastLED.setMaxPowerInVoltsAndMilliamps(5, 300); // 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; return 0;
} }