• tumblr
  • youtube
  • mail

Pot Singer

 


//create variables for pins
const int buttonPin = 2;
const int ledPin = 12;
const int fadeLed = 11;
const int potPin = 0;
const int lightPin = 1;
//timecode
unsigned long previousMillis = 0;
const long interval = 10;
// LED fading variables
boolean fadeUp = true;
int fadeLevel = 0;
//LED blinking variables
int ledState = LOW;
//button variables
int buttonState = 0;
boolean pressed = false;
//analog sensor variables
int lightVar = 0;
int potVar = 0;
void setup() {
// set up pins
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(fadeLed, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && pressed == false ) { //if it is pressed now but was not pressed last loop
delay(5);
// Serial.println("BANG!");
// toggle lED:
if (ledState == LOW) {
ledState = HIGH;
}
else {
ledState = LOW;
}
pressed = true; //change this so we know the button was pressed
}
if (buttonState == LOW && pressed == true ) { //if the button is no longer pressed but was pressed last loop
delay(5);
pressed = false; //change this so we know it is no longer pressed
}
unsigned long currentMillis = millis();
//check sensors
potVar = analogRead(potPin);
lightVar = analogRead(lightPin);
//logic
if (lightVar <= potVar ){
fadeUp = true;
}
else {
fadeUp = false;}
//write to the LED pins
if (currentMillis – previousMillis >= interval) {
previousMillis = currentMillis;
if (fadeUp == true ) {
if (fadeLevel != 255) fadeLevel++;
} else {
if (fadeLevel != 0) fadeLevel –;
}
}
//Serial.println(fadeLevel/4);
digitalWrite(ledPin, ledState);
analogWrite(fadeLed,fadeLevel);
Serial.println(lightVar);
int sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the analog input range (in this case, 400 – 1000 from the photoresistor)
// to the output pitch range (120 – 1500Hz)
// change the minimum and maximum input numbers below
// depending on the range your sensor's giving:
int thisPitch = map(sensorReading, 400, 700, 620, 800);
// play the pitch:
tone(9, thisPitch, 1000);
delay(1); // delay in between reads for stability
}

http://portfolio.newschool.edu/remia021/files/2015/09/IMG_1946-swg08k.mov

Leave a reply

Skip to toolbar