התחל במצב לא מקוון עם האפליקציה Player FM !
פודקאסטים ששווה להאזין
בחסות


1 Encore: Will Poulter, Dave Beran, and The Bear 52:22
Understanding Variables
Manage episode 269164152 series 2774299
Let’s have a discussion about a powerful and semi-confusing programming topic – variables. Arduino code variables are like buckets. You choose what types of stuff you want in the bucket and can change the contents as often as you like. When you declare a variable, you are telling the program two things, firstly – what types of things you plan to put in the bucket, and secondly, what the name of the bucket is so you can refer to it later.
If you like this tutorial, click here to check out FREE Video Arduino course – thousands of people have really enjoyed it. If you tell the program you will be putting fluids in the bucket, then you can go all day filling it with beer, water, and iced tea – but the second you try to fill it with rocks, the compiler will call you out on your discrepancy. Only fluids go in a bucket declared for fluids. To declare a variable, you write the type of contents it will hold followed by the name:
fluid bucketVariable; 1 fluid bucketVariable; Notice in the above declaration statement that the word fluid is a different color – that is because Arduino knows variable data types – and they get a special color to reduce confusion and of course because they are cool.
There are several types of variable data types you can declare. In this lesson, we will discuss the integer data type.
You probably know that an integer is a whole number (no decimals). For Arduino, an integer is a number from -32,768 to 32,767. If you try to put a number bigger than that into an integer variable, the value will roll over to the opposite side like a game of Pac-Man. If you add 5 to 32,767, you would get –32,764. If you subtracted 5 from -32,768 you would get 32,763.
Integer is abbreviated int. Since an integer is an Arduino data type, it will change color to an orange.
int led;// an integer variable called led. 1 int led;// an integer variable called led. The name of the variable can be whatever you want with certain restrictions. There are also a couple good conventions to follow…
The variable name should be descriptive of its function, for example, the ledPin variable could be the pin number that you put your LED into on your Arduino board. By convention, most variables start lowercase. Variable names cannot be the same as keyword names. Now, what if we want to put something in the bucket? Well, we assign a value to the variable. When we first assign the value, it is called initialization, and we use the equal sign to do so. It looks like this.
intled; //first we declare the variable
led = 13; //now we initialize the variable 1 2 3 intled; //first we declare the variable led = 13; //now we initialize the variable Or, we can initialize and declare a variable at the same time…
int led = 13; //declare and initialize a variable with a single statement 1 int led = 13; //declare and initialize a variable with a single statement Now if you are going to initialize a variable (that is assign it a value to hold) before the setup() function, then you must do it all in one line like this:
int led = 13;
void setup(){
} 1 2 3 4 5 int led = 13; void setup(){ } Or you can do it like this:
int led;
void setup(){
led = 13;
} 1 2 3 4 5 6 7 int led; void setup(){ led = 13; } Well, that’s all we will talk about variables for now. I hope you have a basic idea of how they are declared and initialized.
61 פרקים
Manage episode 269164152 series 2774299
Let’s have a discussion about a powerful and semi-confusing programming topic – variables. Arduino code variables are like buckets. You choose what types of stuff you want in the bucket and can change the contents as often as you like. When you declare a variable, you are telling the program two things, firstly – what types of things you plan to put in the bucket, and secondly, what the name of the bucket is so you can refer to it later.
If you like this tutorial, click here to check out FREE Video Arduino course – thousands of people have really enjoyed it. If you tell the program you will be putting fluids in the bucket, then you can go all day filling it with beer, water, and iced tea – but the second you try to fill it with rocks, the compiler will call you out on your discrepancy. Only fluids go in a bucket declared for fluids. To declare a variable, you write the type of contents it will hold followed by the name:
fluid bucketVariable; 1 fluid bucketVariable; Notice in the above declaration statement that the word fluid is a different color – that is because Arduino knows variable data types – and they get a special color to reduce confusion and of course because they are cool.
There are several types of variable data types you can declare. In this lesson, we will discuss the integer data type.
You probably know that an integer is a whole number (no decimals). For Arduino, an integer is a number from -32,768 to 32,767. If you try to put a number bigger than that into an integer variable, the value will roll over to the opposite side like a game of Pac-Man. If you add 5 to 32,767, you would get –32,764. If you subtracted 5 from -32,768 you would get 32,763.
Integer is abbreviated int. Since an integer is an Arduino data type, it will change color to an orange.
int led;// an integer variable called led. 1 int led;// an integer variable called led. The name of the variable can be whatever you want with certain restrictions. There are also a couple good conventions to follow…
The variable name should be descriptive of its function, for example, the ledPin variable could be the pin number that you put your LED into on your Arduino board. By convention, most variables start lowercase. Variable names cannot be the same as keyword names. Now, what if we want to put something in the bucket? Well, we assign a value to the variable. When we first assign the value, it is called initialization, and we use the equal sign to do so. It looks like this.
intled; //first we declare the variable
led = 13; //now we initialize the variable 1 2 3 intled; //first we declare the variable led = 13; //now we initialize the variable Or, we can initialize and declare a variable at the same time…
int led = 13; //declare and initialize a variable with a single statement 1 int led = 13; //declare and initialize a variable with a single statement Now if you are going to initialize a variable (that is assign it a value to hold) before the setup() function, then you must do it all in one line like this:
int led = 13;
void setup(){
} 1 2 3 4 5 int led = 13; void setup(){ } Or you can do it like this:
int led;
void setup(){
led = 13;
} 1 2 3 4 5 6 7 int led; void setup(){ led = 13; } Well, that’s all we will talk about variables for now. I hope you have a basic idea of how they are declared and initialized.
61 פרקים
כל הפרקים
×





1 How to make a secret knock detector to trigger anything with only an Arduino and a few cheap components 12:57

1 Arduino Pseudo Random Non-Consecutive Number Generator 11:13








1 How to Use and Understand the Arduino Reference 12:48

1 Using Red-Green-Blue (RGB) LEDs with Arduino (Common Cathode Type) 14:47

1 Using Random Numbers with Arduino 13:02


1 How to Make One Button Have the Functionality of Two or More with Arduino 15:40

1 Understanding HIGH and LOW Arduino Pin States 12:31

1 Floating Pins, Pull-Up Resistors and Arduino 10:29


1 Throw out your breadboard! Dr. Duino: An Arduino Shield for debugging and developing Arduino projects 11:35

1 Shorthand Arithmetic :: Using Compound Operators (+= , -= , *= , /= ) with Arduino 12:43

1 Understanding Boolean Data Types and Using the Boolean NOT (!) operator to Switch Arduino Pin States 8:11

1 What to do when you just don't know :: Arduino, ADXL345 triple axis accelerometer and an RGB LED 14:04

1 3 Ways to Use Acceleration in an Arduino Sketch 17:37

1 Understanding the Arduino uber functions loop() and setup() 10:26

1 Functions: Let's make programming Arduino as easy as possible 11:00

1 Data Types: One size does not fit all 11:15


1 Syntax; the spelling and grammar of programming 11:32


1 Arduino Board Hardware overview for people like me 10:38

1 Everything you need to know about the Arduino IDE (for now) 11:09








1 How to read voltages with analogRead() 14:44

1 analogRead() and the Serial Port 12:02

1 digitalRead() and the Serial Port 21:22

1 How to Blink an LED with Arduino 14:39







ברוכים הבאים אל Player FM!
Player FM סורק את האינטרנט עבור פודקאסטים באיכות גבוהה בשבילכם כדי שתהנו מהם כרגע. זה יישום הפודקאסט הטוב ביותר והוא עובד על אנדרואיד, iPhone ואינטרנט. הירשמו לסנכרון מנויים במכשירים שונים.