Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sensorValue;
- int sensorLow = 1023;
- int sensorHigh = 0;
- const int ledPin = 13;
- const int photoR = A1;
- const int piezo1 = 8;
- void setup()
- {
- pinMode(ledPin,OUTPUT);
- digitalWrite(ledPin, HIGH);
- while(millis() < 5000)
- {
- sensorValue = analogRead(photoR);
- if (sensorValue > sensorHigh)
- {
- sensorHigh = sensorValue;
- }
- if (sensorValue < sensorLow)
- {
- sensorLow = sensorValue;
- }
- }
- digitalWrite(ledPin,LOW);
- }
- void loop()
- {
- sensorValue = analogRead(photoR);
- int pitch = map(sensorValue, sensorLow, sensorHigh,50, 4000);
- tone(piezo1,pitch,20);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment