Assignment #1 - Blinking LEDs
For this assignment, I made two LEDs blink, one at half the frequency of the other.
code
//set variables for my digital pins
const int led1 = 9;
const int led2 = 6;
//using variables for LED state for easy inversion in loop
int led1Val = 1;
int led2Val = 1;
//a counter used to get the different frequencies
int x = 0;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
//set both LEDs to their state
digitalWrite(led1, led1Val);
digitalWrite(led2, led2Val);
//invert the state of led1 so that its the opposite of right now
led1Val = !led1Val;
//if our counter is divisible by 2, flip led2 state.
//this is only true every other iteration, so led2 blinks at half
//the frequency of led1
if (x%2 == 0) {
led2Val = !led2Val;
}
//increment the counter and delay
x++;
delay(100);
}
http://youtu.be/uqa4kSBd7Xw - video of circuit
- Login to post comments
Drupal theme by Kiwi Themes.