Skip to content

Instantly share code, notes, and snippets.

@natendaben
Created October 4, 2018 15:09
Show Gist options
  • Save natendaben/ae5c11b6db16403c810557e813fb97c1 to your computer and use it in GitHub Desktop.
Save natendaben/ae5c11b6db16403c810557e813fb97c1 to your computer and use it in GitHub Desktop.
Lab 3 Pt. 2
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