This commit is contained in:
Alexander Alber 2022-06-26 00:27:12 +02:00
commit 823a377235
4 changed files with 90 additions and 8 deletions

View File

@ -2,12 +2,19 @@
#include "Arduino.h"
#include <FastLED.h>
#include<Wire.h>
#include<ADXL345_WE.h>
#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();
void switch_app();
bool acc_has_event();

View File

@ -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

View File

@ -22,25 +22,72 @@ std::vector<std::reference_wrapper<App>> apps = {
std::ref<App>(fackel_app)
};
<<<<<<< HEAD
unsigned int current_app = 1;
unsigned int next_app;
=======
static unsigned int current_app = 0;
static unsigned int next_app;
static bool init_successfull = false;
static bool sleep_active=false;
void switch_app() {
if (!sleep_active) {
next_app = current_app + 1;
} else {
sleep_active = false;
next_app = 0;
}
if (next_app >= apps.size()) {
next_app = 0;
// Turn off leds before going to sleep
fadeToBlackBy(leds, NUM_LEDS, 0xFF);
FastLED.show();
//configure wakeup source
esp_sleep_enable_ext0_wakeup(GPIO_NUM_4, 1);
//bedtime
sleep_active = true;
esp_deep_sleep_start();
}
next_app = next_app % apps.size();
}
>>>>>>> update main app handling to include an off state
void setup()
{
next_app = current_app;
<<<<<<< HEAD
zauberstab_init();
//Serial.begin(115200);
=======
if (zauberstab_init() != 0) {
return;
}
Serial.begin(115200);
>>>>>>> update main app handling to include an off state
init_successfull = true;
apps[current_app].get().init();
}
void loop()
{
/* EVERY_N_SECONDS(30)
{
next_app++;
next_app = next_app % apps.size();
} */
if (!init_successfull) {
return;
}
if (acc_has_event()) {
String axes = myAcc.getActTapStatusAsString();
byte intSource = myAcc.readAndClearInterrupts();
if (myAcc.checkInterrupt(intSource, ADXL345_DOUBLE_TAP)) {
switch_app();
}
}
if (next_app != current_app)
{

View File

@ -4,16 +4,42 @@
DcCancelation<float> 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<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);
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;
}