// name: Analog Read
// purpose: to show how analog input works using codes
// commentary: Part 2 of Lab_5
// author: Karl Edward Sarmiento
// ID#: 101143058
// ip/domain: MIT
int analog_in = A5; // potientiometer voltage adjuster
int val = 0; // to acquire the reading of adc from analog input
int interval = 100; // the delay value given to the interval
int button_value;
int button_pin = 7;
void
setup()
{
Serial.begin(9600);
pinMode(button_pin, INPUT_PULLUP);
pinMode(23, OUTPUT); // buzzer
}
void
loop()
{
button_value = digitalRead(button_pin);
if (button_value == 0)
{
val = analogRead(analog_in);
val = map(val, 0, 1023, 100, 1000); // scale values
tone(23, val); // starts the tone
delay (interval); // shows the frequency number for 100 milliseconds
Serial.println(val); // prints the frequency
}
else {
noTone(23); // stops the tone
}
}