Arduino refactoring #4

Open
fiveop wants to merge 28 commits from fiveop/arduino_refactoring into master
Showing only changes of commit aaab790f81 - Show all commits

View file

@ -20,6 +20,8 @@ void setup(){
const int DELAY_TIME = 1000;
const int MAX_COUNTER = 20;
const int LOWER_THRESHOLD = 3;
const int UPPER_THRESHOLD = MAX_COUNTER - LOWER_THRESHOLD;
const int CLOSED_DOOR = 1;
const int OPEN_DOOR = 0;
@ -44,9 +46,9 @@ void update_measured_state_counter() {
void update_published_state() {
// status check if we can switch the status.
// low pass prevents waggling a bit
if (measured_state_counter >= MAX_COUNTER-3) {
if (measured_state_counter >= UPPER_THRESHOLD) {
published_state = CLOSED_DOOR;
} else if (measured_state_counter <= 3) {
} else if (measured_state_counter <= LOWER_THRESHOLD) {
published_state = OPEN_DOOR;
}
}
@ -60,7 +62,7 @@ void update_led_pins() {
digitalWrite(GREEN_LED_OUTPUT_PIN, HIGH);
}
if (measured_state_counter > 3 && measured_state_counter < MAX_COUNTER - 3) {
if (measured_state_counter > LOWER_THRESHOLD && measured_state_counter < UPPER_THRESHOLD) {
digitalWrite(YELLOW_LED_OUTPUT_PIN, HIGH);
} else {
digitalWrite(YELLOW_LED_OUTPUT_PIN, LOW);