digital output card fully working

This commit is contained in:
Siwat Sirichai 2023-12-28 17:31:59 +07:00
parent 63a34afee3
commit 83ed233dd4
2 changed files with 17 additions and 1 deletions

View File

@ -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);
}

View File

@ -29,6 +29,7 @@ void setup()
espmega.iot.registerMqttCallback(mqtt_callback);
espmega.iot.registerCard(1);
espmega.iot.publishCard(1);
}
void loop()