Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //declaring used pins
- int speaker = 8;
- int photo = A0;
- // declaring a float variable for the frequency value
- float freq;
- void setup() {
- // initialize serial communications
- Serial.begin(9600);
- pinMode(speaker, OUTPUT);
- }
- void loop(){
- // read the analog input on A0
- //set sensorReading to this value
- int photoVal = analogRead(photo);
- // map sensor reading to an output between 100 and 1000
- freq = map(photoVal, 0, 1023, 100, 1000);
- // print it to the serial monitor
- analogWrite(speaker, freq);
- //change the pitch, play for 100ms
- tone(speaker, freq, 100);
- //printing photoVal
- Serial.print("Photoresistor Value: ");
- Serial.println(photoVal);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement