HT16K33.h
1 // SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include "Arduino.h" 6 7 #define DISP_REGISTER 0x00 8 #define KEYS_REGISTER 0x40 9 #define MAX_BRIGHTNESS 12 10 #define MIN_BRIGHTNESS 0 11 #define INITIAL_BRIGHTNESS 1 12 13 class HT16K33 { 14 private: 15 uint8_t i2c_addr; 16 uint8_t brightness; 17 uint8_t buffer[16]; 18 19 // all four variables are updated in readButtons() 20 uint8_t previousButtonState; // stored in MSB First format: B7, ... , B0 21 uint8_t currentButtonState; // stored in MSB First format: B7, ... , B0 22 uint8_t buttonFirstPress; // stored in MSB First format: B7, ... , B0 23 uint16_t buttonHoldTime[8]; // stored in LSB First format: B0, ... , B7 24 25 uint16_t* transposeMatrix(uint8_t* matrix); 26 void sendCommand(uint8_t c); 27 void setBrightness(uint8_t b); 28 29 public: 30 HT16K33(uint8_t _addr); 31 void init(); 32 void increaseBrightness(); 33 void decreaseBrightness(); 34 35 void storeToBuffer(uint8_t* matrix); 36 void refreshDisplay(); 37 void clearDisplay(); 38 void readButtons(); // only reads the first byte of the key scan register becasue only the first 7 keys are used on this device 39 bool getButtonFirstPress(uint8_t i); 40 uint16_t getButtonHoldTime(uint8_t i); 41 bool allowToMove(uint8_t i, uint16_t time, uint8_t rate); 42 };