@@ -0,0 +1,80 @@
|
||||
#ifndef POS3_ANALOG_H
|
||||
#define POS3_ANALOG_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../enums.h"
|
||||
#include "../common/ppmath.h"
|
||||
|
||||
class Pos3Analog
|
||||
{
|
||||
public:
|
||||
Pos3Analog(short _upPin, short _downPin) : upPin(_upPin), downPin(_downPin)
|
||||
{
|
||||
}
|
||||
|
||||
short setup()
|
||||
{
|
||||
pinMode(upPin, INPUT_PULLUP);
|
||||
pinMode(downPin, INPUT_PULLUP);
|
||||
last_switch = loop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
short loop()
|
||||
{
|
||||
uchar newDirection = this->read();
|
||||
|
||||
if (newDirection != this->switch_pos)
|
||||
{
|
||||
this->last_switch = this->switch_pos;
|
||||
}
|
||||
this->switch_pos = newDirection;
|
||||
return this->switch_pos;
|
||||
}
|
||||
|
||||
short last_switch = -1; // Track last switch position
|
||||
short switch_pos = -1; // Current switch position
|
||||
short upPin;
|
||||
short downPin;
|
||||
|
||||
|
||||
private:
|
||||
uchar read()
|
||||
{
|
||||
|
||||
bool up = RANGE(analogRead(upPin), 240, 260);
|
||||
bool down = RANGE(analogRead(downPin), 240, 260);
|
||||
|
||||
uchar newDirection = 0;
|
||||
|
||||
if (up)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::UP;
|
||||
}
|
||||
if (down)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::DOWN;
|
||||
}
|
||||
if (!up && !down)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::MIDDLE;
|
||||
}
|
||||
if (up && down)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::INVALID;
|
||||
}
|
||||
return newDirection;
|
||||
}
|
||||
|
||||
bool changed()
|
||||
{
|
||||
return last_switch != switch_pos;
|
||||
}
|
||||
|
||||
bool clear()
|
||||
{
|
||||
return last_switch = switch_pos;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef POS3_H
|
||||
#define POS3_H
|
||||
|
||||
#include <Bounce2.h>
|
||||
#include "../enums.h"
|
||||
|
||||
class Pos3
|
||||
{
|
||||
public:
|
||||
Pos3(int _upPin, int _downPin) : upPin(_upPin), downPin(_downPin)
|
||||
{
|
||||
}
|
||||
|
||||
int setup()
|
||||
{
|
||||
|
||||
this->debouncerUp = Bounce();
|
||||
this->debouncerUp.attach(this->upPin, INPUT_PULLUP);
|
||||
this->debouncerUp.interval(25);
|
||||
|
||||
this->debouncerDown = Bounce();
|
||||
this->debouncerDown.attach(this->downPin, INPUT_PULLUP);
|
||||
this->debouncerDown.interval(25);
|
||||
return 0;
|
||||
}
|
||||
int loop()
|
||||
{
|
||||
int newDirection = this->read();
|
||||
|
||||
if (newDirection != this->switch_pos)
|
||||
{
|
||||
this->last_switch = this->switch_pos;
|
||||
}
|
||||
this->switch_pos = newDirection;
|
||||
|
||||
return this->switch_pos;
|
||||
}
|
||||
|
||||
int last_switch = -1; // Track last switch position
|
||||
int switch_pos = -1; // Current switch position
|
||||
|
||||
protected:
|
||||
int upPin;
|
||||
int downPin;
|
||||
|
||||
Bounce debouncerUp;
|
||||
Bounce debouncerDown;
|
||||
|
||||
private:
|
||||
int read()
|
||||
{
|
||||
|
||||
this->debouncerUp.update();
|
||||
this->debouncerDown.update();
|
||||
|
||||
bool up = this->debouncerUp.read() == 0 ? true : false;
|
||||
bool down = this->debouncerDown.read() == 0 ? true : false;
|
||||
|
||||
int newDirection = 0;
|
||||
|
||||
if (up)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::UP;
|
||||
}
|
||||
if (down)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::DOWN;
|
||||
}
|
||||
if (!up && !down)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::MIDDLE;
|
||||
}
|
||||
if (up && down)
|
||||
{
|
||||
newDirection = POS3_DIRECTION::INVALID;
|
||||
}
|
||||
return newDirection;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef TEMPERATURE_SENSOR_H
|
||||
#define TEMPERATURE_SENSOR_H
|
||||
|
||||
#include <max6675.h>
|
||||
#include "../config.h"
|
||||
#include "../macros.h"
|
||||
#include "../time.h"
|
||||
|
||||
class TemperatureSensor
|
||||
{
|
||||
|
||||
public:
|
||||
TemperatureSensor(short sck, short cs, short so, short _max, short _interval) : ktc(MAX6675(sck, cs, so)),
|
||||
temperature(),
|
||||
temperature_TS(millis()),
|
||||
maxTemp(_max),
|
||||
interval(_interval) {}
|
||||
|
||||
bool ok()
|
||||
{
|
||||
return temperature < maxTemp;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (millis() - temperature_TS > interval)
|
||||
{
|
||||
temperature_TS = millis();
|
||||
temperature = ktc.readCelsius();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MAX6675 ktc;
|
||||
short temperature;
|
||||
short maxTemp;
|
||||
short interval;
|
||||
millis_t temperature_TS;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user