├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── Adafruit_Trellis.cpp ├── Adafruit_Trellis.h ├── README.txt ├── examples ├── TrellisGameofLife │ └── TrellisGameofLife.ino ├── TrellisLightsOut │ └── TrellisLightsOut.ino └── TrellisTest │ └── TrellisTest.ino └── library.properties /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /Adafruit_Trellis.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit Trellis w/HT16K33 3 | 4 | Designed specifically to work with the Adafruit Trellis 5 | ----> https://www.adafruit.com/products/1616 6 | ----> https://www.adafruit.com/products/1611 7 | 8 | These displays use I2C to communicate, 2 pins are required to 9 | interface 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #ifdef __AVR_ATtiny85__ 19 | #include 20 | #define Wire TinyWireM 21 | #else 22 | #include 23 | #endif 24 | 25 | #include "Adafruit_Trellis.h" 26 | 27 | #define HT16K33_BLINK_CMD 0x80 28 | #define HT16K33_BLINK_DISPLAYON 0x01 29 | #define HT16K33_CMD_BRIGHTNESS 0xE0 30 | 31 | /* 32 | These are the lookup tables that convert the LED/button # 33 | to the memory address in the HT16K33 - don't mess with them :) 34 | */ 35 | 36 | static const uint8_t PROGMEM 37 | ledLUT[16] = 38 | { 0x3A, 0x37, 0x35, 0x34, 39 | 0x28, 0x29, 0x23, 0x24, 40 | 0x16, 0x1B, 0x11, 0x10, 41 | 0x0E, 0x0D, 0x0C, 0x02 }, 42 | buttonLUT[16] = 43 | { 0x07, 0x04, 0x02, 0x22, 44 | 0x05, 0x06, 0x00, 0x01, 45 | 0x03, 0x10, 0x30, 0x21, 46 | 0x13, 0x12, 0x11, 0x31 }; 47 | 48 | Adafruit_Trellis::Adafruit_Trellis(void) { 49 | } 50 | 51 | void Adafruit_Trellis::begin(uint8_t _addr = 0x70) { 52 | i2c_addr = _addr; 53 | 54 | Wire.begin(); 55 | 56 | Wire.beginTransmission(i2c_addr); 57 | Wire.write(0x21); // turn on oscillator 58 | Wire.endTransmission(); 59 | blinkRate(HT16K33_BLINK_OFF); 60 | 61 | setBrightness(15); // max brightness 62 | 63 | Wire.beginTransmission(i2c_addr); 64 | Wire.write(0xA1); // turn on interrupt, active low 65 | Wire.endTransmission(); 66 | 67 | } 68 | 69 | /* 70 | Helper button functions, the data is updated every readSwitches() call! 71 | */ 72 | 73 | bool Adafruit_Trellis::isKeyPressed(uint8_t k) { 74 | if (k > 15) return false; 75 | k = pgm_read_byte(&buttonLUT[k]); 76 | return (keys[k>>4] & _BV(k & 0x0F)); 77 | } 78 | bool Adafruit_Trellis::wasKeyPressed(uint8_t k) { 79 | if (k > 15) return false; 80 | k = pgm_read_byte(&buttonLUT[k]); 81 | return (lastkeys[k>>4] & _BV(k & 0x0F)); 82 | } 83 | 84 | boolean Adafruit_Trellis::justPressed(uint8_t k) { 85 | return (isKeyPressed(k) & !wasKeyPressed(k)); 86 | } 87 | boolean Adafruit_Trellis::justReleased(uint8_t k) { 88 | return (!isKeyPressed(k) & wasKeyPressed(k)); 89 | } 90 | 91 | /* 92 | Helper LED functions, the data is written on writeDisplay() 93 | */ 94 | 95 | 96 | boolean Adafruit_Trellis::isLED(uint8_t x) { 97 | if (x > 15) return false; 98 | x = pgm_read_byte(&ledLUT[x]); 99 | return ((displaybuffer[x >> 4] & _BV(x & 0x0F)) > 0); 100 | } 101 | void Adafruit_Trellis::setLED(uint8_t x) { 102 | if (x > 15) return; 103 | x = pgm_read_byte(&ledLUT[x]); 104 | displaybuffer[x >> 4] |= _BV(x & 0x0F); 105 | } 106 | void Adafruit_Trellis::clrLED(uint8_t x) { 107 | if (x > 15) return; 108 | x = pgm_read_byte(&ledLUT[x]); 109 | displaybuffer[x >> 4] &= ~_BV(x & 0x0F); 110 | } 111 | 112 | 113 | /* 114 | Gets the switch memory data and updates the last/current read 115 | */ 116 | 117 | boolean Adafruit_Trellis::readSwitches(void) { 118 | memcpy(lastkeys, keys, sizeof(keys)); 119 | 120 | Wire.beginTransmission((byte)i2c_addr); 121 | Wire.write(0x40); 122 | Wire.endTransmission(); 123 | Wire.requestFrom((byte)i2c_addr, (byte)6); 124 | for (uint8_t i=0; i<6; i++) 125 | keys[i] = Wire.read(); 126 | 127 | for (uint8_t i=0; i<6; i++) { 128 | if (lastkeys[i] != keys[i]) { 129 | for (uint8_t j=0; j<6; j++) { 130 | //Serial.print(keys[j], HEX); Serial.print(" "); 131 | } 132 | //Serial.println(); 133 | return true; 134 | } 135 | } 136 | return false; 137 | } 138 | 139 | void Adafruit_Trellis::setBrightness(uint8_t b) { 140 | if (b > 15) b = 15; 141 | Wire.beginTransmission(i2c_addr); 142 | Wire.write(HT16K33_CMD_BRIGHTNESS | b); 143 | Wire.endTransmission(); 144 | } 145 | 146 | void Adafruit_Trellis::blinkRate(uint8_t b) { 147 | Wire.beginTransmission(i2c_addr); 148 | if (b > 3) b = 0; // turn off if not sure 149 | 150 | Wire.write(HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1)); 151 | Wire.endTransmission(); 152 | } 153 | 154 | 155 | void Adafruit_Trellis::writeDisplay(void) { 156 | Wire.beginTransmission(i2c_addr); 157 | Wire.write((uint8_t)0x00); // start at address $00 158 | 159 | for (uint8_t i=0; i<8; i++) { 160 | Wire.write(displaybuffer[i] & 0xFF); 161 | Wire.write(displaybuffer[i] >> 8); 162 | } 163 | Wire.endTransmission(); 164 | } 165 | 166 | void Adafruit_Trellis::clear(void) { 167 | memset(displaybuffer, 0, sizeof(displaybuffer)); 168 | } 169 | 170 | 171 | /*************************************************************************/ 172 | 173 | // Maximum 8 matrices (3 address pins) 174 | Adafruit_TrellisSet::Adafruit_TrellisSet(Adafruit_Trellis *matrix0, 175 | Adafruit_Trellis *matrix1, 176 | Adafruit_Trellis *matrix2, 177 | Adafruit_Trellis *matrix3, 178 | Adafruit_Trellis *matrix4, 179 | Adafruit_Trellis *matrix5, 180 | Adafruit_Trellis *matrix6, 181 | Adafruit_Trellis *matrix7) { 182 | matrices[0] = matrix0; 183 | matrices[1] = matrix1; 184 | matrices[2] = matrix2; 185 | matrices[3] = matrix3; 186 | matrices[4] = matrix4; 187 | matrices[5] = matrix5; 188 | matrices[6] = matrix6; 189 | matrices[7] = matrix7; 190 | 191 | _nummatrix = 0; 192 | 193 | for (uint8_t i=0; i<8; i++) { 194 | if (matrices[i] != 0) 195 | _nummatrix= i+1; 196 | else break; 197 | } 198 | } 199 | 200 | 201 | 202 | void Adafruit_TrellisSet::begin(uint8_t addr0, uint8_t addr1, 203 | uint8_t addr2, uint8_t addr3, 204 | uint8_t addr4, uint8_t addr5, 205 | uint8_t addr6, uint8_t addr7) { 206 | uint8_t addrs[8] = {addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7}; 207 | 208 | for (uint8_t i=0; i<_nummatrix; i++) { 209 | if (matrices[i] != 0) 210 | matrices[i]->begin(addrs[i]); 211 | } 212 | } 213 | 214 | /* 215 | Helper button functions, the data is updated every readSwitches() call! 216 | */ 217 | 218 | bool Adafruit_TrellisSet::isKeyPressed(uint8_t k) { 219 | if (k > 127) return false; 220 | uint8_t matrix, key; 221 | 222 | // determine submatrix # 223 | matrix = k / 16; 224 | key = k % 16; 225 | 226 | // not that many matrices! 227 | if (matrix >= _nummatrix) return false; 228 | 229 | return matrices[matrix]->isKeyPressed(key); 230 | } 231 | 232 | bool Adafruit_TrellisSet::wasKeyPressed(uint8_t k) { 233 | if (k > 127) return false; 234 | uint8_t matrix, key; 235 | 236 | // determine submatrix # 237 | matrix = k / 16; 238 | key = k % 16; 239 | 240 | // not that many matrices! 241 | if (matrix >= _nummatrix) return false; 242 | 243 | return matrices[matrix]->wasKeyPressed(key); 244 | } 245 | 246 | boolean Adafruit_TrellisSet::justPressed(uint8_t k) { 247 | return (isKeyPressed(k) & !wasKeyPressed(k)); 248 | } 249 | boolean Adafruit_TrellisSet::justReleased(uint8_t k) { 250 | return (!isKeyPressed(k) & wasKeyPressed(k)); 251 | } 252 | 253 | /* 254 | Helper LED functions, the data is written on writeDisplay() 255 | */ 256 | 257 | 258 | boolean Adafruit_TrellisSet::isLED(uint8_t x) { 259 | if (x > 127) return false; 260 | uint8_t matrix, led; 261 | 262 | // determine submatrix # 263 | matrix = x / 16; 264 | led = x % 16; 265 | 266 | // not that many matrices! 267 | if (matrix >= _nummatrix) return false; 268 | 269 | return matrices[matrix]->isLED(led); 270 | } 271 | 272 | void Adafruit_TrellisSet::setLED(uint8_t x) { 273 | if (x > 127) return ; 274 | uint8_t matrix, led; 275 | 276 | // determine submatrix # 277 | matrix = x / 16; 278 | led = x % 16; 279 | 280 | // not that many matrices! 281 | if (matrix >= _nummatrix) return ; 282 | 283 | matrices[matrix]->setLED(led); 284 | } 285 | 286 | void Adafruit_TrellisSet::clrLED(uint8_t x) { 287 | if (x > 127) return ; 288 | uint8_t matrix, led; 289 | 290 | // determine submatrix # 291 | matrix = x / 16; 292 | led = x % 16; 293 | 294 | // not that many matrices! 295 | if (matrix >= _nummatrix) return ; 296 | 297 | matrices[matrix]->clrLED(led); 298 | } 299 | 300 | 301 | /* 302 | Gets the switch memory data and updates the last/current read 303 | */ 304 | 305 | boolean Adafruit_TrellisSet::readSwitches(void) { 306 | boolean changed = false; 307 | for (uint8_t i=0; i<_nummatrix; i++) { 308 | if (matrices[i] != 0) 309 | changed = changed || matrices[i]->readSwitches(); 310 | } 311 | return changed; 312 | } 313 | 314 | void Adafruit_TrellisSet::setBrightness(uint8_t b) { 315 | for (uint8_t i=0; i<_nummatrix; i++) { 316 | if (matrices[i] != 0) 317 | matrices[i]->setBrightness(b); 318 | } 319 | } 320 | 321 | void Adafruit_TrellisSet::blinkRate(uint8_t b) { 322 | for (uint8_t i=0; i<_nummatrix; i++) { 323 | if (matrices[i] != 0) 324 | matrices[i]->blinkRate(b); 325 | } 326 | } 327 | 328 | 329 | void Adafruit_TrellisSet::writeDisplay(void) { 330 | for (uint8_t i=0; i<_nummatrix; i++) { 331 | if (matrices[i] != 0) 332 | matrices[i]->writeDisplay(); 333 | } 334 | } 335 | 336 | void Adafruit_TrellisSet::clear(void) { 337 | for (uint8_t i=0; i<_nummatrix; i++) { 338 | if (matrices[i] != 0) 339 | matrices[i]->clear(); 340 | } 341 | } 342 | -------------------------------------------------------------------------------- /Adafruit_Trellis.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit Trellis w/HT16K33 3 | 4 | Designed specifically to work with the Adafruit Trellis 5 | ----> https://www.adafruit.com/products/1616 6 | ----> https://www.adafruit.com/products/1611 7 | 8 | These displays use I2C to communicate, 2 pins are required to 9 | interface 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #ifndef _TRELLIS_H_ 19 | #define _TRELLIS_H_ 20 | 21 | // Set _BV if not already set (eg. Arudiono DUE, Arduino Zero Pro) 22 | #ifndef _BV 23 | #define _BV(bit) (1 << (bit)) 24 | #endif 25 | 26 | #if (ARDUINO >= 100) 27 | #include "Arduino.h" 28 | #else 29 | #include "WProgram.h" 30 | #endif 31 | 32 | #ifdef __AVR_ATtiny85__ 33 | #include 34 | #else 35 | #include 36 | #endif 37 | 38 | #define LED_ON 1 39 | #define LED_OFF 0 40 | 41 | #define HT16K33_BLINK_OFF 0 42 | #define HT16K33_BLINK_2HZ 1 43 | #define HT16K33_BLINK_1HZ 2 44 | #define HT16K33_BLINK_HALFHZ 3 45 | 46 | 47 | // this is the raw HT16K33 controller 48 | class Adafruit_Trellis { 49 | public: 50 | Adafruit_Trellis(void); 51 | void begin(uint8_t _addr); 52 | void setBrightness(uint8_t b); 53 | void blinkRate(uint8_t b); 54 | void writeDisplay(void); 55 | void clear(void); 56 | bool isKeyPressed(uint8_t k); 57 | bool wasKeyPressed(uint8_t k); 58 | boolean isLED(uint8_t x); 59 | void setLED(uint8_t x); 60 | void clrLED(uint8_t x); 61 | boolean readSwitches(void); 62 | boolean justPressed(uint8_t k); 63 | boolean justReleased(uint8_t k); 64 | 65 | uint16_t displaybuffer[8]; 66 | 67 | void init(uint8_t a); 68 | private: 69 | uint8_t keys[6], lastkeys[6]; 70 | 71 | uint8_t i2c_addr; 72 | }; 73 | 74 | 75 | // control a large # at a time! 76 | class Adafruit_TrellisSet { 77 | public: 78 | Adafruit_TrellisSet(Adafruit_Trellis *matrix0, 79 | Adafruit_Trellis *matrix1=0, 80 | Adafruit_Trellis *matrix2=0, 81 | Adafruit_Trellis *matrix3=0, 82 | Adafruit_Trellis *matrix4=0, 83 | Adafruit_Trellis *matrix5=0, 84 | Adafruit_Trellis *matrix6=0, 85 | Adafruit_Trellis *matrix7=0); 86 | void begin(uint8_t _addr0 = 0x70, uint8_t _addr1 = 0x71, 87 | uint8_t _addr2 = 0x72, uint8_t _addr3 = 0x73, 88 | uint8_t _addr4 = 0x74, uint8_t _addr5 = 0x75, 89 | uint8_t _addr6 = 0x76, uint8_t _addr7 = 0x77); 90 | 91 | void setBrightness(uint8_t b); 92 | void blinkRate(uint8_t b); 93 | void writeDisplay(void); 94 | void clear(void); 95 | bool isKeyPressed(uint8_t k); 96 | bool wasKeyPressed(uint8_t k); 97 | boolean isLED(uint8_t x); 98 | void setLED(uint8_t x); 99 | void clrLED(uint8_t x); 100 | boolean readSwitches(void); 101 | boolean justPressed(uint8_t k); 102 | boolean justReleased(uint8_t k); 103 | 104 | private: 105 | Adafruit_Trellis *matrices[8]; 106 | uint8_t _nummatrix; 107 | }; 108 | 109 | #endif // _TRELLIS_H_ 110 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit Trellis PCB 2 | 3 | Designed specifically to work with the Adafruit Trellis! 4 | ----> https://www.adafruit.com/products/1611 5 | ----> https://www.adafruit.com/products/1616 6 | 7 | These tiles use I2C to communicate, 2 pins are required to interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Check out the links above for our tutorials and wiring diagrams 14 | 15 | Arduino library Written by Limor Fried for Adafruit Industries. 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_Trellis 18 | Check that the Adafruit_Trellis folder contains Adafruit_Trellis.cpp and Adafruit_Trellis.h 19 | 20 | Place the Adafruit_Trellis library folder your *arduinosketchfolder*/libraries/ folder. 21 | You may need to create the libraries subfolder if its your first library. Restart the IDE. 22 | 23 | Check out our tutorial on how to install libraries for more details 24 | http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use -------------------------------------------------------------------------------- /examples/TrellisGameofLife/TrellisGameofLife.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an implementation of Conway's Game of Life. 3 | 4 | Designed specifically to work with the Adafruit Trellis 5 | ----> https://www.adafruit.com/products/1616 6 | ----> https://www.adafruit.com/products/1611 7 | 8 | These displays use I2C to communicate, 2 pins are required to 9 | interface 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Tony Sherwood for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #include 19 | #include "Adafruit_Trellis.h" 20 | 21 | Adafruit_Trellis matrix0 = Adafruit_Trellis(); 22 | Adafruit_Trellis matrix1 = Adafruit_Trellis(); 23 | Adafruit_Trellis matrix2 = Adafruit_Trellis(); 24 | Adafruit_Trellis matrix3 = Adafruit_Trellis(); 25 | 26 | Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0, &matrix1, &matrix2, &matrix3); 27 | 28 | #define NUMTRELLIS 4 29 | 30 | #define numKeys (NUMTRELLIS * 16) 31 | 32 | /* 33 | In order for this layout to work, you will have to have soldered your 4 boards 34 | together in the same order that I did. Below is the top view of the circuit, with 35 | each board's address, and lines indicating which boards are connected to each other. 36 | If you soldered your boards together differently, you will need to edit the chessboard 37 | array below until the LED wipe when you start up your sketch turns on all of the LEDs 38 | in order. 39 | 40 | [0x73]--[0x72] 41 | | 42 | [ARDUINO]--[0x70]--[0x71] 43 | 44 | */ 45 | 46 | int chessboard[8][8] = { 47 | {60, 56, 52, 48, 44, 40, 36, 32}, 48 | {61, 57, 53, 49, 45, 41, 37, 33}, 49 | {62, 58, 54, 50, 46, 42, 38, 34}, 50 | {63, 59, 55, 51, 47, 43, 39, 35}, 51 | {12, 8, 4, 0, 28, 24, 20, 16}, 52 | {13, 9, 5, 1, 29, 25, 21, 17}, 53 | {14, 10, 6, 2, 30, 26, 22, 18}, 54 | {15, 11, 7, 3, 31, 27, 23, 19} 55 | }; 56 | 57 | int nextFrame[64]; 58 | 59 | 60 | // Connect Trellis Vin to 5V and Ground to ground. 61 | // Connect the INT wire to pin #5 (can change later 62 | #define INTPIN 5 63 | // Connect I2C SDA pin to your Arduino SDA line 64 | // Connect I2C SCL pin to your Arduino SCL line 65 | // All Trellises share the SDA, SCL and INT pin! 66 | // Even 8 tiles use only 3 wires max 67 | 68 | 69 | void setup() { 70 | Serial.begin(9600); 71 | //Serial.println("Trellis Game of Life"); 72 | 73 | // INT pin requires a pullup 74 | pinMode(INTPIN, INPUT); 75 | digitalWrite(INTPIN, HIGH); 76 | 77 | trellis.begin(0x72, 0x71, 0x70, 0x73); 78 | 79 | for (uint8_t i=0; i<8; i++) { 80 | for (uint8_t j=0; j<8; j++) { 81 | trellis.setLED(chessboard[i][j]); 82 | trellis.writeDisplay(); 83 | delay(50); 84 | } 85 | } 86 | 87 | 88 | for (uint8_t i=0; i 7) x = 0; 153 | if (y < 0) y = 7; 154 | if (y > 7) y = 0; 155 | 156 | return chessboard[x][y]; 157 | } 158 | 159 | int getPosition(int pv, int *tx, int *ty) { 160 | for (int i=0; i<8; i++) { 161 | for (int j=0; j<8; j++) { 162 | if (chessboard[i][j] == pv) { 163 | *tx = i; 164 | *ty = j; 165 | return 1; 166 | } 167 | } 168 | } 169 | return -1; 170 | } 171 | 172 | void makeGlider() { 173 | trellis.setLED(chessboard[2][3]); 174 | trellis.setLED(chessboard[1][2]); 175 | trellis.setLED(chessboard[3][1]); 176 | trellis.setLED(chessboard[3][2]); 177 | trellis.setLED(chessboard[3][3]); 178 | trellis.writeDisplay(); 179 | } 180 | 181 | void makeOscillator() { 182 | trellis.setLED(chessboard[6][0]); 183 | trellis.setLED(chessboard[6][6]); 184 | trellis.setLED(chessboard[6][7]); 185 | trellis.setLED(chessboard[5][0]); 186 | trellis.setLED(chessboard[5][1]); 187 | trellis.setLED(chessboard[5][2]); 188 | } 189 | 190 | 191 | void liveOrDie(int placeVal) { 192 | // Calculate whether to live or die the next round 193 | int neighbors = 0; 194 | for (int d=0; d<=7; d++) { 195 | if (trellis.isLED(getNeighbor(placeVal, d))) { 196 | neighbors++; 197 | } 198 | } 199 | 200 | if (neighbors == 3 && !trellis.isLED(placeVal)) { 201 | nextFrame[placeVal] = 1; 202 | }else if ((neighbors == 2 || neighbors == 3) && trellis.isLED(placeVal)) { 203 | nextFrame[placeVal] = 1; 204 | } else { 205 | nextFrame[placeVal] = 0; 206 | } 207 | } 208 | 209 | void loop() { 210 | delay(500); // 100ms delay is required, dont remove me! 211 | 212 | // Clear out the next frame 213 | for(int c=0; c<64; c++) { 214 | nextFrame[c] = 0; 215 | } 216 | 217 | //compute the next step 218 | for (uint8_t i=0; i https://www.adafruit.com/products/1616 8 | ----> https://www.adafruit.com/products/1611 9 | 10 | These displays use I2C to communicate, 2 pins are required to 11 | interface 12 | Adafruit invests time and resources providing this open source code, 13 | please support Adafruit and open-source hardware by purchasing 14 | products from Adafruit! 15 | 16 | Written by Tony Sherwood for Adafruit Industries. 17 | MIT license, all text above must be included in any redistribution 18 | ****************************************************/ 19 | 20 | #include 21 | #include "Adafruit_Trellis.h" 22 | 23 | Adafruit_Trellis matrix0 = Adafruit_Trellis(); 24 | Adafruit_Trellis matrix1 = Adafruit_Trellis(); 25 | Adafruit_Trellis matrix2 = Adafruit_Trellis(); 26 | Adafruit_Trellis matrix3 = Adafruit_Trellis(); 27 | 28 | Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0, &matrix1, &matrix2, &matrix3); 29 | 30 | #define NUMTRELLIS 4 31 | 32 | #define numKeys (NUMTRELLIS * 16) 33 | 34 | /* 35 | In order for this layout to work, you will have to have soldered your 4 boards 36 | together in the same order that I did. Below is the top view of the circuit, with 37 | each board's address, and lines indicating which boards are connected to each other. 38 | If you soldered your boards together differently, you will need to edit the chessboard 39 | array below until the LED wipe when you start up your sketch turns on all of the LEDs 40 | in order. 41 | 42 | [0x73]--[0x72] 43 | | 44 | [ARDUINO]--[0x70]--[0x71] 45 | 46 | */ 47 | 48 | int chessboard[8][8] = { 49 | {60, 56, 52, 48, 44, 40, 36, 32}, 50 | {61, 57, 53, 49, 45, 41, 37, 33}, 51 | {62, 58, 54, 50, 46, 42, 38, 34}, 52 | {63, 59, 55, 51, 47, 43, 39, 35}, 53 | {12, 8, 4, 0, 28, 24, 20, 16}, 54 | {13, 9, 5, 1, 29, 25, 21, 17}, 55 | {14, 10, 6, 2, 30, 26, 22, 18}, 56 | {15, 11, 7, 3, 31, 27, 23, 19} 57 | }; 58 | 59 | 60 | // Connect Trellis Vin to 5V and Ground to ground. 61 | // Connect the INT wire to pin #5 (can change later 62 | #define INTPIN 5 63 | // Connect I2C SDA pin to your Arduino SDA line 64 | // Connect I2C SCL pin to your Arduino SCL line 65 | // All Trellises share the SDA, SCL and INT pin! 66 | // Even 8 tiles use only 3 wires max 67 | 68 | 69 | void setup() { 70 | Serial.begin(9600); 71 | Serial.println("Trellis Lights Out"); 72 | 73 | // INT pin requires a pullup 74 | pinMode(INTPIN, INPUT); 75 | digitalWrite(INTPIN, HIGH); 76 | 77 | trellis.begin(0x71, 0x72, 0x73, 0x70); 78 | 79 | for (uint8_t i=0; i<8; i++) { 80 | for (uint8_t j=0; j<8; j++) { 81 | trellis.setLED(chessboard[i][j]); 82 | trellis.writeDisplay(); 83 | delay(50); 84 | } 85 | } 86 | 87 | 88 | for (uint8_t i=0; i 7) x = 0; 151 | if (y < 0) y = 7; 152 | if (y > 7) y = 0; 153 | 154 | return chessboard[x][y]; 155 | } 156 | 157 | int getPosition(int pv, int *tx, int *ty) { 158 | for (int i=0; i<8; i++) { 159 | for (int j=0; j<8; j++) { 160 | if (chessboard[i][j] == pv) { 161 | *tx = i; 162 | *ty = j; 163 | return 1; 164 | } 165 | } 166 | } 167 | return -1; 168 | } 169 | 170 | void makeRandomBoard() { 171 | int x = 0; 172 | int y = 0; 173 | for (int i=0; i<10; i++) { 174 | x = random(0,7); 175 | y = random(0,7); 176 | makeYourMove(chessboard[x][y]); 177 | } 178 | trellis.writeDisplay(); 179 | delay(100); 180 | } 181 | 182 | void makeYourMove(int placeVal) { 183 | // First, flip this light 184 | toggle(placeVal); 185 | 186 | // Then, flip the lights to the N,S,E,W of this light 187 | toggle(getNeighbor(placeVal, 0)); // North 188 | toggle(getNeighbor(placeVal, 2)); // East 189 | toggle(getNeighbor(placeVal, 4)); // South 190 | toggle(getNeighbor(placeVal, 6)); // West 191 | } 192 | 193 | void loop() { 194 | delay(30); // 30ms delay is required, dont remove me! 195 | // If a button was just pressed or released... 196 | if (trellis.readSwitches()) { 197 | // go through every button 198 | for (uint8_t i=0; i https://www.adafruit.com/products/1616 6 | ----> https://www.adafruit.com/products/1611 7 | 8 | These displays use I2C to communicate, 2 pins are required to 9 | interface 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #include 19 | #include "Adafruit_Trellis.h" 20 | 21 | /*************************************************** 22 | This example shows reading buttons and setting/clearing buttons in a loop 23 | "momentary" mode has the LED light up only when a button is pressed 24 | "latching" mode lets you turn the LED on/off when pressed 25 | 26 | Up to 8 matrices can be used but this example will show 4 or 1 27 | ****************************************************/ 28 | 29 | #define MOMENTARY 0 30 | #define LATCHING 1 31 | // set the mode here 32 | #define MODE LATCHING 33 | 34 | 35 | Adafruit_Trellis matrix0 = Adafruit_Trellis(); 36 | 37 | // uncomment the below to add 3 more matrices 38 | /* 39 | Adafruit_Trellis matrix1 = Adafruit_Trellis(); 40 | Adafruit_Trellis matrix2 = Adafruit_Trellis(); 41 | Adafruit_Trellis matrix3 = Adafruit_Trellis(); 42 | // you can add another 4, up to 8 43 | */ 44 | 45 | // Just one 46 | Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0); 47 | // or use the below to select 4, up to 8 can be passed in 48 | //Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0, &matrix1, &matrix2, &matrix3); 49 | 50 | // set to however many you're working with here, up to 8 51 | #define NUMTRELLIS 1 52 | 53 | #define numKeys (NUMTRELLIS * 16) 54 | 55 | // Connect Trellis Vin to 5V and Ground to ground. 56 | // Connect the INT wire to pin #A2 (can change later!) 57 | #define INTPIN A2 58 | // Connect I2C SDA pin to your Arduino SDA line 59 | // Connect I2C SCL pin to your Arduino SCL line 60 | // All Trellises share the SDA, SCL and INT pin! 61 | // Even 8 tiles use only 3 wires max 62 | 63 | 64 | void setup() { 65 | Serial.begin(9600); 66 | Serial.println("Trellis Demo"); 67 | 68 | // INT pin requires a pullup 69 | pinMode(INTPIN, INPUT); 70 | digitalWrite(INTPIN, HIGH); 71 | 72 | // begin() with the addresses of each panel in order 73 | // I find it easiest if the addresses are in order 74 | trellis.begin(0x70); // only one 75 | // trellis.begin(0x70, 0x71, 0x72, 0x73); // or four! 76 | 77 | // light up all the LEDs in order 78 | for (uint8_t i=0; i 5 | sentence=Arduino library for controlling Adafruit Trellis 6 | paragraph=Arduino library for controlling Adafruit Trellis 7 | category=Device Control 8 | url=https://github.com/adafruit/Adafruit_Trellis_Library 9 | architectures=* 10 | --------------------------------------------------------------------------------