IoT Component

This commit is contained in:
Siwat Sirichai 2023-12-28 12:46:39 +07:00
parent 908c3f9c0e
commit d3497b671e
8 changed files with 209 additions and 6 deletions

View file

@ -27,6 +27,8 @@ bool DigitalOutputCard::begin() {
// Set the output to the specified state
void DigitalOutputCard::digitalWrite(uint8_t pin, bool state) {
this->pwm.setPin(pin, state ? 4095 : 0);
this->state_buffer[pin] = state;
this->value_buffer[pin] = state ? 4095 : 0;
}
// Set the output to the specified pwm value
void DigitalOutputCard::analogWrite(uint8_t pin, uint16_t value) {
@ -34,12 +36,24 @@ void DigitalOutputCard::analogWrite(uint8_t pin, uint16_t value) {
if (value > 4095) value = 4095;
// Set the pwm value
this->pwm.setPin(pin, value);
this->state_buffer[pin] = value > 0;
this->value_buffer[pin] = value;
}
// Dummy loop function
void DigitalOutputCard::loop() {
}
// Get the state of the specified pin
bool DigitalOutputCard::getState(uint8_t pin) {
return this->state_buffer[pin];
}
// Get the pwm value of the specified pin
uint16_t DigitalOutputCard::getValue(uint8_t pin) {
return this->value_buffer[pin];
}
// Get type of card
uint8_t DigitalOutputCard::getType() {
return CARD_TYPE_DIGITAL_OUTPUT;