Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <toneAC.h>
- const int piezo=9;
- const int ledPin= 13;
- const int photoPin= A0;
- int readVal;
- int minSense= 1000;
- int maxSense= 0;
- unsigned long myTime;
- void setup() {
- // put your setup code here, to run once:
- pinMode (piezo, OUTPUT);
- pinMode (photoPin, INPUT);
- Serial.begin (9600);
- calibrate ();
- }
- void calibrate()
- {
- digitalWrite (ledPin, HIGH);
- delay (30);
- digitalWrite (ledPin, LOW);
- myTime= millis();
- while( millis () - myTime < 5000)
- {
- readVal= analogRead (photoPin);
- if (readVal > maxSense)
- {
- maxSense= readVal;
- }
- if (readVal< minSense)
- {
- minSense= readVal;
- }
- }
- Serial. print(" Max Value ");
- Serial. print (maxSense);
- Serial. print (" Min Value = ");
- Serial. println (minSense);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int readVal= analogRead (photoPin);
- readVal= map (readVal, minSense, maxSense, 40, 4000);
- readVal= constrain (readVal, 40, 4000);
- tone (piezo, readVal, 20);
- delay (10);
- noTone (piezo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement