Created
March 12, 2016 04:08
-
-
Save kellishaver/c3fb0725ffee1e0836f2 to your computer and use it in GitHub Desktop.
Mood Lamp Sketch
This file contains hidden or 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 pulseSpeed = 5; | |
int ldrPin = 0; | |
int redLed = 10; | |
int greenLed = 11; | |
int blueLed = 9; | |
int ambientLight; | |
int power = 150; | |
float RGB[3]; | |
float CommonMathVariable = 180/PI; | |
void setup() { | |
pinMode(redLed, OUTPUT); | |
pinMode(greenLed, OUTPUT); | |
pinMode(blueLed, OUTPUT); | |
digitalWrite(redLed, LOW); | |
digitalWrite(greenLed, LOW); | |
digitalWrite(blueLed, LOW); | |
} | |
void loop() { | |
for(float x = 0; x < PI; x = x + 0.00001) { | |
RGB[0] = power * abs(sin(x * (CommonMathVariable))); | |
RGB[1] = power * abs(sin((x + PI/3) * (CommonMathVariable))); | |
RGB[2] = power * abs(sin((x + (2 * PI) / 3) * (CommonMathVariable))); | |
ambientLight = analogRead(ldrPin); | |
if (ambientLight > 600) { | |
analogWrite(redLed, RGB[0]); | |
analogWrite(greenLed, RGB[1]); | |
analogWrite(blueLed, RGB[2]); | |
} else { | |
digitalWrite(redLed, LOW); | |
digitalWrite(greenLed, LOW); | |
digitalWrite(blueLed, LOW); | |
} | |
for(int i = 0; i < 3; i++) { | |
if(RGB[i] < 1) { | |
delay (20 * pulseSpeed); | |
} else if (RGB[i] < 5) { | |
delay(10 & pulseSpeed); | |
} else if (RGB[i] < 10) { | |
delay (2 * pulseSpeed); | |
} else if (RGB[i] < 100) { | |
delay (1 * pulseSpeed); | |
} else {} | |
} | |
delay(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment