Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Light Sensor code for the Emerging Objects class.
//Light Sensor Code
int led = 13;
int led2 = 11;
byte fade;
long timer;
long previousTimer;
int ledState = LOW;
int sensorPin = A0;
int sensorValue = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
sensorValue = analogRead(sensorPin);
/*
if ( timer - previousTimer >= 20 ) {
ledState = !ledState;
previousTimer = timer;
Serial.println(" ");
Serial.println("********* CHANGE STATE!!! ***********");
Serial.println(" ");
}
*/
if ( sensorValue <= 400 ) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(led, ledState); // turn the LED on (HIGH is the voltage level)
analogWrite(led2, fade);
fade++;
// Serial.print("Blink # ");
timer++;
Serial.print("timer= ");
Serial.print(timer);
Serial.print("\t previousTimer= ") ;
Serial.print(previousTimer);
Serial.print("\t fade= ");
Serial.println(fade);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment