From 83ed233dd4f2feef0918257491c9e5ebf3d962c3 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 28 Dec 2023 17:31:59 +0700 Subject: [PATCH] digital output card fully working --- .../lib/ESPMegaPRO/DigitalOutputCard.cpp | 17 ++++++++++++++++- Template Project/src/iotdemo.cpp | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Template Project/lib/ESPMegaPRO/DigitalOutputCard.cpp b/Template Project/lib/ESPMegaPRO/DigitalOutputCard.cpp index 9186844..71414a6 100644 --- a/Template Project/lib/ESPMegaPRO/DigitalOutputCard.cpp +++ b/Template Project/lib/ESPMegaPRO/DigitalOutputCard.cpp @@ -18,7 +18,6 @@ DigitalOutputCard::DigitalOutputCard(bool bit0, bool bit1, bool bit2, bool bit3, bool DigitalOutputCard::begin() { this->pwm = Adafruit_PWMServoDriver(this->address); this->pwm.begin(); - pwm.reset(); pwm.setOutputMode(true); // Output card don't send ack, we can't check if it's connected // so we just return true @@ -60,13 +59,29 @@ uint8_t DigitalOutputCard::getType() { } void DigitalOutputCard::setState(uint8_t pin, bool state) { + Serial.print("Setting state of pin "); + Serial.print(pin); + Serial.print(" to "); + Serial.println(state); this-> state_buffer[pin] = state; + Serial.print("New state of pin "); + Serial.print(pin); + Serial.print(" is "); + Serial.println(state_buffer[pin]*value_buffer[pin]); this->pwm.setPin(pin, state*value_buffer[pin]); } void DigitalOutputCard::setValue(uint8_t pin, uint16_t value) { + Serial.print("Setting value of pin "); + Serial.print(pin); + Serial.print(" to "); + Serial.println(value); // If value is greater than 4095, set it to 4095 if (value > 4095) value = 4095; this-> value_buffer[pin] = value; + Serial.print("New value of pin "); + Serial.print(pin); + Serial.print(" is "); + Serial.println(value_buffer[pin]*state_buffer[pin]); this->pwm.setPin(pin, state_buffer[pin]*value); } diff --git a/Template Project/src/iotdemo.cpp b/Template Project/src/iotdemo.cpp index d2846a0..2fa7e88 100644 --- a/Template Project/src/iotdemo.cpp +++ b/Template Project/src/iotdemo.cpp @@ -29,6 +29,7 @@ void setup() espmega.iot.registerMqttCallback(mqtt_callback); espmega.iot.registerCard(1); espmega.iot.publishCard(1); + } void loop()