Last active
February 17, 2018 10:04
-
-
Save MargenauMaker/282210f32299a392f0bc9288f4e88c8a to your computer and use it in GitHub Desktop.
Lilypad - light sensor with RGB
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
/* | |
LilyPad ProtoSnap Plus Activity 7: Sensing Light | |
SparkFun Electronics | |
modified by ringotron5000 | |
Modified by K Margenau | |
for LilyMini | |
16 Feb 2018 | |
darkness is low value, maybe 5 | |
light is higher , maybe 190 | |
so let's make threshold 100 | |
******************************************************************************/ | |
// Create variables for the pins we'll use: | |
int sensorPin = 1; | |
int redLED = 5; | |
int greenLED = 6; | |
int blueLED = 7; | |
void setup() | |
{ | |
// Initialize the sensor pin as an input, but without a pullup | |
// (Pullups are only used for switch inputs) | |
pinMode(sensorPin, INPUT); | |
// Initialize the output pins: | |
pinMode(redLED, OUTPUT); | |
pinMode(greenLED, OUTPUT); | |
pinMode(blueLED, OUTPUT); | |
// Initialize the serial monitor: | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
int sensorValue; | |
// Read the sensor value (will be 0 to 1023): | |
sensorValue = analogRead(sensorPin); | |
// Print out the sensor reading to the serial monitor: | |
Serial.print("sensor value: "); | |
Serial.println(sensorValue); | |
if (sensorValue < 100) | |
{ | |
digitalWrite(redLED, HIGH); | |
digitalWrite(greenLED, HIGH); | |
digitalWrite(blueLED, HIGH); | |
delay(100); | |
digitalWrite(redLED, LOW); | |
digitalWrite(greenLED, LOW); | |
digitalWrite(blueLED, LOW); | |
delay(100); | |
} | |
else | |
{ | |
digitalWrite(redLED, LOW); | |
digitalWrite(greenLED, LOW); | |
digitalWrite(blueLED, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment