Professional Documents
Culture Documents
Submitted by
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
void loop() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
B) Blinking Led in 5s
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
void loop() {
2. Activity 2
A) Police Chaser Lights (flashes the middle red and blue LED and the
LED directly to the left of each color)
void setup() {
void loop() {
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
delay(100);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
delay(100);
digitalWrite(10, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(100);
digitalWrite(10, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(100);
B) Police Chaser Lights (flash the middle red and blue LED and the
LED directly to the right of each color, and then flash the middle red and blue
LED as well as the LED directly to the left of each color)
// the setup function runs once when you press reset or power the board
void setup() {
void loop() {
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
delay(100);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(100);
digitalWrite(12, HIGH);
digitalWrite(9, HIGH);
delay(100);
digitalWrite(12, LOW);
digitalWrite(9, LOW);
delay(100);
//
digitalWrite(13, HIGH);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(13, LOW);
digitalWrite(8, LOW);
delay(100);
C) Police Chaser Lights (free order: 2 leds sequentially turn on from left to
right each time)
// the setup function runs once when you press reset or power the board
void setup() {
void loop() {
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
delay(100);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(100);
//
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
delay(100)
3. Activity 3
A) Arduino Traffic Light Simulator
- Change the flashing order to Red - Yellow - Green
- Increase the delay time of Red and Green lights to 7 seconds
// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
// basic functions
void setup()
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
void loop()
red_light();
delay(DELAY_RED);
yellow_light();
delay(DELAY_YELLOW);
green_light();
delay(DELAY_GREEN);
void green_light()
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
void yellow_light()
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}
void red_light()
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
4. Activity 4
/*
'normal' presentation:
int ledPin4 = 4;
int ledPin5 = 5;
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9;
void setup () {
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
*/
/* However, by creating void setup() as an empty statement, we save space in the Arduino memory
by using the lowest possible number of int statements, because they are not in the program
twice, which also enables the LEDs to Flash BRIGHT, instead of 'glinting'.
*/
void setup() {}
void loop() {
for (int pin = 13; pin > 3; pin--) // 13 and 5 used here so that
if (pin %2){
delay(delayPeriod);
digitalWrite(pin, LOW);
delay(delayPeriod);
/*
'normal' presentation:
int ledPin4 = 4;
int ledPin5 = 5;
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9;
void setup () {
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
*/
/* However, by creating void setup() as an empty statement, we save space in the Arduino memory
by using the lowest possible number of int statements, because they are not in the program
twice, which also enables the LEDs to Flash BRIGHT, instead of 'glinting'.
*/
void setup() {}
void loop() {
for (int pin = 13; pin > 3; pin--) // 13 and 5 used here so that
if (!(pin %2)){
digitalWrite(pin, HIGH);
delay(delayPeriod);
digitalWrite(pin, LOW);
delay(delayPeriod);
'normal' presentation:
int ledPin4 = 4;
int ledPin5 = 5;
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9;
void setup () {
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
*/
/* However, by creating void setup() as an empty statement, we save space in the Arduino memory
by using the lowest possible number of int statements, because they are not in the program
twice, which also enables the LEDs to Flash BRIGHT, instead of 'glinting'.
*/
void setup() {}
void loop() {
for (int pin = 13; pin > 3; pin--) // 13 and 5 used here so that
if (!(pin %2)){
digitalWrite(pin, HIGH);
delay(delayPeriod);
digitalWrite(pin, LOW);
delay(delayPeriod);