Friday, 20 November 2015

Arduino Lab 2

Challenge Name:
Wavy Lights

Author:
Joshua Mac

Credit:
Kyle Chan
Aron Graca

Difficulty Level:
- 3
Pictures:




















Time to Complete:
- 10 minutes

Challenge Description:
In this challenge you will have to make a wave with 3 LED's. The process in this challenge is: LED1 turning on then off, LED2 turning on then off, LED3 turning on then off.

Hint:
- It is 1 big code, and not 3 separate ones

Answer:

int LedPin2 = 2; -Creating a variable named ledPin2 to represent the number 2
int LedPin3 = 3; -Creating a variable named ledPin3 to represent the number 3
int LedPin4 = 4; -Creating a variable named ledPin4 to represent the number 4

void setup() -This creates our setup() function which defines what the pins will do
{ -This indicates the start of void setup() 
  pinMode(ledPin2, OUTPUT); -This declares the value of ledPin2 to be an OUTPUT
  pinMode(ledPin3, OUTPUT); -This declares the value of ledPin3 to be an OUTPUT
  pinMode(ledPin4, OUTPUT); -This declares the value of ledPin4 to be an OUTPUT
This indicates the end of void setup() 

void loop() -This is where we put the program we want to loop forever 
{ - 
This indicates the start of void loop()   
  digitalWrite(ledPin2, HIGH); -ledPin2 is given maximum power
  delay(1000) -1000ms wait 
  digitalWrite(ledPin2, LOW); -ledPin4 goes off
  delay(1000) -1000ms wait 
  digitalWrite(ledPin3, HIGH); -ledPin3 is given maximum power
  delay(1000) -1000ms wait
  digitalWrite(ledPin3, LOW); -ledPin4 goes off
  delay(1000) -1000ms wait
  digitalWrite(ledPin4, HIGH); -ledPin4 is given maximum power
  delay(1000) -1000ms wait
  digitalWrite(ledPin4, LOW); -ledPin4 goes off
  delay(1000) -1000ms wait
} -This indicates the end of void loop() 


1 comment: