Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Code and Diagrams from Intro to Arduino talk given at Montana Programmers on Thursday, Marth 8, 2012

View README
1
Code and Diagrams from Intro to Arduino talk given at Montana Programmers on Thursday, Marth 8, 2012
View README
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 
int blue_brightness = 0; // how bright the blue LED is
int red_brightness = 255; // how bright the red LED is
int blue_fadeAmount = 5; // how many points to fade the blue LED by
int red_fadeAmount = -5; // how many points to fade the red LED by
 
void setup() {
// declare pins 9 and 10 to be an outputs:
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
 
void loop() {
// set the brightness levels:
analogWrite(9, blue_brightness);
analogWrite(10, red_brightness);
 
// change the brightness for next time through the loop:
blue_brightness = blue_brightness + blue_fadeAmount;
red_brightness = red_brightness + red_fadeAmount;
 
// reverse the direction of the fading at the ends of the fade:
if (blue_brightness == 0 || blue_brightness == 255) {
blue_fadeAmount = -blue_fadeAmount ;
}
if (red_brightness == 0 || red_brightness == 255) {
red_fadeAmount = -red_fadeAmount ;
}
// set the delay based off of the light sensor reading so that
// the speed of fading is set by the ambient light amount
delay(5);
}
View README
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 
int blue_brightness = 0; // how bright the blue LED is
int red_brightness = 255; // how bright the red LED is
int blue_fadeAmount = 5; // how many points to fade the blue LED by
int red_fadeAmount = -5; // how many points to fade the red LED by
int ambient = 0;
 
void setup() {
// declare pins 9 and 10 to be an outputs:
pinMode(9, OUTPUT); // blue LED
pinMode(10, OUTPUT); // red LED
pinMode(A0, INPUT); // Light Sensor
}
 
void loop() {
// set the brightness levels:
analogWrite(9, blue_brightness);
analogWrite(10, red_brightness);
 
ambient = analogRead(0); //grab the value from the light sensor
 
// change the brightness for next time through the loop:
blue_brightness = blue_brightness + blue_fadeAmount;
red_brightness = red_brightness + red_fadeAmount;
 
// reverse the direction of the fading at the ends of the fade:
if (blue_brightness == 0 || blue_brightness == 255) {
blue_fadeAmount = -blue_fadeAmount ;
}
if (red_brightness == 0 || red_brightness == 255) {
red_fadeAmount = -red_fadeAmount ;
}
// set the delay based off of the light sensor reading so that
// the speed of fading is set by the ambient light amount
delay(30 % ambient);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.