#include "cocotouch.h"
#include <Adafruit_NeoPixel.h>
#define PIN 2 //The signal pin connected with Arduino
#define LED_COUNT 16 // the amount of the leds of your strip
char itemIndex;
uint8_t idx;
uint8_t midiNotes[6];
uint8_t states[6];
CocoTouch touch;
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
if (!touch.begin()) { while(1){;} }
touch.setMIDIProgram(26, 1);
leds.begin(); // Call this to start up the LED strip.
clearLEDs(); // This function, defined below, turns all LEDs off...
leds.show(); // ...but the LEDs don't actually update until you call this.
}
void loop() {
for (idx = 6; idx <= 11; idx++) {
itemIndex = idx - 6;
if (states[itemIndex] == 0 && touch.getTouched(idx) == 1) {
touch.playMIDINote(midiNotes[itemIndex], 100, 1);
states[itemIndex] = 1;
} else if (states[itemIndex] == 1 && touch.getTouched(idx) < 1) {
states[itemIndex] = 0;
}
}
if (touch.getTouched(0) == 1) {
midiNotes[0] = 43;
midiNotes[1] = 48;
midiNotes[2] = 52;
midiNotes[3] = 55;
midiNotes[4] = 60;
midiNotes[5] = 64;
for (int i=0; i<LED_COUNT; i++)
{
rainbow(i);
delay(10); // Delay between rainbow slides
}
} else if (touch.getTouched(1) == 1) {
midiNotes[0] = 45;
midiNotes[1] = 50;
midiNotes[2] = 54;
midiNotes[3] = 57;
midiNotes[4] = 62;
midiNotes[5] = 66;
for (int i=0; i<LED_COUNT; i++)
{
rainbow(i);
delay(10); // Delay between rainbow slides
}
} else if (touch.getTouched(2) == 1) {
midiNotes[0] = 43;
midiNotes[1] = 47;
midiNotes[2] = 52;
midiNotes[3] = 55;
midiNotes[4] = 59;
midiNotes[5] = 64;
for (int i=0; i<LED_COUNT; i++)
{
rainbow(i);
delay(10); // Delay between rainbow slides
}
} else if (touch.getTouched(3) == 1) {
midiNotes[0] = 45;
midiNotes[1] = 48;
midiNotes[2] = 53;
midiNotes[3] = 57;
midiNotes[4] = 60;
midiNotes[5] = 65;
for (int i=0; i<LED_COUNT; i++)
{
rainbow(i);
delay(10); // Delay between rainbow slides
}
} else if (touch.getTouched(4) == 1) {
midiNotes[0] = 47;
midiNotes[1] = 50;
midiNotes[2] = 55;
midiNotes[3] = 59;
midiNotes[4] = 62;
midiNotes[5] = 67;
for (int i=0; i<LED_COUNT; i++)
{
rainbow(i);
delay(10); // Delay between rainbow slides
}
} else if (touch.getTouched(5) == 1) {
midiNotes[0] = 45;
midiNotes[1] = 48;
midiNotes[2] = 52;
midiNotes[3] = 57;
midiNotes[4] = 60;
midiNotes[5] = 64;
for (int i=0; i<LED_COUNT; i++)
{
rainbow(i);
delay(10); // Delay between rainbow slides
}
} else {
leds.begin(); // Call this to start up the LED strip.
clearLEDs(); // This function, defined below, turns all LEDs off...
leds.show(); // ...but the LEDs don't actually update until you call this.
}
}
void clearLEDs()
{
for (int i=0; i<LED_COUNT; i++)
{
leds.setPixelColor(i, 0);
}
}
// Prints a rainbow on the ENTIRE LED strip.
// The rainbow begins at a specified position.
// ROY G BIV!
void rainbow(byte startPosition)
{
// Need to scale our rainbow. We want a variety of colors, even if there
// are just 10 or so pixels.
int rainbowScale = 192 / LED_COUNT;
// Next we setup each pixel with the right color
for (int i=0; i<LED_COUNT; i++)
{
// There are 192 total colors we can get out of the rainbowOrder function.
// It'll return a color between red->orange->green->...->violet for 0-191.
leds.setPixelColor(i, rainbowOrder((rainbowScale * (i + startPosition)) % 192));
}
// Finally, actually turn the LEDs on:
leds.show();
}
// Input a value 0 to 191 to get a color value.
// The colors are a transition red->yellow->green->aqua->blue->fuchsia->red...
// Adapted from Wheel function in the Adafruit_NeoPixel library example sketch
uint32_t rainbowOrder(byte position)
{
// 6 total zones of color change:
if (position < 31) // Red -> Yellow (Red = FF, blue = 0, green goes 00-FF)
{
return leds.Color(0xFF, position * 8, 0);
}
else if (position < 63) // Yellow -> Green (Green = FF, blue = 0, red goes FF->00)
{
position -= 31;
return leds.Color(0xFF - position * 8, 0xFF, 0);
}
else if (position < 95) // Green->Aqua (Green = FF, red = 0, blue goes 00->FF)
{
position -= 63;
return leds.Color(0, 0xFF, position * 8);
}
else if (position < 127) // Aqua->Blue (Blue = FF, red = 0, green goes FF->00)
{
position -= 95;
return leds.Color(0, 0xFF - position * 8, 0xFF);
}
else if (position < 159) // Blue->Fuchsia (Blue = FF, green = 0, red goes 00->FF)
{
position -= 127;
return leds.Color(position * 8, 0, 0xFF);
}
else //160 <position< 191 Fuchsia->Red (Red = FF, green = 0, blue goes FF->00)
{
position -= 159;
return leds.Color(0xFF, 0x00, 0xFF - position * 8);
}
}
|