Last active
August 29, 2015 13:56
-
-
Save arielchuri/8942579 to your computer and use it in GitHub Desktop.
Code for testing your 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 ledPins[] = { | |
11, 10, 9, 6, 5, 3 }; | |
int pinCount = 6; | |
int lightPin = A0; // A variable for which pin has the light sensor. | |
int lightValue = 0; // A variable to keep track of the value we get from the light sensor. | |
int aLED = 13; | |
boolean aLEDstate; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(aLED, OUTPUT); | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
pinMode(ledPins[thisPin], OUTPUT); | |
} | |
startUp(); //I put the LED test into a function that runs every time the Arduino starts up. | |
} | |
//===============LOOP================// | |
void loop() { | |
lightValue = analogRead(lightPin); //Read the light sensor and store the value. | |
monitor(); | |
} | |
//==============ENDLOOP==============// | |
void startUp() { //This code will run once at start up. | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
digitalWrite(ledPins[thisPin], HIGH); | |
delay(30); | |
digitalWrite(ledPins[thisPin], LOW); | |
} | |
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { | |
digitalWrite(ledPins[thisPin], HIGH); | |
delay(30); | |
digitalWrite(ledPins[thisPin], LOW); | |
} | |
} | |
void monitor() { //This code will run at the bottom of every loop. | |
Serial.print("light = "); | |
Serial.println(lightValue); | |
digitalWrite(aLED, aLEDstate); | |
aLEDstate = !aLEDstate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment