เส้น สี่เหลี่ยม และวงกลม
วาดรูปทรงเพื่อสร้างส่วนติดต่อผู้ใช้อย่างง่าย
เส้น สี่เหลี่ยม และวงกลม เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Arduino & IoT Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Beyond Text
Text alone gets dull. The GFX library also draws shapes, so you can frame data, build meters, and design a real little interface. 🎨
The Pixel Grid
Every shape lives on a coordinate grid. Point (0,0) is top-left; x runs right and y runs down, just like the text cursor you already used.
Draw a Single Pixel
The smallest mark is one dot. drawPixel takes an x, a y, and a color, lighting exactly one point on the screen.
display.drawPixel(10, 10, WHITE);Draw a Line
drawLine connects two points. Give a start x and y, an end x and y, and a color to stroke a straight line between them.
display.drawLine(0, 0, 127, 63, WHITE);Outline a Rectangle
drawRect needs a top-left x and y, then a width and height. It strokes just the border, perfect for framing a value or a section.
display.drawRect(0, 0, 60, 30, WHITE);Fill a Rectangle
Swap to fillRect with the same arguments to paint the whole box solid. Filled bars are the heart of meters and progress displays.
display.fillRect(0, 0, 60, 30, WHITE);Outline a Circle
drawCircle takes a center x and y plus a radius. It strokes a ring, handy for dials, status dots, or rounded icons.
display.drawCircle(64, 32, 20, WHITE);Fill a Circle
Use fillCircle for a solid disc. A small filled circle makes a clear on/off indicator that is easy to read at a glance.
display.fillCircle(64, 32, 5, WHITE);Rounded Rectangles
For a softer look, drawRoundRect adds a corner radius after width and height. Rounded boxes make buttons and cards feel friendlier.
display.drawRoundRect(0, 0, 60, 30, 8, WHITE);Layer Shapes and Text
Order matters: shapes drawn later sit on top. Draw a filled box first, then print text over it for a labeled badge effect.
display.fillRect(0, 0, 50, 16, WHITE);
display.setTextColor(BLACK);Then Push to Screen
As always, all drawing fills the buffer. End your shape work with display.display() so the whole composed image appears at once.
display.display();Quick Check
You want a solid bar to show how full a tank is.
Recap
You can now draw pixels, lines, rectangles, and circles, and layer shapes with text. These primitives are all you need to compose a real UI.
คำถามที่พบบ่อย
บทเรียน “เส้น สี่เหลี่ยม และวงกลม” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “เส้น สี่เหลี่ยม และวงกลม” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “เส้น สี่เหลี่ยม และวงกลม”
วาดรูปทรงเพื่อสร้างส่วนติดต่อผู้ใช้อย่างง่าย คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “เส้น สี่เหลี่ยม และวงกลม” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม
ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ต่อสายและเริ่มต้น SSD1306 OLED
- วาดข้อความหลายขนาด
- เส้น สี่เหลี่ยม และวงกลม
- สร้างภาพเคลื่อนไหวให้กราฟแท่ง