Lab 5: Pressure simon

Attached potentiometer to speaker, adding an LED, and a pressure sensitive LED as a rudimentary game of simon.

 

Joe

 

Here is the code:

 

/* Theremin
 * --------
 *
 *
 * Created 24 October 2006
 * copyleft 2006 Tod E. Kurt <tod@todbot.com
 * http://todbot.com/
 */
 
int potPin = 2;    // select the input pin for the potentiometer
int speakerPin = 7;
int sensorPin = 0;  // select the input pin for the sensor
int ledPin = 10; 
 
int val = 0;
int wal = 0;
 
void setup() {
  pinMode(11, OUTPUT); 
   pinMode(10, OUTPUT); 
     pinMode(9, OUTPUT); 
  pinMode(speakerPin, OUTPUT); 
  Serial.begin(9600);
  Serial.println("ready");
}
 
void loop() {
  digitalWrite(speakerPin, LOW);
   val = analogRead(potPin);    // read value from the sensor
   wal = analogRead(sensorPin); // read the value from the sensor, 0-1023
   
 
  
  for( int i=0; i<100; i++ ) {  // play it for 50 cycles
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(val);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(val);
  }
 
   analogWrite(ledPin, wal/5);  // analogWrite (dimming the LED) can be between 0-255
   Serial.println(wal/5);       // writing the value to the PC via serial connection
  
  digitalWrite(11, HIGH);   // set the LED on
  delay(val);              // wait for a second
  digitalWrite(11, LOW);    // set the LED off
  delay(val);              // wait for a second
     
if (val = wal)
{
  digitalWrite(9, LOW);// turn off led
}
else
{
  digitalWrite(9, HIGH); // turn on led
}
  
}
 
 
 
photo (2).JPG
0
Your rating: None