Atm_led_mcp.cpp 996 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Atm_led_mcp.cpp
  3. *
  4. * Created on: 09.12.2017
  5. * Author: ian
  6. */
  7. #include <Atm_led_mcp.h>
  8. #include <Atm_led.hpp>
  9. Atm_led_mcp::Atm_led_mcp(Adafruit_MCP23017& _gpio):
  10. Atm_led(), // base class ctor would also be called implicitly, but better style to mention this explicitly :)
  11. gpio(_gpio) {
  12. // nothing to see here
  13. }
  14. void Atm_led_mcp::initLED() {
  15. gpio.pinMode(pin, OUTPUT);
  16. gpio.digitalWrite(pin, activeLow ? HIGH : LOW);
  17. Serial.printf("LED init on pin %c%x\n", activeLow?'~':' ', pin);
  18. }
  19. void Atm_led_mcp::switchOn() {
  20. Serial.printf("LED ON on pin %c%x\n", activeLow?'~':' ', pin);
  21. gpio.digitalWrite(pin, !activeLow);
  22. }
  23. void Atm_led_mcp::switchOff() {
  24. Serial.printf("LED OFF on pin %c%x\n", activeLow?'~':' ', pin);
  25. gpio.digitalWrite(pin, activeLow);
  26. }
  27. void Atm_led_mcp::setBrightness(int value) {
  28. if (value == toHigh) switchOn(); else if(value==toLow) switchOff(); else
  29. Serial.printf("ERROR: Setting brightness on GPIO expander is not possible (pin: %d)\n", pin);
  30. }