Adding all files from Project 1 to start

This commit is contained in:
2026-09-10 10:15:52 +00:00
parent 2bd9fb2ba4
commit a73f7002bc
22 changed files with 786 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
#include "rotary_encoder_driver.h"
#include <avr/interrupt.h>
RotaryEncoderDriver* driver = nullptr;
RotaryEncoderDriver::RotaryEncoderDriver()
: cycle(0)
, count(0)
, prev_count(0)
, led(5)
, eA(2)
, eB(5) {}
void RotaryEncoderDriver::begin() {
driver = this;
led.init();
eA.init();
eB.init();
EICRA |= (1<<ISC01) | (1<<ISC00);
EIMSK |= (1<<INT0);
timer.init(100);
}
void RotaryEncoderDriver::update() {
count += eB.is_hi() ? 1 : -1;
led.set_hi();
}
int RotaryEncoderDriver::position() {
led.set_lo();
return count;
}
void RotaryEncoderDriver::update_delta() {
if (++cycle == 0) {
delta = count - prev_count;
prev_count = count;
}
led.set_lo();
}
float RotaryEncoderDriver::count_per_sec() {
return delta / (256.0f * 0.0001f);
}
ISR(INT0_vect) {
driver->update();
}
ISR(TIMER1_COMPA_vect) {
driver->update_delta();
}