/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().

The circuit:
* Potentiometer attached to analog input 0
* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V
* LED anode (long leg) attached to digital output 13
* LED cathode (short leg) attached to ground

* Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.

Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe

This example code is in the public domain.
http://arduino.cc/en/Tutorial/AnalogInput

modified 16 July 2016
by Jody Culkin and Eric Hagan
*/
int sensorPin = A0; // select the input pin for the potentiometer
int photoPin = A1; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue1 = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0;

void setup() {
// declare the ledPin as an OUTPUT:
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    sensorValue1 = analogRead(sensorPin);
    sensorValue2 = analogRead(photoPin);
    Serial.println(sensorValue2);
    if (sensorValue2 < 200){
        tone(11, 440, 500);
    }
    else if (sensorValue2 < 400){
        tone(11, 523, 500);
    }
    else if (sensorValue2 < 800){
        tone(11, 196, 500);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>