Lesson 5/31: Introduction to Arduino Data Types SunFounder Learning Kit
In this tutorial, we will explore the various data types available in Arduino programming, such as integers, floats, characters, and strings. Understanding these data types is essential for effective programming in Arduino, as they determine how data is stored and manipulated in memory. By the end of this lesson, you will have a solid grasp of how to use these data types in your projects.
To illustrate these concepts, we will be using the SunFounder 3-in-1 Arduino kit, which comes with a variety of components and projects. This lesson will not only cover the theoretical aspects of data types but also provide practical examples through code snippets. For a visual explanation, be sure to check out the accompanying video (in video at 00:00).
Code Examples & Walkthrough
Now, let's delve into the code snippets that demonstrate the usage of various data types. In the setup function, we declare an integer variable age and calculate days based on the age:
int age = 36;
int days = age * 365;
This snippet showcases how we can use integers to store whole numbers and perform calculations. The variable days is derived from multiplying age by 365, demonstrating basic arithmetic operations.
Next, we explore binary and hexadecimal representations. The following code stores a binary value in temperature and a hexadecimal value in year:
int temperature = B101101; // binary integer value 45
int year = 0x7E3; // hex value for 2019
In this example, temperature is assigned a binary value using the B prefix, while year is defined with the 0x prefix to indicate it is in hexadecimal format. This illustrates how different bases can be used to represent the same numerical value.
Demonstration / What to Expect
After uploading the code to your Arduino, you can expect to see the printed output on the Serial Monitor. The output will display the age, days, temperature, and year in their respective formats. Make sure to set the baud rate to match the one defined in the code (9600 baud) for proper communication (in video at 14:30).
Common pitfalls include incorrect wiring that can lead to no output or unexpected results. Ensure all connections are secure, and double-check that the correct pins are used as per the code. If you see garbled characters in the Serial Monitor, verify the baud rate settings.
/*
* درس 05-نوع داده ها 01
* کیت هوشمند 3 در 1 ماشین آردوینو سان فاندری
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT588
* نوشته احمد شمشیری
* توضیح کامل ویدیو را تماشا کنید https://youtu.be/xi9Hegk9M9k
* www.robojax.com
*/
void setup() {
int age = 36;
int days = age * 365;
Serial.begin(9600);
Serial.println("Robojax Step By Step Arduino Course");
// رابوجکس https://robojax.com/RJT588
Serial.print("Age:");
Serial.println(age);
Serial.print("Days:");
Serial.println(days);
Serial.println();
int temperature = B101101; // مقدار صحیح باینری ۴۵
Serial.print("B101101:");
Serial.println(temperature);
Serial.println();
int year = 0x7E3; // مقدار هگزا دسیمال برای 2019
Serial.print("0x7E3:");
Serial.println(year);
Serial.println();
}
void loop() {
// شِفر (کود) اصلی خود را اینجا قرار دهید تا بهطور مکرر اجرا شود:
// دورهی آردوینو قدم به قدم روباتجکس
}
/*
* درس 05- انواع داده 02- خصیصه
* کیفیت 3-in-1 ماشین هوشمند آرودینوی سان فاندر
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT588
* نوشته احمد شمشیری
* ویدئوی کامل توضیحات را مشاهده کنید https://youtu.be/xi9Hegk9M9k
* www.robojax.com
*/
void setup() {
char grade = 'A';
char grade2 = 65;
Serial.begin(9600);
Serial.println("Robojax Step By Step Arduino Course");
// دوره آموزشی آردوینو قدم به قدم ربوجکس http://robojax.com/L/?id=338
Serial.println(grade);
Serial.println(grade2);
}
void loop() {
// شِفر (کود) اصلی خود را اینجا بنویسید تا به طور مکرر اجرا شود:
}
/*
* درس 05- نوع داده 03- کلاوت
* کیفیت هوشمند 3 در 1 خودرو سن فاندری
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT588
* نوشته احمد شمشیری
* ویدئو توضیحات کامل را مشاهده کنید https://youtu.be/xi9Hegk9M9k
* www.robojax.com
*/
void setup() {
float price= 4.35;
float quantity = 8;
float cost = price * quantity;
Serial.begin(9600);
Serial.println("Robojax Step By Step Arduino Course");
// دوره آردوینو گام به گام روبوجکس http://robojax.com/L/?id=338
Serial.print("Price:");
Serial.println(price);
Serial.println(price, 4);
Serial.print("Quantity:");
Serial.println(quantity);
Serial.print("Cost:");
Serial.println(cost);
}
void loop() {
// شِفر (کود) اصلی خود را اینجا قرار دهید، تا به طور مکرر اجرا شود:
}
/*
* درس 05- نوع دادهها 04- بولی
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT588
* نوشته احمد شمشیری
* برای تماشای توضیحات کامل ویدیو https://youtu.be/xi9Hegk9M9k
* www.robojax.com
*/
void setup() {
float price= 4.35;
float quantity = 8;
float cost = price * quantity;
Serial.begin(9600);
Serial.println("Robojax Step By Step Arduino Course");
// دوره آموزشی آردوینو قدم به قدم روبوجکس http://robojax.com/L/?id=338
Serial.print("Price:");
Serial.println(price);
Serial.println(price, 4);
Serial.print("Quantity:");
Serial.println(quantity);
Serial.print("Cost:");
Serial.println(cost);
}
void loop() {
// شِفر (کود) اصلی خود را اینجا قرار دهید تا به طور مکرر اجرا شود:
}
/*
* درس 05- نوعهای داده 05- رشته
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT588
* نوشته شده توسط احمد شمشیری
* تماشای توضیحات ویدیویی کامل https://youtu.be/xi9Hegk9M9k
* www.robojax.com
*/
void setup() {
String string1 = "Hello String"; // استفاده از یک رشته ثابت
String string2 = String('a'); // تبدیل یک خصیصه ثابت به یک رشته
String string3 = String("This is a string"); // تبدیل یک رشته ثابت به یک شیء String
String string4 = String(string3 + " with more"); // الحاق دو رشته
String string5 = String(13); // استفاده از یک عدد صحیح ثابت
String string6 = String(45, HEX); // استفاده از یک عدد صحیح و یک پایه (هگزادسیمال)
String string7 = String(255, BIN); // استفاده از یک عدد صحیح و یک مبنا (باینری)
String string8 = String(5.698, 2); // استفاده از یک عدد اعشاری و مکانهای اعشاری
Serial.begin(9600);
Serial.println("Robojax Step By Step Arduino Course");
// دوره آموزشی آردوینو مرحله به مرحله روبوجکس http://robojax.com/L/?id=338
Serial.print("String1:");
Serial.println(string1);
Serial.println();
Serial.print("String2:");
Serial.println(String('a'));
Serial.println();
Serial.print("string3:");
Serial.println(string3);
Serial.println();
Serial.print("string3 + \" with more\":");
Serial.println(string4);
Serial.println();
Serial.print("string5:");
Serial.println(string5);
Serial.println();
Serial.print("String(45, HEX):");
Serial.println(string6);
Serial.println();
Serial.print("String(255, BIN):");
Serial.println(string7);
Serial.println();
Serial.print("String(5.698, 3):");
Serial.println(string8);
Serial.println();
}
void loop() {
// شِفر (کود) اصلی خود را اینجا قرار دهید تا به صورت مکرر اجرا شود:
}
/*
* درس 05-نوع داده 04-عدد صحیح بدون علامت
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT588
* نویسنده احمد شمشیری
* ویدئوی کامل توضیح را مشاهده کنید https://youtu.be/xi9Hegk9M9k
* www.robojax.com
*/
void setup() {
Serial.begin(9600);
Serial.println("Robojax Step By Step Arduino Course");
// دوره آموزش آردوینو به صورت گام به گام Robojax http://robojax.com/L/?id=338
unsigned int x = 456;
Serial.print("x: ");
Serial.println(x);
Serial.print("size of x (bytes): ");
Serial.println( sizeof(x) );
}
void loop() {
// شِفر (کود) اصلی خود را اینجا قرار دهید تا به طور مداوم اجرا شود:
}
Common Course Links
Common Course Files
منابع و مراجع
هنوز هیچ منبعی موجود نیست.
فایلها📁
هیچ فایلی موجود نیست.