I was just messing around with one of the example sketches. (Graph)
I thought it turned out pretty cool, so I thought I'd throw it out there.
You'll need an analog input, 8 LEDs (with resistors), and a piezo speaker.
Here's the code:
void setup() {
for (int n=2; n<10; n++) {
pinMode(n, OUTPUT);
}
Serial.begin(9600);
}
void ledsOFF() {
for (int thisPin = 2; thisPin < 10; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
void loop() {
Serial.println(analogRead(A0));
int sensorReading = analogRead(A0);
int ledLevel = map(sensorReading, 0, 1023, 2, 9);
switch (ledLevel) {
case 2:
ledsOFF();
digitalWrite(2, HIGH);
break;
case 3:
ledsOFF();
digitalWrite(3, HIGH);
break;
case 4:
ledsOFF();
digitalWrite(4, HIGH);
break;
case 5:
ledsOFF();
digitalWrite(5, HIGH);
break;
case 6:
ledsOFF();
digitalWrite(6, HIGH);
break;
case 7:
ledsOFF();
digitalWrite(7, HIGH);
break;
case 8:
ledsOFF();
digitalWrite(8, HIGH);
break;
case 9:
ledsOFF();
digitalWrite(9, HIGH);
break;
default:
ledsOFF();
}
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
tone(10, thisPitch, 10);
delay(3);
}
/* Processing code
import processing.serial.*;
Serial myPort;
int xPos = 1;
int Rvalue = 255;
int Gvalue = 0;
int Bvalue = 0;
int CycleCount = 0;
void setup () {
size(1200, 900);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
if (CycleCount >= 0 && CycleCount < 255) {
Gvalue++;
}
if (CycleCount >= 255 && CycleCount < 511) {
Rvalue -= 1;
}
if (CycleCount >= 511 && CycleCount < 767) {
Bvalue++;
}
if (CycleCount >= 767 && CycleCount < 1023) {
Gvalue -= 1;
}
if (CycleCount >= 1023 && CycleCount < 1279) {
Rvalue++;
}
if (CycleCount >= 1279 && CycleCount < 1535) {
Bvalue -= 1;
}
stroke(Rvalue,Gvalue,Bvalue);
line(xPos, height, xPos, height - inByte);
}
if (xPos >= width) {
xPos = 0;
background(0);
CycleCount++;
if (CycleCount == 1536){
CycleCount = 0;
}
}
else {
xPos++;
CycleCount++;
if (CycleCount == 1536){
CycleCount = 0;
}
}
}
*/
Let me know what you think!
Enjoy!