Advertisement
goncharn20

Untitled

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