Created
November 2, 2017 15:51
-
-
Save winsonwq/c6dc1fc40eaf57fa5657b601cae8e86f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cocotouch.h" | |
#include <Adafruit_NeoPixel.h> | |
#include <avr/power.h> | |
#define PIN 5 | |
#define NUMPIXELS 60 | |
CocoTouch touch; | |
uint8_t touchstates[12]; | |
uint8_t index; | |
uint8_t notes[12] = {35, 38, 40, 42, 46, 43, 48, 47, 41, 51, 49, 52}; | |
uint8_t colors[12][3] = { | |
{231,52,106}, | |
{241,156,166}, | |
{232,194,85}, | |
{238,115,13}, | |
{237,220,77}, | |
{233,68,65}, | |
{195,217,78}, | |
{152,80,152}, | |
{45,116,187}, | |
{145,211,232}, | |
{200,109,68}, | |
{142,207,205}, | |
}; | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
if (!touch.begin()) { while(1){;} } | |
#if defined (__AVR_ATtiny85__) | |
if (F_CPU == 16000000) clock_prescale_set(clock_div_1); | |
#endif | |
pixels.begin(); // This initializes the NeoPixel library. | |
touch.setMIDIProgram(1, 0); | |
} | |
void loop() { | |
for (uint8_t index = 0; index <= 11; index++) { | |
if (touchstates[index] == 0 && touch.getTouched(index) == 1) { | |
touch.playMIDINote(notes[index], 127, 0); | |
touchstates[index] = 1; | |
pixels.setPixelColor(index * 5, pixels.Color(colors[index][0],colors[index][1],colors[index][2])); | |
pixels.setPixelColor(index * 5 + 1, pixels.Color(colors[index][0],colors[index][1],colors[index][2])); | |
pixels.setPixelColor(index * 5 + 2, pixels.Color(colors[index][0],colors[index][1],colors[index][2])); | |
pixels.setPixelColor(index * 5 + 3, pixels.Color(colors[index][0],colors[index][1],colors[index][2])); | |
pixels.setPixelColor(index * 5 + 4, pixels.Color(colors[index][0],colors[index][1],colors[index][2])); | |
pixels.show(); | |
} else if (touchstates[index] == 1 && touch.getTouched(index) == 0) { | |
touchstates[index] = 0; | |
pixels.setPixelColor(index, pixels.Color(0,0,0)); | |
pixels.setPixelColor(index * 5, pixels.Color(0,0,0)); | |
pixels.setPixelColor(index * 5 + 1, pixels.Color(0,0,0)); | |
pixels.setPixelColor(index * 5 + 2, pixels.Color(0,0,0)); | |
pixels.setPixelColor(index * 5 + 3, pixels.Color(0,0,0)); | |
pixels.setPixelColor(index * 5 + 4, pixels.Color(0,0,0)); | |
pixels.show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment