เขียนโปรแกรมแสดงอุณหภูมิแสดงผลตัวเลขบน 7 segment MAX7219
ฟังก์ชั่นที่ใช้งาน
-delay() http://arduino.cc/en/Reference/Delay (http://arduino.cc/en/Reference/Delay)
-millis()http://arduino.cc/en/Reference/Millis (http://arduino.cc/en/Reference/Millis)
-analogRead() http://arduino.cc/en/Reference/AnalogRead (http://arduino.cc/en/Reference/AnalogRead)
-map() http://arduino.cc/en/reference/map (http://arduino.cc/en/reference/map)
ไลบารี่เพิ่มเติม
-LedControl.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 20 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 20 (http://www.praphas.com/forum/index.php?topic=266.0)
ฟังก์ชั่นในไลบารี่ LedControl.h
-LedControl lc=LedControl(dataPin,clkPin,csPin,numDevices);
-lc.shutdown(addr,false); // Enable display
-lc.setIntensity(addr,value); // Set brightness level (0 is min, 15 is max)
-lc.clearDisplay(addr); // Clear display register
-lc.setDigit(addr, digit, value, point_decimal) //display number 0-9
-lc.setChar(addr, digit, character, false) //display character etc. A,b,c,d,E,F,H,L,P,-,_
-lc.setRow(addr, digit,value) //display part of segment
รายละเอียดเพิ่มเติมของไลบารี่ http://playground.arduino.cc/Main/LedControl (http://playground.arduino.cc/Main/LedControl)
โจทย์โปรแกรม
-แสดงค่าอุณภูมิ (องศาเซลเซียส) จากเซนเซอร์ NTC Thermistor โดยแสดงผลที่ 7 segment MAX7219 และ UART
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino
(http://www.praphas.com/PhotoForum/arduino/Lab-22-01.png)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)
(http://www.praphas.com/PhotoForum/arduino/Lab-22-02.png)
บริเวณใช้งานบอร์ดทดลอง
(http://www.praphas.com/PhotoForum/arduino/Lab-21-03.png)
โมดูลสำเร็จรูปเพิ่มเติม
MAX7219 7 Segment
(http://www.praphas.com/PhotoForum/arduino/Lab-20-c.jpg)
http://www.arduinoall.com (คลิก) (http://www.arduinoall.com/product/460/%E0%B9%82%E0%B8%A1%E0%B8%94%E0%B8%B9%E0%B8%A5-%E0%B8%88%E0%B8%AD%E0%B9%81%E0%B8%AA%E0%B8%94%E0%B8%87%E0%B8%95%E0%B8%B1%E0%B8%A7%E0%B9%80%E0%B8%A5%E0%B8%82-8-%E0%B8%AB%E0%B8%A5%E0%B8%B1%E0%B8%81-%E0%B8%AA%E0%B8%B5%E0%B9%81%E0%B8%94%E0%B8%87-0-36quot-max7219-digital-tube-display-module)
ตัวอย่างโปรแกรมแสดงอุณภูมิเบื้องต้น
#include <math.h>
double Thermistor(int RawADC)
{
double Cal;
Cal = log(10000.0/((1024.0/RawADC-1)));
Cal = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Cal * Cal ))* Cal );
Cal = Cal - 273.15; // Convert Kelvin to Celcius
return Cal;
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
int Temp=Thermistor(analogRead(A3));
Serial.println(Temp);
delay(1000);
}