Created
March 3, 2014 00:55
-
-
Save LucyMatch/9316628 to your computer and use it in GitHub Desktop.
RGBeatz Sketch - Arduino Piezo RGB Led Disco Box
This file contains 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
int soundSensor1 = 0; // piezo 1 connect to analog 0 | |
int soundSensor2 = 1; // piezo 2 connect to analog 1 | |
int threshold = 20; | |
int sensorReading1 = 0; //var to hold anaolg reading of piezo1 | |
int sensorReading2 = 0; //var to hold anaolg reading of piezo2 | |
//first LED pins// | |
int LED1R = 3; | |
int LED1G = 5; | |
int LED1B = 6; | |
//second LED pins// | |
int LED2R = 9; | |
int LED2G = 10; | |
int LED2B = 11; | |
//static LED// | |
int red1 = 2; | |
int blue1 = 4; | |
int red2 = 12; | |
int blue2 = 13; | |
int read1 = 0; | |
int read2 = 0; | |
void setup(){ | |
Serial.begin(9600); //set serial output | |
pinMode(LED1R, OUTPUT); //set pins for first LED | |
pinMode(LED1G, OUTPUT); | |
pinMode(LED1B, OUTPUT); | |
pinMode(LED2R, OUTPUT); //set pins for second LED | |
pinMode(LED2G, OUTPUT); | |
pinMode(LED2B, OUTPUT); | |
pinMode(red1,OUTPUT); //set Red & Blue pins for third LED | |
pinMode(blue1,OUTPUT); | |
pinMode(red2,OUTPUT); //set Red * Blue pins for fouth LED | |
pinMode(blue2,OUTPUT); | |
} | |
void loop(){ | |
sensorReading1 = analogRead(soundSensor1); //reading in piezo sensors 1 & 2 | |
sensorReading2 = analogRead(soundSensor2); | |
// Serial.println("one"); | |
// Serial.println(sensorReading1); | |
// Serial.println("two"); | |
// Serial.println(sensorReading2); | |
read1 = map(sensorReading1,0,10,255,0); //map analog input to RGB scale | |
read2 = map(sensorReading2,0,10,255,0); | |
analogWrite(LED1R, read1); //for middle two LEDs scale Red & Blue to sensor input | |
analogWrite(LED1G, 100); | |
analogWrite(LED1B, read2); | |
analogWrite(LED2R, read1); | |
analogWrite(LED2G, 100); | |
analogWrite(LED2B, read2); | |
//four outter two LEDs change from red to Blue at volume threshold | |
if(sensorReading1 > threshold){ | |
digitalWrite(red1,LOW); | |
digitalWrite(blue1,HIGH); | |
digitalWrite(red2,HIGH); | |
digitalWrite(blue2,LOW); | |
} | |
else{ | |
digitalWrite(red1,HIGH); | |
digitalWrite(blue1,LOW); | |
digitalWrite(red2,LOW); | |
digitalWrite(blue2,HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!