Created
November 9, 2017 20:50
-
-
Save winsonwq/7d25a2fced9b79c27a0a5b9ff075aef8 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 8 | |
#define NUMPIXELS 60 | |
char index; | |
uint8_t idx; | |
uint8_t midiNotes[6]; | |
uint8_t states[6]; | |
CocoTouch touch; | |
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(26, 1); | |
} | |
void loop() { | |
for (idx = 0; idx <= 5; idx++) { | |
if (states[idx] == 0 && touch.getTouched(idx) == 1) { | |
touch.playMIDINote(midiNotes[idx], 127, 1); | |
states[idx] = 1; | |
pixels.setPixelColor(idx * 5, pixels.Color(colors[idx][0],colors[idx][1],colors[idx][2])); | |
pixels.setPixelColor(idx * 5 + 1, pixels.Color(colors[idx][0],colors[idx][1],colors[idx][2])); | |
pixels.setPixelColor(idx * 5 + 2, pixels.Color(colors[idx][0],colors[idx][1],colors[idx][2])); | |
pixels.setPixelColor(idx * 5 + 3, pixels.Color(colors[idx][0],colors[idx][1],colors[idx][2])); | |
pixels.setPixelColor(idx * 5 + 4, pixels.Color(colors[idx][0],colors[idx][1],colors[idx][2])); | |
pixels.show(); | |
} else if (states[idx] == 1 && touch.getTouched(idx) < 1) { | |
states[idx] = 0; | |
pixels.setPixelColor(idx * 5, pixels.Color(0, 0, 0)); | |
pixels.setPixelColor(idx * 5 + 1, pixels.Color(0, 0, 0)); | |
pixels.setPixelColor(idx * 5 + 2, pixels.Color(0, 0, 0)); | |
pixels.setPixelColor(idx * 5 + 3, pixels.Color(0, 0, 0)); | |
pixels.setPixelColor(idx * 5 + 4, pixels.Color(0, 0, 0)); | |
pixels.show(); | |
} | |
} | |
if (touch.getTouched(6) == 1) { | |
midiNotes[0] = 43; | |
midiNotes[1] = 48; | |
midiNotes[2] = 52; | |
midiNotes[3] = 55; | |
midiNotes[4] = 60; | |
midiNotes[5] = 64; | |
} else if (touch.getTouched(7) == 1) { | |
midiNotes[0] = 45; | |
midiNotes[1] = 50; | |
midiNotes[2] = 54; | |
midiNotes[3] = 57; | |
midiNotes[4] = 62; | |
midiNotes[5] = 66; | |
} else if (touch.getTouched(8) == 1) { | |
midiNotes[0] = 43; | |
midiNotes[1] = 47; | |
midiNotes[2] = 52; | |
midiNotes[3] = 55; | |
midiNotes[4] = 59; | |
midiNotes[5] = 64; | |
} else if (touch.getTouched(9) == 1) { | |
midiNotes[0] = 45; | |
midiNotes[1] = 48; | |
midiNotes[2] = 53; | |
midiNotes[3] = 57; | |
midiNotes[4] = 60; | |
midiNotes[5] = 65; | |
} else if (touch.getTouched(10) == 1) { | |
midiNotes[0] = 47; | |
midiNotes[1] = 50; | |
midiNotes[2] = 55; | |
midiNotes[3] = 59; | |
midiNotes[4] = 62; | |
midiNotes[5] = 67; | |
} else if (touch.getTouched(11) == 1) { | |
midiNotes[0] = 45; | |
midiNotes[1] = 48; | |
midiNotes[2] = 52; | |
midiNotes[3] = 57; | |
midiNotes[4] = 60; | |
midiNotes[5] = 64; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment