This commit is contained in:
Michal Courson
2025-08-28 21:35:21 -04:00
commit 82dde89d80
23 changed files with 6801 additions and 0 deletions

37
main/Detector.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "Detector.hpp"
#include "TimeSync.hpp"
#include "kartSender.hpp"
Detector detector;
#define PIN_BUTTON 0
#define NUM_SAMPLES 100
void Detector::Init() {
pinMode(PIN_BUTTON, INPUT_PULLUP);
}
void Detector::Tasks() {
uint32_t avg = 0;
for (int i = 0; i < NUM_SAMPLES; i++) {
avg += analogRead(1);
}
float detect = avg / (float)NUM_SAMPLES / 4095.0f;
detect -= .37; // idle state
// Serial.printf("Button detect: %.2f\n", detect);
uint16_t button_state = detect < .02f;
if (button_state != last_button_state) {
if (!button_state) {
falling_edge_time = millis();
handled = false;
}
}
last_button_state = button_state;
if (!button_state && millis() - falling_edge_time > 30 && !handled) {
handled = true;
// Serial.printf("Timestamp: %llu\n", TimeSync::GetTime());
kart_sender.Send();
}
}