Demo program for using adafruit trellis.

Dependencies:   Adafruit_Trellis mbed

Committer:
wliu88
Date:
Sun Mar 13 17:31:36 2016 +0000
Revision:
0:1b1f6789bbdd
hello world

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wliu88 0:1b1f6789bbdd 1 #include "mbed.h"
wliu88 0:1b1f6789bbdd 2 #include "Adafruit_Trellis.h"
wliu88 0:1b1f6789bbdd 3
wliu88 0:1b1f6789bbdd 4 I2C wire(p28, p27);
wliu88 0:1b1f6789bbdd 5
wliu88 0:1b1f6789bbdd 6 int main() {
wliu88 0:1b1f6789bbdd 7 Adafruit_Trellis trellis = Adafruit_Trellis();
wliu88 0:1b1f6789bbdd 8 trellis.begin(&wire, 0x70);
wliu88 0:1b1f6789bbdd 9 trellis.clear();
wliu88 0:1b1f6789bbdd 10 int numKeys = 16;
wliu88 0:1b1f6789bbdd 11 for (uint8_t i=0; i<numKeys; i++) {
wliu88 0:1b1f6789bbdd 12 trellis.setLED(i);
wliu88 0:1b1f6789bbdd 13 trellis.writeDisplay();
wliu88 0:1b1f6789bbdd 14 wait(0.05);
wliu88 0:1b1f6789bbdd 15 }
wliu88 0:1b1f6789bbdd 16 // then turn them off
wliu88 0:1b1f6789bbdd 17 for (uint8_t i=0; i<numKeys; i++) {
wliu88 0:1b1f6789bbdd 18 trellis.clrLED(i);
wliu88 0:1b1f6789bbdd 19 trellis.writeDisplay();
wliu88 0:1b1f6789bbdd 20 wait(0.05);
wliu88 0:1b1f6789bbdd 21 }
wliu88 0:1b1f6789bbdd 22
wliu88 0:1b1f6789bbdd 23 while(true) {
wliu88 0:1b1f6789bbdd 24 wait(0.03);
wliu88 0:1b1f6789bbdd 25 if (trellis.readSwitches()) {
wliu88 0:1b1f6789bbdd 26 // go through every button
wliu88 0:1b1f6789bbdd 27 for (uint8_t i=0; i<numKeys; i++) {
wliu88 0:1b1f6789bbdd 28 // if it was pressed...
wliu88 0:1b1f6789bbdd 29 if (trellis.justPressed(i)) {
wliu88 0:1b1f6789bbdd 30 // Alternate the LED
wliu88 0:1b1f6789bbdd 31 if (trellis.isLED(i))
wliu88 0:1b1f6789bbdd 32 trellis.clrLED(i);
wliu88 0:1b1f6789bbdd 33 else
wliu88 0:1b1f6789bbdd 34 trellis.setLED(i);
wliu88 0:1b1f6789bbdd 35 }
wliu88 0:1b1f6789bbdd 36 }
wliu88 0:1b1f6789bbdd 37 // tell the trellis to set the LEDs we requested
wliu88 0:1b1f6789bbdd 38 trellis.writeDisplay();
wliu88 0:1b1f6789bbdd 39 }
wliu88 0:1b1f6789bbdd 40 }
wliu88 0:1b1f6789bbdd 41 }