Advertisement
gilmaster63

Project 06: Light Theremin

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