Created
October 4, 2018 15:09
-
-
Save natendaben/ae5c11b6db16403c810557e813fb97c1 to your computer and use it in GitHub Desktop.
Lab 3 Pt. 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int light = 0; | |
float frequency = 0; | |
void setup() { | |
// init serial comm | |
Serial.begin(9600); | |
pinMode(8, OUTPUT); | |
pinMode(A0, INPUT); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//set light to be the input from light sensor | |
light = analogRead(A0); | |
//print out light value | |
Serial.println(light); | |
//map the light sensor values to a frequency value between 100 and 1000 | |
frequency = map(light, 100, 600, 100, 1000); | |
//use the tone function to output values to the speaker | |
tone(8, frequency); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment