テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:8468a4403fea 1 /***************************************************
jksoft 0:8468a4403fea 2 This is a library for our I2C LED Backpacks
jksoft 0:8468a4403fea 3
jksoft 0:8468a4403fea 4 Designed specifically to work with the Adafruit LED Matrix backpacks
jksoft 0:8468a4403fea 5 ----> http://www.adafruit.com/products/
jksoft 0:8468a4403fea 6 ----> http://www.adafruit.com/products/
jksoft 0:8468a4403fea 7
jksoft 0:8468a4403fea 8 These displays use I2C to communicate, 2 pins are required to
jksoft 0:8468a4403fea 9 interface. There are multiple selectable I2C addresses. For backpacks
jksoft 0:8468a4403fea 10 with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
jksoft 0:8468a4403fea 11 with 3 Address Select pins: 0x70 thru 0x77
jksoft 0:8468a4403fea 12
jksoft 0:8468a4403fea 13 Adafruit invests time and resources providing this open source code,
jksoft 0:8468a4403fea 14 please support Adafruit and open-source hardware by purchasing
jksoft 0:8468a4403fea 15 products from Adafruit!
jksoft 0:8468a4403fea 16
jksoft 0:8468a4403fea 17 Written by Limor Fried/Ladyada for Adafruit Industries.
jksoft 0:8468a4403fea 18 BSD license, all text above must be included in any redistribution
jksoft 0:8468a4403fea 19 ****************************************************/
jksoft 0:8468a4403fea 20
jksoft 0:8468a4403fea 21 /*
jksoft 0:8468a4403fea 22 * Modified by Luiz Hespanha (http://www.d3.do) 8/16/2013 for use in LPC1768
jksoft 0:8468a4403fea 23 */
jksoft 0:8468a4403fea 24
jksoft 0:8468a4403fea 25 #include "mbed.h"
jksoft 0:8468a4403fea 26 #include "Adafruit_LEDBackpack.h"
jksoft 0:8468a4403fea 27 #include "Adafruit_GFX.h"
jksoft 0:8468a4403fea 28
jksoft 0:8468a4403fea 29 void Adafruit_LEDBackpack::setBrightness(uint8_t b) {
jksoft 0:8468a4403fea 30 if (b > 15) b = 15;
jksoft 0:8468a4403fea 31 uint8_t c = 0xE0 | b;
jksoft 0:8468a4403fea 32 char foo[1];
jksoft 0:8468a4403fea 33 foo[0] = c;
jksoft 0:8468a4403fea 34 _i2c->write(i2c_addr, foo, 1);
jksoft 0:8468a4403fea 35 }
jksoft 0:8468a4403fea 36
jksoft 0:8468a4403fea 37 void Adafruit_LEDBackpack::blinkRate(uint8_t b) {
jksoft 0:8468a4403fea 38 if (b > 3) b = 0; // turn off if not sure
jksoft 0:8468a4403fea 39 uint8_t c = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1);
jksoft 0:8468a4403fea 40 char foo[1];
jksoft 0:8468a4403fea 41 foo[0] = c;
jksoft 0:8468a4403fea 42 _i2c->write(i2c_addr, foo, 1);
jksoft 0:8468a4403fea 43 }
jksoft 0:8468a4403fea 44
jksoft 0:8468a4403fea 45 Adafruit_LEDBackpack::Adafruit_LEDBackpack(myI2C *i2c): _i2c(i2c) {
jksoft 0:8468a4403fea 46 }
jksoft 0:8468a4403fea 47
jksoft 0:8468a4403fea 48 void Adafruit_LEDBackpack::begin(uint8_t _addr = 0x70) {
jksoft 0:8468a4403fea 49 i2c_addr = _addr << 1;
jksoft 0:8468a4403fea 50
jksoft 0:8468a4403fea 51 char foo[1];
jksoft 0:8468a4403fea 52 foo[0] = 0x21;
jksoft 0:8468a4403fea 53
jksoft 0:8468a4403fea 54 _i2c->write(i2c_addr, foo, 1); // turn on oscillator
jksoft 0:8468a4403fea 55
jksoft 0:8468a4403fea 56 blinkRate(HT16K33_BLINK_OFF);
jksoft 0:8468a4403fea 57
jksoft 0:8468a4403fea 58 setBrightness(15); // max brightness
jksoft 0:8468a4403fea 59 }
jksoft 0:8468a4403fea 60
jksoft 0:8468a4403fea 61 void Adafruit_LEDBackpack::writeDisplay(void) {
jksoft 0:8468a4403fea 62 char foo[17];
jksoft 0:8468a4403fea 63 foo[0] = 0x00;
jksoft 0:8468a4403fea 64 int j = 0;
jksoft 0:8468a4403fea 65 for (uint8_t i=1; i<=16; i+=2) {
jksoft 0:8468a4403fea 66 int x = displaybuffer[j] & 0xFF;
jksoft 0:8468a4403fea 67 foo[i] = x;
jksoft 0:8468a4403fea 68 int x2 = displaybuffer[j] >> 8;
jksoft 0:8468a4403fea 69 foo[i+1] = x2;
jksoft 0:8468a4403fea 70 j++;
jksoft 0:8468a4403fea 71 }
jksoft 0:8468a4403fea 72 _i2c->write(i2c_addr, foo, 17);
jksoft 0:8468a4403fea 73 }
jksoft 0:8468a4403fea 74
jksoft 0:8468a4403fea 75 void Adafruit_LEDBackpack::clear(void) {
jksoft 0:8468a4403fea 76 for (uint8_t i=0; i<16; i++) {
jksoft 0:8468a4403fea 77 displaybuffer[i] = 0;
jksoft 0:8468a4403fea 78 }
jksoft 0:8468a4403fea 79 }
jksoft 0:8468a4403fea 80
jksoft 0:8468a4403fea 81 Adafruit_8x8matrix::Adafruit_8x8matrix(myI2C *i2c) : Adafruit_LEDBackpack(i2c), Adafruit_GFX(16, 16) {
jksoft 0:8468a4403fea 82 }
jksoft 0:8468a4403fea 83
jksoft 0:8468a4403fea 84 void Adafruit_8x8matrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
jksoft 0:8468a4403fea 85 if ((y < 0) || (y >= 16)) return;
jksoft 0:8468a4403fea 86 if ((x < 0) || (x >= 16)) return;
jksoft 0:8468a4403fea 87
jksoft 0:8468a4403fea 88 // check rotation, move pixel around if necessary
jksoft 0:8468a4403fea 89 switch (getRotation()) {
jksoft 0:8468a4403fea 90 case 0:
jksoft 0:8468a4403fea 91 if(y>=8){
jksoft 0:8468a4403fea 92 y+=16;
jksoft 0:8468a4403fea 93 }
jksoft 0:8468a4403fea 94 if(x>=8){
jksoft 0:8468a4403fea 95 x-=8;
jksoft 0:8468a4403fea 96 y+=8;
jksoft 0:8468a4403fea 97 }
jksoft 0:8468a4403fea 98 swap(x,y);
jksoft 0:8468a4403fea 99 break;
jksoft 0:8468a4403fea 100 case 1:
jksoft 0:8468a4403fea 101 swap(x, y);
jksoft 0:8468a4403fea 102 x = 8 - x - 1;
jksoft 0:8468a4403fea 103 break;
jksoft 0:8468a4403fea 104 case 2:
jksoft 0:8468a4403fea 105 x = 8 - x - 1;
jksoft 0:8468a4403fea 106 y = 8 - y - 1;
jksoft 0:8468a4403fea 107 break;
jksoft 0:8468a4403fea 108 case 3:
jksoft 0:8468a4403fea 109 swap(x, y);
jksoft 0:8468a4403fea 110 y = 8 - y - 1;
jksoft 0:8468a4403fea 111 break;
jksoft 0:8468a4403fea 112 }
jksoft 0:8468a4403fea 113
jksoft 0:8468a4403fea 114 #if 0
jksoft 0:8468a4403fea 115 // wrap around the x
jksoft 0:8468a4403fea 116 x += 7;
jksoft 0:8468a4403fea 117 x %= 8;
jksoft 0:8468a4403fea 118 #endif
jksoft 0:8468a4403fea 119
jksoft 0:8468a4403fea 120
jksoft 0:8468a4403fea 121 if (color) {
jksoft 0:8468a4403fea 122 displaybuffer[y] |= 1 << x;
jksoft 0:8468a4403fea 123 } else {
jksoft 0:8468a4403fea 124 displaybuffer[y] &= ~(1 << x);
jksoft 0:8468a4403fea 125 }
jksoft 0:8468a4403fea 126 }