🤩 FREE Arduino Crash Course 👇👇
bit.ly/get_Arduino_skills
**If you like this, I think you'll like the premium Arduino training we offer. Check it out here** bit.ly/3nSBPUs
We designed this circuit board for beginners!
Kit-On-A-Shield: amzn.to/3lfWClU
SHOP OUR FAVORITE STUFF! (affiliate links)
---------------------------------------------------
We use Rev Captions for our subtitles
bit.ly/39trLeB
Arduino UNO R3:
Amazon: amzn.to/37eP4ra
Newegg: bit.ly/3fahas8
Budget Arduino Kits:
Amazon:amzn.to/3C0VqsH
Newegg:bit.ly/3j4tISX
Multimeter Options:
Amazon: amzn.to/3rRo3E0
Newegg: bit.ly/3rJoekA
Helping Hands:
Amazon: amzn.to/3C8IYXZ
Newegg: bit.ly/3fb03X1
Soldering Stations:
Amazon: amzn.to/2VawmP4
Newegg: bit.ly/3BZ6oio
AFFILIATES & REFERRALS
---------------------------------------------------
►Audible Plus Free trial: amzn.to/3j5IGrV
►Join Honey- Save Money bit.ly/3xmj7rH
►Download Glasswire for Free:bit.ly/3iv1fql
FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook: / programmingelectronics...
Twitter: / progelecacademy
Website: www.programmingelectronics.com/
Click Below to Read About This Topic on Our Website
programmingelectronics.com/tu...
Description:
Arduino Course for Absolute Beginners
There are few functions so useful that you find them everywhere. The 'for loop' is an example of this type. A For Loop repeats an action for a specified number of iterations, reducing the lines of code that need to be written thus making the programmers life easier.
In this example we are setting out to make a row of LEDs light up somewhat similar to Kit in Knight Rider.
You Will Need
LED (6)
220 Ohm Resistor (6)
Solder-less Breadboard
Jumper Wires (1)
Red Canary (42)
Step-by-Step Instructions
Connect one side of a resistor into pin 2, connect the other side into a row on the breadboard.
From that row in the breadboard where you attached the resistor, connect the long leg of the LED.
Connect the short leg of the LED to one of the power strip columns on your breadboard.
Now connect a resistor to pin 3, and put the other leg in a row on the breadboard (a different one then your first LED.
Connect an LED in the same manor - make sure the short leg goes in the SAME power strip column as the previous LED.
Repeat this through pin 7.
Using a jumper wire, connect the common power strip to a GND pin on the Arduino.
Connect the Arduino to your computer.
Open up the Arduino IED.
Go to File, Examples, 05.Control, ForLoopIteration
Click the Verify button (Top Left). The button will turn orange and then blue once finished.
Click the Upload button. The button will turn orange and then blue when finished.
Watch in awe as your LEDs turn on and off in sequence.
The first executable code we find is the declaration of the 'timer' variable...
int timer = 100; // The higher the number, the slower the timing.
This integer variable with a descriptive name will set the rate between one LED turning on and off. What is so important about variables like these is how easy they allow you to alter your code and how your circuit will run. If the programmer had written the number 100 in a bunch of functions through out this program we would have had the exact same effect, but as soon as we want to speed up the blinking of the LEDs, now we have to go through and change every 100 to a 500 - what a pain - especially when you miss a couple 100's, and accidentally put a 500 where there shouldn't have bee one. These variables are like controls into your program - imagine you are on the Star Ship Enterprise, all those buttons and touch screen levers - these are your control variables.
Our next friendly block of code is setup(). In this setup() function we run into our first For Loop.
void setup() {
for (int thisPin = 2; thisPin LT 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
Let's consider just what is inside the parenthesis following the for loop..
for (int thisPin = 2; thisPin lt 8; thisPin++)
There are three separate statements in the parenthesis separated by a semicolon. The first statement is initialization of the counter variable used in the 'for loop' and it looks like any other variable declaration and initialization that you have seen.
int thisPin = 2;
The 'thisPin' variable is what will be used in the next block of code - or the test.
thisPin lt 8;
This is the test condition that will tell the loop to keep going or to stop. If this condition is TRUE, the code in the curly brackets of the 'for loop; will be executed again, if the condition is FALSE, the
Негізгі бет Ғылым және технология Tutorial 12: For Loop Iteration: Arduino Course for Absolute Beginners (ReM)
Пікірлер: 264