Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Britney Beatey
- * 6/21/17
- */
- const int photoPin = A0;
- const int piezoPin = 8;
- int min = 40;
- int max = 1000;
- int photoVal = 0;
- unsigned long time;
- int minVal = 1000;
- int maxVal = 0;
- int timeVal = 0;
- void setup()
- {
- // put your setup code here, to run once:
- pinMode (photoPin, INPUT);
- pinMode (piezoPin, OUTPUT);
- Serial.begin(9600);
- while(millis() - timeVal < 5000)
- {
- photoVal = analogRead (photoPin);
- if (photoVal > max)
- {
- max = photoVal;
- }
- else if (photoVal < min)
- {
- min = photoVal;
- }
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- photoVal = analogRead (photoPin);
- photoVal = map(photoVal, min, max, 50, 560);
- tone(piezoPin, photoVal, 20);
- noTone (piezoPin);
- delay (100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement