-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Photon
authored
Sep 14, 2020
1 parent
1dfeab2
commit bcaedac
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
________ ___ ___ | ||
/ __/ __ \/ _ | / _ \ | ||
_\ \/ /_/ / __ |/ , _/ | ||
/___/\____/_/ |_/_/|_| | ||
Arduino Workshop Series | ||
Session 1 | ||
> Blink an LED via pin 11. | ||
*/ | ||
|
||
|
||
void setup() | ||
{ | ||
pinMode(11, OUTPUT); //Set pin to output mode | ||
} | ||
|
||
void loop() | ||
{ | ||
digitalWrite(11, HIGH); // Output HIGH @ pin 11 | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(11, LOW); // Output LOW @ pin 11 | ||
delay(500); // Wait for 500 millisecond(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
________ ___ ___ | ||
/ __/ __ \/ _ | / _ \ | ||
_\ \/ /_/ / __ |/ , _/ | ||
/___/\____/_/ |_/_/|_| | ||
Arduino Workshop Series | ||
Session 1 | ||
> Blink multiple LEDs via pin 11, 10, 6, 5, 3. | ||
*/ | ||
|
||
void setup() | ||
{ | ||
//Setup the pins as output | ||
pinMode(11, OUTPUT); | ||
pinMode(10, OUTPUT); | ||
pinMode(6, OUTPUT); | ||
pinMode(5, OUTPUT); | ||
pinMode(3, OUTPUT); | ||
} | ||
|
||
void loop() | ||
{ | ||
//Turn the LED(s) On & Off one after another, repeating the sequence once the LED has lighted | ||
digitalWrite(11, HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(11, LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(10, HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(10, LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(6, HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(6, LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(5, HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(5, LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(3, HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(3, LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
________ ___ ___ | ||
/ __/ __ \/ _ | / _ \ | ||
_\ \/ /_/ / __ |/ , _/ | ||
/___/\____/_/ |_/_/|_| | ||
Arduino Workshop Series | ||
Session 1 | ||
> Blink multiple LEDs via pin 11, 10, 6, 5, 3. | ||
*/ | ||
|
||
int led_pins[5] = {11,10,6,5,3}; //Declare pin array | ||
|
||
void setup() | ||
{ | ||
for(int i=0; i<5; i++){ | ||
pinMode(led_pins[i], OUTPUT); //Iterate through the array & set them as output | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
//Iterate through the array & turn the LED(s) On & Off respectively | ||
for(int j=0; j<5; j++){ | ||
digitalWrite(led_pins[j], HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(led_pins[j], LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
________ ___ ___ | ||
/ __/ __ \/ _ | / _ \ | ||
_\ \/ /_/ / __ |/ , _/ | ||
/___/\____/_/ |_/_/|_| | ||
Arduino Workshop Series | ||
Session 1 | ||
> Bounce the light left & right. | ||
*/ | ||
|
||
int led_pins[5] = {11,10,6,5,3}; //Declare pins | ||
int index = 0; //Used to track the position of the light | ||
bool isInverted = false; //Determine the direction of the light, defaults to left | ||
|
||
void setup() | ||
{ | ||
for(int i=0; i<5; i++){ //Pin setup | ||
pinMode(led_pins[i], OUTPUT); | ||
} | ||
} | ||
|
||
void lightLED(const int &num){ //Function to turn the LED On & Off | ||
digitalWrite(num, HIGH); | ||
delay(500); // Wait for 500 millisecond(s) | ||
digitalWrite(num, LOW); | ||
delay(500); // Wait for 500 millisecond(s) | ||
} | ||
|
||
void loop() | ||
{ | ||
lightLED(led_pins[index]); //Run the function at the current LED position | ||
|
||
if((!isInverted&&index==4)||(isInverted&&index==0)){ | ||
isInverted = !isInverted; //If position is at the beginning or end, flip the direction | ||
} | ||
if(!isInverted&&index<5){ | ||
++index; //Increment only if the direction is moving right and the index is not at the end (5) | ||
}else if(isInverted&&index>-1){ | ||
--index; //Decrement only if the direction is moving left and the index is not at the beginning (0) | ||
} | ||
} | ||
|