keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

LED_MCP23018.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef LED_MCP23018_H
  2. #define LED_MCP23018_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <Wire.h>
  6. #include <LED.h>
  7. #include "IOExpanderPort.h"
  8. /* Class LED_MCP23018 uses a MCP23018 I/O expander pin to turn a LED on and off.
  9. Connect the LED in series with the resistor:
  10. determin resistor value needed (Internet search: LED resistor value)
  11. Connect the LED's (-) ground to the AVR output pin
  12. connect LED's (+) to power
  13. Never connect a LED directly from ground to power. Doing so would destroy the LED.
  14. MCP23018 ouput is open drain. The output acts like a switch to ground.
  15. It cannot produce a high signal by itself.
  16. */
  17. class LED_MCP23018: public LED
  18. {
  19. private:
  20. IOExpanderPort& port;
  21. const uint8_t GPIO; //General Purpose Input/Ouput register address
  22. const uint8_t pin; //bitwise pin to LED
  23. public:
  24. LED_MCP23018(IOExpanderPort& port, const uint8_t pin)
  25. : port(port), GPIO(port.num + 0x12), pin(pin) {}
  26. virtual void on();
  27. virtual void off();
  28. };
  29. #endif