led.cpp 416 B

1234567891011121314151617181920212223
  1. #include "led.h"
  2. #include <Arduino.h>
  3. Led::Led(uint8_t const pin)
  4. : pin_{ pin } {
  5. }
  6. void Led::init() noexcept {
  7. pinMode(pin_, OUTPUT);
  8. }
  9. void Led::setState(LedState const state) noexcept {
  10. digitalWrite(pin_, static_cast<uint8_t>(state));
  11. }
  12. LedState Led::getState() const noexcept {
  13. return static_cast<LedState>(digitalRead(pin_));
  14. }
  15. void Led::toggleState() noexcept {
  16. return setState(~getState());
  17. }