0Pricing
Arduino & IoT Academy · บทเรียน

int, float, bool บน Arduino

เลือกชนิดข้อมูลที่เหมาะสมสำหรับเก็บข้อมูลเซนเซอร์และสถานะ

int, float, bool บน Arduino เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Boxes for Your Data

A variable is a named box that holds a value while your sketch runs, so you can store a sensor reading once and reuse it later. 📦

Why Types Matter

On Arduino you must say what kind of value a box holds. The type decides how much memory it takes and what values fit inside it.

Whole Numbers with int

An int stores whole numbers like counts, pin numbers, or a 0 to 1023 sensor value. It is the type you will reach for most often.

int sensorValue = 512;

int Has Limits

On an Uno an int holds roughly -32,768 to 32,767. Go past that and the number wraps around, which can cause sneaky bugs.

Decimals with float

A float holds numbers with a decimal point, like 23.5 degrees from a temperature sensor. Use it when whole numbers are too coarse.

float temperature = 23.5;

float Is Approximate

A float trades exactness for range, so values are stored approximately. Avoid it for money or precise counting; it is great for sensors.

True or False with bool

A bool holds just true or false, perfect for a yes or no fact like whether a button is currently pressed or an LED is on.

bool ledOn = false;

Name It Clearly

Give each variable name a clear meaning like buttonPin or doorOpen. Future you reads code faster when names say what they hold.

Declare Then Use

First you declare a variable with its type and a name, then you can read it or change it anywhere below in the same sketch.

int count = 0;
count = count + 1;

Global vs Local

Declare a variable above setup to make it global and shared everywhere. Declare it inside a function and only that function can see it.

Pick the Right Type

Match the type to the data: int for counts and pins, float for temperatures, bool for flags. The right choice saves memory and prevents bugs.

Quick Check

Which type best stores a temperature reading of 23.5 degrees?

Recap

You now pick types like a pro: int for whole numbers, float for decimals, and bool for true or false flags. Clear names keep it all readable. 🎯

คำถามที่พบบ่อย

บทเรียน “int, float, bool บน Arduino” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “int, float, bool บน Arduino” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “int, float, bool บน Arduino”

เลือกชนิดข้อมูลที่เหมาะสมสำหรับเก็บข้อมูลเซนเซอร์และสถานะ คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “int, float, bool บน Arduino” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม

ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. int, float, bool บน Arduino
  2. ทำไม delay() จึงบล็อกทุกอย่าง
  3. ทำไฟกะพริบโดยไม่ใช้ delay ด้วย millis
  4. ทำงานสองอย่างพร้อมกัน
← กลับไปที่ Arduino & IoT Academy