#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, 6, NEO_RGB + NEO_KHZ800);
#include "pitches.h"
const int SOFT_POT_PIN = A0; // Pin connected to softpot wiper
const int VERT = A1; // y thumbstick
const int HORIZ = A2; // x thumbstick
const int constON = A4;
const int constON1 = A5;
const int SEL =11; // digital
const int RED_PIN = 7; // Red LED Pin Buzzer
const int GREEN_PIN = 5; // Green LED Pin Buzzer
const int BLUE_PIN = 9; // Blue LED Pin Buzzer
const int buzzerPin = 8;
const int GRAPH_LENGTH = 40; // Length of line graph
int tempRed = 0;
int tempGreen = 0;
int tempBlue = 0;
int wait = 250;
void setup()
{
Serial.begin(9600);
pinMode(SOFT_POT_PIN, INPUT);
pinMode(constON, OUTPUT);
pinMode(constON1, OUTPUT);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(SEL,INPUT);
digitalWrite(SEL,HIGH);
digitalWrite(constON, HIGH);
digitalWrite(constON1, HIGH);
strip.begin();
strip.show();
pcr();
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_G4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
strip.setPixelColor(0, 170, 80, 10);
strip.setPixelColor(1, 170, 80, 10);
strip.setPixelColor(2, 170, 80, 10);
strip.setPixelColor(3, 170, 80, 10);
strip.setPixelColor(4, 170, 80, 10);
strip.show();
tone(8, NOTE_A4);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 120, 0, 200);
strip.setPixelColor(1, 120, 0, 200);
strip.setPixelColor(2, 120, 0, 200);
strip.setPixelColor(3, 120, 0, 200);
strip.setPixelColor(4, 120, 0, 200);
strip.show();
tone(8, NOTE_F4);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 128, 120, 0);
strip.setPixelColor(1, 128, 120, 0);
strip.setPixelColor(2, 128, 120, 0);
strip.setPixelColor(3, 128, 120, 0);
strip.setPixelColor(4, 128, 120, 0);
strip.show();
tone(8, NOTE_F3);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 140, 180, 180);
strip.setPixelColor(1, 140, 180, 180);
strip.setPixelColor(2, 140, 180, 180);
strip.setPixelColor(3, 140, 180, 180);
strip.setPixelColor(4, 140, 180, 180);
strip.show();
tone(8, NOTE_C4);
delay(wait);
noTone(8);
pcr();
}
void loop()
{
// Read in the soft pot's ADC value
int softPotADC = analogRead(SOFT_POT_PIN);
int mapSoftPotADC = map(softPotADC, 1, 690, 0, 127);
// Map the 0-1023 value to 0-40
int softPotPosition = map(softPotADC, 1, 690, 0, GRAPH_LENGTH);
// Print a line graph:
Serial.print("<"); // Starting end
for (int i=0; i<GRAPH_LENGTH; i++)
{
if (i == softPotPosition) Serial.print("|");
else Serial.print("-");
}
Serial.print("> (" + String(softPotADC) + ") map: " + mapSoftPotADC);
decideColor(softPotADC);
setColor();
int vertical = analogRead(VERT); // will be 0-1023
int horizontal = analogRead(HORIZ); // will be 0-1023
int select = digitalRead(SEL); // will be HIGH (1) if not pressed, and LOW (0) if pressed
decideIfTune(horizontal, vertical, select);
Serial.print(" vertical: ");
Serial.print(vertical,DEC);
Serial.print(" horizontal: ");
Serial.print(horizontal,DEC);
Serial.print(" select: ");
if(select == HIGH)
Serial.println("not pressed");
else
Serial.println("PRESSED!");
int toneSound = map(softPotADC, 1, 690, 100, 650);
if(softPotADC <= 15){
noTone(buzzerPin);
delay(50);
}
else{
tone(buzzerPin, toneSound);
delay(50);
}
}
void decideColor(int softPot){
if(softPot <= 15){
tempRed = 0;
tempGreen = 0;
tempBlue = 0;
}
else if (softPot < 230) // Lowest third of the potentiometer's range (0-340)
{
tempRed = 256 - map(softPot, 1, 230, 0, 256); // Red from full to off
tempGreen = map(softPot, 1, 230, 0, 256); // Green from off to full
tempBlue = 1; // Blue off
}
else if (softPot < 460) // Middle third of potentiometer's range (341-681)
{
tempRed = 1; // Red off
tempGreen = 256 - map(softPot, 231, 460, 0, 256); // Green from full to off
tempBlue = map(softPot, 231, 460, 0, 256); // Blue from off to full
}
else // Upper third of potentiometer"s range (682-1023)
{
tempRed = map(softPot, 461, 690, 0, 256); // Red from off to full
tempGreen = 1; // Green off
tempBlue = 256 - map(softPot, 461, 690, 0, 256); // Blue from full to off
}
}
void setColor() {
analogWrite(RED_PIN, tempRed);
analogWrite(GREEN_PIN, tempGreen);
analogWrite(BLUE_PIN, tempBlue);
}
void decideIfTune(int h, int v, int p){
if(p == LOW){
strip.begin();
strip.show();
pcr();
strip.setPixelColor(0, 100, 100, 100);
strip.setPixelColor(1, 100, 100, 100);
strip.setPixelColor(2, 100, 100, 100);
strip.setPixelColor(3, 100, 100, 100);
strip.setPixelColor(4, 100, 100, 100);
strip.show();
tone(8, NOTE_A4); // this starts the tone
delay(125);
noTone(8);
delay(75);
tone(8, NOTE_G3); // this starts the tone
delay(75);
noTone(8);
delay(75);
tone(8, NOTE_G3); // this starts the tone
delay(75);
noTone(8);
delay(75);
tone(8, NOTE_A4); // this starts the tone
delay(125);
noTone(8);
delay(75);
tone(8, NOTE_G3); // this starts the tone
delay(125);
noTone(8);
delay(500);
tone(8, NOTE_B4); // this starts the tone
delay(125);
noTone(8);
delay(75);
tone(8, NOTE_C5); // this starts the tone
delay(250);
noTone(8);
delay(500);
pcr();
}
else if(h <= 100){
tune0();
}
else if(v >= 800){
tune1();
}
else if(h >= 800){
tune2();
}
else if(v <= 100){
tune3();
}
return;
}
void tune0(){
strip.begin();
strip.show();
// We initalize the NeoPixel Library here, by starting it and then sending the first strip.show() command.
// Next we will tell all of the LEDs to switch off before continuing.
pcr(); // PixelColorsReset function, it turns all of the LEDs completely off.
// This custom function can be found at the bottom of this Sketch.
//E
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//C
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_C4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 100, 0, 0);
strip.setPixelColor(2, 100, 0, 0);
strip.setPixelColor(3, 100, 0, 0);
strip.setPixelColor(4, 100, 0, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
delay(250);
}
void tune1(){
strip.begin();
strip.show();
// We initalize the NeoPixel Library here, by starting it and then sending the first strip.show() command.
// Next we will tell all of the LEDs to switch off before continuing.
pcr(); // PixelColorsReset function, it turns all of the LEDs completely off.
// This custom function can be found at the bottom of this Sketch.
// We play the melody once during setup with all 5 LEDs lighting up in the color for the tone being played.
//D
strip.setPixelColor(0, 100, 100, 0);
strip.setPixelColor(1, 100, 100, 0);
strip.setPixelColor(2, 100, 100, 0);
strip.setPixelColor(3, 100, 100, 0);
strip.setPixelColor(4, 100, 100, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 100, 100, 0);
strip.setPixelColor(1, 100, 100, 0);
strip.setPixelColor(2, 100, 100, 0);
strip.setPixelColor(3, 100, 100, 0);
strip.setPixelColor(4, 100, 100, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 100, 100, 0);
strip.setPixelColor(1, 100, 100, 0);
strip.setPixelColor(2, 100, 100, 0);
strip.setPixelColor(3, 100, 100, 0);
strip.setPixelColor(4, 100, 100, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
delay(250);
//E
strip.setPixelColor(0, 100, 100, 0);
strip.setPixelColor(1, 100, 100, 0);
strip.setPixelColor(2, 100, 100, 0);
strip.setPixelColor(3, 100, 100, 0);
strip.setPixelColor(4, 100, 100, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//G
strip.setPixelColor(0, 100, 100, 0);
strip.setPixelColor(1, 100, 100, 0);
strip.setPixelColor(2, 100, 100, 0);
strip.setPixelColor(3, 100, 100, 0);
strip.setPixelColor(4, 100, 100, 0);
strip.show();
tone(8, NOTE_G4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//G
strip.setPixelColor(0, 100, 100, 0);
strip.setPixelColor(1, 100, 100, 0);
strip.setPixelColor(2, 100, 100, 0);
strip.setPixelColor(3, 100, 100, 0);
strip.setPixelColor(4, 100, 100, 0);
strip.show();
tone(8, NOTE_G4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
delay(250);
}
void tune2(){
strip.begin();
strip.show();
// We initalize the NeoPixel Library here, by starting it and then sending the first strip.show() command.
// Next we will tell all of the LEDs to switch off before continuing.
pcr(); // PixelColorsReset function, it turns all of the LEDs completely off.
// This custom function can be found at the bottom of this Sketch.
// We play the melody once during setup with all 5 LEDs lighting up in the color for the tone being played.
//E
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//C
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_C4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 0, 100, 0);
strip.setPixelColor(1, 0, 100, 0);
strip.setPixelColor(2, 0, 100, 0);
strip.setPixelColor(3, 0, 100, 0);
strip.setPixelColor(4, 0, 100, 0);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
}
void tune3(){
strip.begin();
strip.show();
// We initalize the NeoPixel Library here, by starting it and then sending the first strip.show() command.
// Next we will tell all of the LEDs to switch off before continuing.
pcr(); // PixelColorsReset function, it turns all of the LEDs completely off.
// This custom function can be found at the bottom of this Sketch.
// We play the melody once during setup with all 5 LEDs lighting up in the color for the tone being played.
//E
strip.setPixelColor(0, 0, 0, 100);
strip.setPixelColor(1, 0, 0, 100);
strip.setPixelColor(2, 0, 0, 100);
strip.setPixelColor(3, 0, 0, 100);
strip.setPixelColor(4, 0, 0, 100);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 0, 0, 100);
strip.setPixelColor(1, 0, 0, 100);
strip.setPixelColor(2, 0, 0, 100);
strip.setPixelColor(3, 0, 0, 100);
strip.setPixelColor(4, 0, 0, 100);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 0, 0, 100);
strip.setPixelColor(1, 0, 0, 100);
strip.setPixelColor(2, 0, 0, 100);
strip.setPixelColor(3, 0, 0, 100);
strip.setPixelColor(4, 0, 0, 100);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//E
strip.setPixelColor(0, 0, 0, 100);
strip.setPixelColor(1, 0, 0, 100);
strip.setPixelColor(2, 0, 0, 100);
strip.setPixelColor(3, 0, 0, 100);
strip.setPixelColor(4, 0, 0, 100);
strip.show();
tone(8, NOTE_E4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//D
strip.setPixelColor(0, 0, 0, 100);
strip.setPixelColor(1, 0, 0, 100);
strip.setPixelColor(2, 0, 0, 100);
strip.setPixelColor(3, 0, 0, 100);
strip.setPixelColor(4, 0, 0, 100);
strip.show();
tone(8, NOTE_D4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
//C
strip.setPixelColor(0, 0, 0, 100);
strip.setPixelColor(1, 0, 0, 100);
strip.setPixelColor(2, 0, 0, 100);
strip.setPixelColor(3, 0, 0, 100);
strip.setPixelColor(4, 0, 0, 100);
strip.show();
tone(8, NOTE_C4); // this starts the tone
delay(wait);
noTone(8); // this stops the tone
pcr();
delay(wait/10);
}
void pcr() {
// This function turns all the LEDs off, reseting them.
// I wrote this function to overcome the only real shortcomming I saw in the Adafruit Library, a reset command.
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
return;
}
void notes() {
// This function plays the melody, lighting up only the LED that corresponds to the tone played.
pcr();
strip.setPixelColor(0, 100, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
tone(8, NOTE_G4);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 170, 80, 10);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
tone(8, NOTE_A4);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 120, 0, 200);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
tone(8, NOTE_F4);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 128, 120, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
tone(8, NOTE_F3);
delay(wait);
noTone(8);
pcr();
delay(wait/10);
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 140, 180, 180);
strip.show();
tone(8, NOTE_C4);
delay(wait);
noTone(8);
pcr();
return;
}
Comments
Please log in or sign up to comment.