-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmly038.h
More file actions
31 lines (23 loc) · 834 Bytes
/
mly038.h
File metadata and controls
31 lines (23 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
#include "SelfThreadable/self_threadable.h"
// mLY wraps LY038 in a async class. This way, less things to worry about.
class mLY : protected SelfThreadable {
const int m_pin;
float m_vol = 0.0f;
bool m_has_new_data = false;
void async() {
pinMode(m_pin, INPUT);
while(1) {
const float rn = 100.0f * analogRead(m_pin) / 4095.0f;
m_vol = (m_vol * 199.0f + rn) / 200.0f;
m_has_new_data = true;
delay(5);
}
vTaskDelete(NULL);
}
public:
mLY(const int pin) : SelfThreadable("ASYNC"), m_pin(pin) { async_start(); }
float get_vol() const { return m_vol; }
bool has_issues() const { return false; }
bool has_new_data_autoreset() { bool had = m_has_new_data; m_has_new_data = false; return had; }
};