Mbed driver for adafruit trellis.

Dependents:   Adafruit_Trellis_Hello_World

Committer:
wliu88
Date:
Sun Mar 13 17:31:13 2016 +0000
Revision:
1:3a43c8b959d8
Parent:
0:bbc12ba2cb6c
comments added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wliu88 0:bbc12ba2cb6c 1 #ifndef _BV
wliu88 0:bbc12ba2cb6c 2 #define _BV(bit) (1 << (bit))
wliu88 0:bbc12ba2cb6c 3 #endif
wliu88 0:bbc12ba2cb6c 4
wliu88 0:bbc12ba2cb6c 5 #include "mbed.h"
wliu88 0:bbc12ba2cb6c 6
wliu88 0:bbc12ba2cb6c 7 #define LED_ON 1
wliu88 0:bbc12ba2cb6c 8 #define LED_OFF 0
wliu88 0:bbc12ba2cb6c 9 #define HT16K33_BLINK_OFF 0
wliu88 0:bbc12ba2cb6c 10 #define HT16K33_BLINK_2HZ 1
wliu88 0:bbc12ba2cb6c 11 #define HT16K33_BLINK_1HZ 2
wliu88 0:bbc12ba2cb6c 12 #define HT16K33_BLINK_HALFHZ 3
wliu88 0:bbc12ba2cb6c 13
wliu88 0:bbc12ba2cb6c 14
wliu88 1:3a43c8b959d8 15 /**
wliu88 1:3a43c8b959d8 16 * A class for Adafruit trellis
wliu88 1:3a43c8b959d8 17 */
wliu88 0:bbc12ba2cb6c 18 class Adafruit_Trellis {
wliu88 1:3a43c8b959d8 19 public:
wliu88 1:3a43c8b959d8 20 /**
wliu88 1:3a43c8b959d8 21 * Create a new trellis object
wliu88 1:3a43c8b959d8 22 */
wliu88 1:3a43c8b959d8 23 Adafruit_Trellis(void);
wliu88 1:3a43c8b959d8 24
wliu88 1:3a43c8b959d8 25 /**
wliu88 1:3a43c8b959d8 26 * Initialize the trellis controller
wliu88 1:3a43c8b959d8 27 * @param _wire Address of an I2C master object
wliu88 1:3a43c8b959d8 28 * @param _addr Slave address of the trellis controller
wliu88 1:3a43c8b959d8 29 */
wliu88 1:3a43c8b959d8 30 void begin(I2C *_wire, uint8_t _addr);
wliu88 1:3a43c8b959d8 31
wliu88 1:3a43c8b959d8 32 /**
wliu88 1:3a43c8b959d8 33 * Set brightness(PWM) of LEDs
wliu88 1:3a43c8b959d8 34 * @param b Brightness level from 1 to 16 with 16 being the brightest
wliu88 1:3a43c8b959d8 35 */
wliu88 1:3a43c8b959d8 36 void setBrightness(uint8_t b);
wliu88 1:3a43c8b959d8 37
wliu88 1:3a43c8b959d8 38 /**
wliu88 1:3a43c8b959d8 39 * Set blink rate of LEDs
wliu88 1:3a43c8b959d8 40 * @param b Blink rate defined as macros
wliu88 1:3a43c8b959d8 41 */
wliu88 1:3a43c8b959d8 42 void blinkRate(uint8_t b);
wliu88 1:3a43c8b959d8 43
wliu88 1:3a43c8b959d8 44 /**
wliu88 1:3a43c8b959d8 45 * Write to LEDs after set and clear status of LEDs
wliu88 1:3a43c8b959d8 46 */
wliu88 1:3a43c8b959d8 47 void writeDisplay(void);
wliu88 1:3a43c8b959d8 48
wliu88 1:3a43c8b959d8 49 /**
wliu88 1:3a43c8b959d8 50 * Set all LEDs to off
wliu88 1:3a43c8b959d8 51 */
wliu88 1:3a43c8b959d8 52 void clear(void);
wliu88 1:3a43c8b959d8 53
wliu88 1:3a43c8b959d8 54 /**
wliu88 1:3a43c8b959d8 55 * Check status of LED
wliu88 1:3a43c8b959d8 56 * @param x LED index (1-16)
wliu88 1:3a43c8b959d8 57 * @return 1 for on, 0 for off
wliu88 1:3a43c8b959d8 58 */
wliu88 1:3a43c8b959d8 59 bool isLED(uint8_t x);
wliu88 1:3a43c8b959d8 60
wliu88 1:3a43c8b959d8 61 /**
wliu88 1:3a43c8b959d8 62 * Set LED status to on
wliu88 1:3a43c8b959d8 63 * @param x LED index (1-16)
wliu88 1:3a43c8b959d8 64 */
wliu88 1:3a43c8b959d8 65 void setLED(uint8_t x);
wliu88 0:bbc12ba2cb6c 66
wliu88 1:3a43c8b959d8 67 /**
wliu88 1:3a43c8b959d8 68 * Set LED status to off
wliu88 1:3a43c8b959d8 69 * @param x LED index (1-16)
wliu88 1:3a43c8b959d8 70 */
wliu88 1:3a43c8b959d8 71 void clrLED(uint8_t x);
wliu88 0:bbc12ba2cb6c 72
wliu88 1:3a43c8b959d8 73 /**
wliu88 1:3a43c8b959d8 74 * Check if button is pressed
wliu88 1:3a43c8b959d8 75 * @param k button index (1-16)
wliu88 1:3a43c8b959d8 76 * @return 1 for pressed, 0 for not pressed
wliu88 1:3a43c8b959d8 77 */
wliu88 1:3a43c8b959d8 78 bool isKeyPressed(uint8_t k);
wliu88 1:3a43c8b959d8 79
wliu88 1:3a43c8b959d8 80 /**
wliu88 1:3a43c8b959d8 81 * Check if button was pressed
wliu88 1:3a43c8b959d8 82 * @param k button index (1-16)
wliu88 1:3a43c8b959d8 83 * @return 1 for pressed, 0 for not pressed
wliu88 1:3a43c8b959d8 84 */
wliu88 1:3a43c8b959d8 85 bool wasKeyPressed(uint8_t k);
wliu88 1:3a43c8b959d8 86
wliu88 1:3a43c8b959d8 87 /**
wliu88 1:3a43c8b959d8 88 * Update all buttons' status, need to be called before checking buttons' status
wliu88 1:3a43c8b959d8 89 * @return 1 for any button has been switched, 0 otherwise
wliu88 1:3a43c8b959d8 90 */
wliu88 1:3a43c8b959d8 91 bool readSwitches(void);
wliu88 0:bbc12ba2cb6c 92
wliu88 1:3a43c8b959d8 93 /**
wliu88 1:3a43c8b959d8 94 * Check if button was just pressed
wliu88 1:3a43c8b959d8 95 * @param k button index (1-16)
wliu88 1:3a43c8b959d8 96 * @return 1 for pressed, 0 for not pressed
wliu88 1:3a43c8b959d8 97 */
wliu88 1:3a43c8b959d8 98 bool justPressed(uint8_t k);
wliu88 1:3a43c8b959d8 99
wliu88 1:3a43c8b959d8 100 /**
wliu88 1:3a43c8b959d8 101 * Check if button was just released
wliu88 1:3a43c8b959d8 102 * @param k button index (1-16)
wliu88 1:3a43c8b959d8 103 * @return 1 for released, 0 for not released
wliu88 1:3a43c8b959d8 104 */
wliu88 1:3a43c8b959d8 105 bool justReleased(uint8_t k);
wliu88 1:3a43c8b959d8 106
wliu88 1:3a43c8b959d8 107 uint16_t displaybuffer[8];
wliu88 1:3a43c8b959d8 108
wliu88 1:3a43c8b959d8 109 void init(uint8_t a);
wliu88 1:3a43c8b959d8 110
wliu88 1:3a43c8b959d8 111 private:
wliu88 1:3a43c8b959d8 112 uint8_t keys[6], lastkeys[6];
wliu88 1:3a43c8b959d8 113
wliu88 1:3a43c8b959d8 114 uint8_t i2c_addr;
wliu88 1:3a43c8b959d8 115 char cmd[20];
wliu88 1:3a43c8b959d8 116 I2C *wire;
wliu88 1:3a43c8b959d8 117 };