updated hall code
This commit is contained in:
Binary file not shown.
32194
CAD/3D/PCB_floor2.STL
32194
CAD/3D/PCB_floor2.STL
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
189751
CAD/Leo_muziekdoos_ESP32/Leo_muziekdoos.step
Normal file
189751
CAD/Leo_muziekdoos_ESP32/Leo_muziekdoos.step
Normal file
File diff suppressed because it is too large
Load Diff
BIN
FW/leo_muziekdoos_esp32/hallsensor_output.xlsx
Normal file
BIN
FW/leo_muziekdoos_esp32/hallsensor_output.xlsx
Normal file
Binary file not shown.
@@ -12,7 +12,9 @@
|
||||
platform = espressif32
|
||||
board = m5stack-atom
|
||||
framework = arduino
|
||||
lib_deps = bblanchon/ArduinoJson@^6.18.5
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^6.18.5
|
||||
kosme/arduinoFFT@^1.5.6
|
||||
monitor_speed = 115200
|
||||
lib_ldf_mode = deep+
|
||||
extra_scripts = ./littlefsbuilder.py
|
||||
|
||||
@@ -5,7 +5,7 @@ AudioFileSourceID3 *id3;
|
||||
AudioFileSourceLittleFS *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
uint8_t i = 0;
|
||||
uint8_t audio_current_Song = 0;
|
||||
uint8_t n = 0;
|
||||
|
||||
const char *waveFile[] =
|
||||
@@ -72,23 +72,28 @@ void initAudio()
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
|
||||
Serial.println("init Audio Done");
|
||||
playSong(i);
|
||||
//playSong(audio_current_Song);
|
||||
}
|
||||
|
||||
void handleAudio()
|
||||
{
|
||||
if (mp3->isRunning())
|
||||
if (hallIsIdle())
|
||||
{
|
||||
if (!mp3->loop())
|
||||
if (mp3->isRunning())
|
||||
{
|
||||
Serial.println("Audio: stop playback");
|
||||
mp3->stop();
|
||||
if(n++ >= AUDIOREPEATS)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mp3->isRunning())
|
||||
{
|
||||
if (!mp3->loop())
|
||||
{
|
||||
i++;
|
||||
n= 0;
|
||||
mp3->stop();
|
||||
playSong(audio_current_Song);
|
||||
}
|
||||
//playSong(i);
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
#define AUDIOGAIN 0.7
|
||||
#include "game.h"
|
||||
|
||||
#define AUDIOGAIN 0.25
|
||||
#define AUDIONSONGS 3
|
||||
#define AUDIOREPEATS 3
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#include "game.h"
|
||||
|
||||
#include "math.h"
|
||||
|
||||
uint64_t last_hall_read;
|
||||
|
||||
uint32_t last_hall_read;
|
||||
uint16_t last_hall_sample;
|
||||
uint8_t hall_idle_count;
|
||||
bool hall_is_Idle = true;
|
||||
|
||||
void initGame(void)
|
||||
{
|
||||
@@ -14,7 +19,42 @@ void handleGame(void)
|
||||
uint32_t timeNow = millis();
|
||||
if(timeNow - last_hall_read > HALLINTERVAL)
|
||||
{
|
||||
Serial.println(analogRead(HALL_INPUT));
|
||||
uint16_t hall_sample = analogRead(HALL_INPUT);
|
||||
uint16_t hall_delta = (last_hall_sample > hall_sample)? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||
if(hall_delta > HALLIDLETHRESHOLD)
|
||||
{
|
||||
if(hall_idle_count > HALLIDLESAMPLES)
|
||||
{
|
||||
hall_is_Idle = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hall_idle_count == 0)
|
||||
{
|
||||
hall_is_Idle = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
}
|
||||
Serial.printf("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
|
||||
hall_sample,
|
||||
hall_delta,
|
||||
hall_idle_count,
|
||||
(hall_is_Idle? "yes":"no"));
|
||||
last_hall_sample = hall_sample;
|
||||
last_hall_read = timeNow;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool hallIsIdle(void)
|
||||
{
|
||||
return hall_is_Idle;
|
||||
}
|
||||
@@ -3,7 +3,10 @@
|
||||
#include "Arduino.h"
|
||||
#include "board.h"
|
||||
|
||||
#define HALLINTERVAL 500
|
||||
#define HALLINTERVAL 200
|
||||
#define HALLIDLETHRESHOLD 11
|
||||
#define HALLIDLESAMPLES 4
|
||||
|
||||
void initGame(void);
|
||||
void handleGame(void);
|
||||
void handleGame(void);
|
||||
bool hallIsIdle(void);
|
||||
|
||||
@@ -3,9 +3,17 @@
|
||||
|
||||
bool powerbutton_released = true;
|
||||
|
||||
#define DR_REG_RTCCNTL_BASE 0x3ff48000
|
||||
#define RTC_CNTL_BROWN_OUT_REG (DR_REG_RTCCNTL_BASE + 0xd4)
|
||||
|
||||
|
||||
|
||||
void initPowerOn(void)
|
||||
{
|
||||
//disable brownout
|
||||
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
|
||||
|
||||
//enable LDO
|
||||
pinMode(PWR_HOLD, OUTPUT);
|
||||
pinMode(PWR_BTN, INPUT);
|
||||
digitalWrite(PWR_HOLD, HIGH);
|
||||
|
||||
Reference in New Issue
Block a user