Created
January 12, 2016 15:02
-
-
Save JHeld07/a9fd9c1f99f2d346346c to your computer and use it in GitHub Desktop.
Light Sensor
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 State=0; | |
void setup() { | |
pinMode(5,OUTPUT); // Set Digital pin 5 to output | |
} | |
void loop() { | |
int sensorValue = analogRead(A0); // Read analog value off of photoresistor | |
float voltage = sensorValue * (5.0 / 1023.0); // Calculate voltage with a resolution of 1023 | |
if(voltage<3){ //not recording | |
if (State==0){ | |
digitalWrite(5,HIGH); // Toggle record state | |
delay(50); | |
digitalWrite(5,LOW); | |
State=1; | |
} | |
} | |
if (voltage>3){ // recording | |
if (State==1){ | |
digitalWrite(5,HIGH); // Toggle record state | |
delay(50); | |
digitalWrite(5,LOW); | |
State=0; | |
} | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment