Lorenzo1818

Sketch - Project 6 Starter kit modified V1(non funziona)

Apr 8th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. int sensorValue;
  2. int sensorLow = 1023;
  3. int sensorHigh = 0;
  4.  
  5. const int ledPin = 13;
  6. const int buttonPin = 2;
  7.  
  8. int run = 0;
  9.  
  10. void setup(){
  11.   pinMode(ledPin, OUTPUT);
  12.   digitalWrite(ledPin, HIGH);
  13.  
  14.   while (millis() < 5000) {
  15.     sensorValue = analogRead(A0);
  16.    
  17.     if (sensorValue > sensorHigh) {
  18.       sensorHigh = sensorValue;
  19.     }
  20.     if (sensorValue < sensorLow) {
  21.       sensorLow = sensorValue;
  22.     }
  23.   }
  24.  
  25.   digitalWrite(ledPin, LOW);
  26. }
  27.  
  28. void loop() {
  29.   if (digitalRead(buttonPin)) {
  30.       if (run == 0){run = 1;}
  31.       else {run = 0;}
  32.   }
  33.   if (run){
  34.     sensorValue = analogRead(A0);
  35.  
  36.     int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
  37.     tone(8, pitch, 20);
  38.  
  39.     delay(10);
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment