[Description]
- Control beat tempo and pitch with two potentiometers
- Use 3 LEDs to indicate different beat tempos
- Pause beat with FSR
[Components]
- Potentiometer X 2
- Piezo Speaker X 1
- LED X 3 (r, g, b)
- FSR X 1
- Resistor X 4
[Arduino Code]
int sensorPin = 0; // select the input pin for the sensor
int fsrVal = 0; // variable to store the value coming from fsr
int pot1Pin = 1; // select the input pin for the potentiometer 1
int pot2Pin = 2; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 9; // select the pin for the LED 1
int led2Pin = 10; // select the pin for the LED 2
int led3Pin = 11; // select the pin for the LED 3
int speakerPin = 7; // select the pin for speaker
int beat = 200; // set the initial beat tempo
int alt = 1; // alternate pitch for duotone
void setup() {
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(speakerPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}
void loop() {
pot1Val = analogRead(pot1Pin);
pot2Val = analogRead(pot2Pin);
fsrVal = analogRead(sensorPin); // read the value from the sensor, 0-1023
// Serial.println(pot1Val);
// Serial.println(pot2Val);
digitalWrite(speakerPin, LOW);
if (pot1Val < 342) {
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, LOW);
beat = 10;
}
else if ((pot1Val >= 342) && (pot1Val < 684)) {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
digitalWrite(led3Pin, LOW);
beat = 100;
}
else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, HIGH);
beat = 200;
}
if (fsrVal > 100) {
for( int i=0; i<beat; i++ ) {
if( alt >= 0 ) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(pot2Val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(pot2Val);
}
}
for( int i=0; i<beat; i++ ) {
digitalWrite(speakerPin, 0);
delayMicroseconds(pot2Val);
}
}
}
[Video]