ผู้เขียน หัวข้อ: งานครั้งที่ 39 เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล 7 segment MAX7219  (อ่าน 6585 ครั้ง)

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 706
    • ดูรายละเอียด
    • อีเมล์
เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล 7 segment MAX7219

ไลบารี่เพิ่มเติม
-LedControl.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 20 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 20
-Keypah.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 38 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 38

ฟังก์ชั่นในไลบารี่ 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

ฟังก์ชั่นในไลบารี่ Keypad.h http://playground.arduino.cc/Code/Keypad
-begin(
-waitForKey()
-getKey()
-getState()
-keyStateChanged()
-setHoldTime()
-setDebounceTime()
-addEventListener()

ฟังก์ชั่นที่ใช้งาน
-pinMode() http://arduino.cc/en/Reference/PinMode
-digitalWrite() http://arduino.cc/en/Reference/DigitalWrite
-delay() http://arduino.cc/en/reference/delay

*หมายเหตุ จากการทดลองไลบรารี่ keypad เมื่อใช้ขา D13 จะทำให้ไม่สามารถใช้งานได้ ดังนั้นเวลาใช้งานขา D13 จึงห้ามใช้

โจทย์การทดลอง
-เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล 7 segment MAX7219
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)

วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino


วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)


บริเวณใช้งานบอร์ดทดลอง


โมดูลสำเร็จรูปเพิ่มเติม
Keypad
http://www.arduinoall.com (คลิก)

MAX7219 7 Segment
http://www.arduinoall.com (คลิก)


ตำแหน่งขาต่อของคีย์แพด


ตัวอย่างโปรแกรมรับค่าจากคีย์แพด
โค๊ด: [Select]
#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
โค๊ด: [Select]
#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);
}
« แก้ไขครั้งสุดท้าย: มิถุนายน 27, 2017, 09:54:37 PM โดย admin »