From c8c27d440c01aca4122e46c6aad1dffcbd824bd3 Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Thu, 15 May 2025 23:30:48 +0200 Subject: [PATCH] Implement pump control via port register --- firmware/atmega/source/main.c | 7 +++++-- firmware/atmega/source/pump.c | 18 ++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/firmware/atmega/source/main.c b/firmware/atmega/source/main.c index 4b27300..a7065e4 100644 --- a/firmware/atmega/source/main.c +++ b/firmware/atmega/source/main.c @@ -3,8 +3,11 @@ #include #include #include -#include "moisture.h" #include "adc.h" +#include "moisture.h" +#include "pump.h" + + ISR(WDT_vect) { triggerRead(); @@ -27,8 +30,8 @@ void enterSleep(void) { void setup(void) { adcInit(); - //pumpsInit(); sensorsInit(); + //pumpsInit(); watchdogs(); } diff --git a/firmware/atmega/source/pump.c b/firmware/atmega/source/pump.c index 36829d3..356b5f8 100644 --- a/firmware/atmega/source/pump.c +++ b/firmware/atmega/source/pump.c @@ -10,17 +10,15 @@ void pumpsInit(void) { (1 << PUMP_D4) | (1 << PUMP_D3) | 0 | 0 | 0 )); - // Disable pullup - PORTD &= ~((1 << PUMP_D7) | - (1 << PUMP_D6) | - (1 << PUMP_D5) | - (1 << PUMP_D4) | - (1 << PUMP_D3) | - 0 | 0 | 0 )); } void triggerPump(int8_t pump_pin, int16_t milliseconds) { - // turn on pump - // watchdog for n milliseconds - // turn of pump + // Turn on pump + PORTD |= (1 << pump_pin); + + // timer for n milliseconds + // NOTE: watchout for overflows!! create a safety net. + + // Turn off pump + PORTD &= ~(1 << pump_pin); }