เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล 7 segment MAX7219
ไลบารี่เพิ่มเติม
-LedControl.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 20 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 20 (http://www.praphas.com/forum/index.php?topic=266.0)
-Keypah.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 38 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 38 (http://www.praphas.com/forum/index.php?topic=289.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)
ฟังก์ชั่นในไลบารี่ Keypad.h http://playground.arduino.cc/Code/Keypad (http://playground.arduino.cc/Code/Keypad)
-begin(
-waitForKey()
-getKey()
-getState()
-keyStateChanged()
-setHoldTime()
-setDebounceTime()
-addEventListener()
ฟังก์ชั่นที่ใช้งาน
-pinMode() http://arduino.cc/en/Reference/PinMode (http://arduino.cc/en/Reference/PinMode)
-digitalWrite() http://arduino.cc/en/Reference/DigitalWrite (http://arduino.cc/en/Reference/DigitalWrite)
-delay() http://arduino.cc/en/reference/delay (http://arduino.cc/en/reference/delay)
*หมายเหตุ จากการทดลองไลบรารี่ keypad เมื่อใช้ขา D13 จะทำให้ไม่สามารถใช้งานได้ ดังนั้นเวลาใช้งานขา D13 จึงห้ามใช้
โจทย์การทดลอง
-เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล 7 segment MAX7219
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino
(http://www.praphas.com/PhotoForum/arduino/Lab-39-01.png)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)
(http://www.praphas.com/PhotoForum/arduino/Lab-39-01.png)
บริเวณใช้งานบอร์ดทดลอง
(http://www.praphas.com/PhotoForum/arduino/Lab-39-01.png)
โมดูลสำเร็จรูปเพิ่มเติม
Keypad
http://www.arduinoall.com (คลิก) (http://www.arduinoall.com/product/119/3x4-matrix-keypad)
MAX7219 7 Segment
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)
ตำแหน่งขาต่อของคีย์แพด
(http://www.praphas.com/PhotoForum/arduino/Lab-37-b.png)
ตัวอย่างโปรแกรมรับค่าจากคีย์แพด
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {13,12,11,10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A0,A1,A2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
Serial.println(key);
}
}
ตัวอย่างโปรแกรมแสดงผล 7 Segment MAX7219
#include "LedControl.h"
LedControl lc=LedControl(6,4,5,1); // Pin 11->DIN, 13->CLK, 12->CS, 1 = No.of devices
void setup()
{
lc.shutdown(0,false); // Enable display
lc.setIntensity(0,10); // Set brightness level (0 is min, 15 is max)
lc.clearDisplay(0); // Clear display register
}
void loop()
{
lc.setDigit(0,7,2,false);
lc.setDigit(0,6,3,true);
lc.setDigit(0,5,4,false);
lc.setRow(0,4,B00110111);
lc.setRow(0,3,B01001111);
lc.setRow(0,2,B00001110);
lc.setRow(0,1,B00001110);
lc.setRow(0,0,B01111110);
delay(1000);
}