Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. //declaring used pins
  2. int speaker = 8;
  3. int photo = A0;
  4. // declaring a float variable for the frequency value
  5. float freq;
  6.  
  7. void setup() {
  8. // initialize serial communications
  9. Serial.begin(9600);
  10. pinMode(speaker, OUTPUT);
  11. }
  12.  
  13. void loop(){
  14. // read the analog input on A0
  15. //set sensorReading to this value
  16. int photoVal = analogRead(photo);
  17. // map sensor reading to an output between 100 and 1000
  18. freq = map(photoVal, 0, 1023, 100, 1000);
  19. // print it to the serial monitor
  20. analogWrite(speaker, freq);
  21. //change the pitch, play for 100ms
  22. tone(speaker, freq, 100);
  23. //printing photoVal
  24. Serial.print("Photoresistor Value: ");
  25. Serial.println(photoVal);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement