int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int buzzerPin=8;
int keyPin = 9;
int frequency, oldfrequency = 0;


boolean isOn = false;

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
  pinMode(keyPin, INPUT);  
}

void loop() {
  if (!digitalRead(keyPin)) {
    // read the value from the sensor:
    
    sensorValue = 0;
    for (int i=0; i<=9; i++) {
      sensorValue += analogRead(sensorPin);    
    }
    frequency=(sensorValue/10) * 5 + 220;
    if (frequency != oldfrequency) {
      tone(buzzerPin, frequency); 
      oldfrequency = frequency;
    } 
  } else {
    noTone(buzzerPin);
    oldfrequency=0;
  } 
}
project/arduino-kickstarter-wheewhee.txt · Zuletzt geändert: 14.01.2013 15:56 von 127.0.0.1
Falls nicht anders bezeichnet, ist der Inhalt dieses Wikis unter der folgenden Lizenz veröffentlicht: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Driven by DokuWiki