Section 1 Exercises

In order to really learn you must use your knowledge. In this section you will complete assignments that use what you have learned in section 1.

1. Change the blink.

Change the speed of the blink or introduce a pattern of blinking.
You can change the amount of time of the delay commands to keep the LED on or off as you like. You can also introduce more and more delay and digitalwrite commands.

2. More light.

Add a second LED circuit on pin 12.
This is just repeating what you did before but now you will have to code to blink both leds.

3. Alternating pattern

Make a pattern where the second LED blinks multiple times every time the first LED blinks.

===============================================================

Solutions

1. Change the blink.

There are many possible solutions. Here is one:
[code lang="arduino" firstline="8" gutter="0"]
void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(400);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(100);
}
[/code]

2. More light.


[code lang="arduino" firstline="8" gutter="0"]
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
delay(50);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
delay(300);
}
[/code]

3. Alternating pattern

[code lang="arduino" firstline="8" gutter="0"]
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
delay(100);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
}
[/code]

Leave a Reply