เขียนโปรแกรมปรับค่าความสว่างของ LED (PWM pin)
ฟังก์ชั่นที่ใช้งาน
-analogWrite() http://arduino.cc/en/Reference/AnalogWrite (http://arduino.cc/en/Reference/AnalogWrite)
ผลของ PWM กับความสว่าง
(http://www.praphas.com/PhotoForum/arduino/Lab-07-01.gif)
โจทย์การทดลอง
-เขียนโปรแกรมควบคุมความสว่างของ LED ที่ขา D9,D10,D11
-รูปแบบเป็นไฟวิ่งความสว่างในแต่ละจังหวะและรูปแบบที่แตกต่างกัน
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)
ผังขาต่อใช้งานของ Arduino Nano
(http://www.praphas.com/PhotoForum/arduino/nano.jpg)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino
(http://www.praphas.com/PhotoForum/arduino/Lab-07-02.png)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)
(http://www.praphas.com/PhotoForum/arduino/Lab-07-03.png)
บริเวณใช้งานบอร์ดทดลอง
(http://www.praphas.com/PhotoForum/arduino/Lab-07-04.png)
ตัวอย่างโปรแกรม
#define LED 11
void setup()
{
pinMode(LED,OUTPUT);
}
void loop()
{
for(byte i=0;i<255;i+=5) //Add up step to 5
{
analogWrite(LED,i);
delay(50);
}
}