Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. const int sound = 8;
  2. const int photoPin = A0;
  3. int readVal;
  4. int minSense = 1000;
  5. int maxSense = 0;
  6. unsigned long myTime;
  7. void setup() {
  8. // put your setup code here, to run once:
  9. pinMode (photoPin, INPUT);
  10. pinMode (sound, OUTPUT);
  11. Serial.begin (9600);
  12. calibrate ();
  13.  
  14.  
  15. }
  16.  
  17. void calibrate ()
  18. {
  19. myTime = millis ();
  20. while (millis() - myTime < 5000)
  21. {
  22.  
  23. readVal = analogRead (photoPin);
  24. if (readVal > maxSense)
  25. {
  26. maxSense = readVal;
  27.  
  28. }
  29. if (readVal < minSense)
  30. {
  31. minSense = readVal;
  32. }
  33. }
  34. Serial.print (" max Value ");
  35. Serial.print (maxSense);
  36. Serial.print ("min Value ");
  37. Serial.print (minSense);
  38.  
  39.  
  40. }
  41.  
  42. void loop()
  43. {
  44. readVal = analogRead(photoPin);
  45. readVal = map(readVal, minSense, maxSense, 40, 4000);
  46. readVal = constrain(readVal, 4000, 40);
  47. tone (sound, readVal, 20);
  48. delay (10);
  49. noTone (sound);
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement