-
-
Save maxhawkins/a7302c672e2d05172d43 to your computer and use it in GitHub Desktop.
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
/** | |
** Pulse | |
**/ | |
const int redLED = 11; | |
const int greenLED = 10; | |
void setup() {} | |
void loop() { | |
// Fade in | |
for(int brightness = 0 ; brightness <= 255; brightness +=5) { | |
analogWrite(redLED, 255 - brightness); | |
analogWrite(greenLED, brightness); | |
delay(30); | |
} | |
// Fade out | |
for(int brightness = 255 ; brightness >= 0; brightness -=5) { | |
analogWrite(redLED, 255 - brightness); | |
analogWrite(greenLED, brightness); | |
delay(30); | |
} | |
} | |
/** | |
** Color Mixer | |
**/ | |
const int redLED = 11; | |
const int redSwitch = 1; | |
int redBrightness = 0; | |
const int greenLED = 10; | |
const int greenSwitch = 2; | |
int greenBrightness = 0; | |
void setup() { | |
pinMode(redLED, INPUT); | |
pinMode(greenLED, INPUT); | |
} | |
void loop() { | |
getBrightness(); | |
analogWrite(redLED, redBrightness); | |
analogWrite(greenLED, greenBrightness); | |
} | |
void getBrightness() { | |
int pressedRed = digitalRead(redSwitch); | |
int pressedGreen = digitalRead(greenSwitch); | |
if(pressedRed) | |
redBrightness++; | |
if(pressedGreen) | |
greenBrightness++; | |
if(pressedRed && pressedGreen) | |
redBrightness = greenBrightness = 0; | |
redBrightness = constrain(redBrightness, 0, 255); | |
greenBrightness = constrain(greenBrightness, 0, 255); | |
} | |
/** | |
** Pulsing Color Mixer | |
**/ | |
const int redLED = 11; | |
const int redSwitch = 1; | |
int redBrightness = 0; | |
const int greenLED = 10; | |
const int greenSwitch = 2; | |
int greenBrightness = 0; | |
void setup() { | |
pinMode(redLED, INPUT); | |
pinMode(greenLED, INPUT); | |
} | |
void loop() { | |
getBrightness(); | |
// Fade in | |
for(int brightness = 0 ; brightness <= 255; brightness +=5) { | |
analogWrite(redLED, map(brightness, 0, 255, 0, redBrightness)); | |
analogWrite(greenLED, map(brightness, 0, 255, 0, greenBrightness)); | |
delay(30); | |
} | |
// Fade out | |
for(int brightness = 255 ; brightness >= 0; brightness -=5) { | |
analogWrite(redLED, map(brightness, 0, 255, 0, redBrightness)); | |
analogWrite(greenLED, map(brightness, 0, 255, 0, greenBrightness)); | |
delay(30); | |
} | |
} | |
void getBrightness() { | |
int pressedRed = digitalRead(redSwitch); | |
int pressedGreen = digitalRead(greenSwitch); | |
if(pressedRed) | |
redBrightness++; | |
if(pressedGreen) | |
greenBrightness++; | |
if(pressedRed && pressedGreen) | |
redBrightness = greenBrightness = 0; | |
redBrightness = constrain(redBrightness, 0, 255); | |
greenBrightness = constrain(greenBrightness, 0, 255); | |
} | |
/** | |
** Finding Sensor Value Limits | |
**/ | |
const int sensor = 3; | |
int low, high, current; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
current = analogRead(sensor); | |
if(current > high) high = current; | |
if(current < low) low = current; | |
char sensors[20]; | |
sprintf(sensors, "%d3 %d3 %d3", low, high, current); | |
Serial.println(sensors); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment