|
收到了L大送來的禮物. 很潦草地隨便測試一下, 準備繼續改良做玩具, 目的是測試在單電池供電可否運作, 結果是OK. 20mA-40mA, 比較耗電, 不過3.5V-4.2還是正常運作. ARDUINO 已經拆除 5V 穩壓IC, 不需要, 不然更耗電, 原因不詳. 要自行控制寫特殊符號, 例如 r, 口, 等字符, 還沒研究出來. 有空再來.
test lgc12002
接線圖
test lgc12002
接線圖再放大一點, 這樣接, 麵包板最有條理
test lgc12002
測試碼, 抄來的
Arduino skectch
- #include <PT6961.h>
- // Pin 4 = CS
- // Pin 3 = CLK
- // Pin 2 = DIN
- PT6961 LED(2, 3, 4);
- void setup()
- {
- LED.initDisplay();
- LED.sendCmd(0x8a); // (_DISPLAY_4_16); // dim LED display 1/4
- Serial.begin(9600);
- }
-
- void loop()
- {
- //count through 0-9,a-f
- for(int i=0; i<16; i++)
- {
- LED.sendDigits(0,0,0,i,0);
- Serial.println(i);
- delay(1000);
- }
- }
複製代碼
PT6961.cpp
- /*
- PT6961.cpp - Library for communicating with PT6961 LED driver.
- Created by Garrett Blanton January, 16, 2013.
- Released into the public domain.
- */
- //0 - A
- //1 - B
- //2 - C
- //3 - D
- //4 - E
- //5 - F
- //6 - G
- //7 - Colon
- #include "Arduino.h"
- #include "PT6961.h"
- PT6961::PT6961(int DIN, int CLK, int CS)
- {
- pinMode(DIN, OUTPUT);
- pinMode(CLK, OUTPUT);
- pinMode(CS, OUTPUT);
- _DIN = DIN;
- _CLK = CLK;
- _CS = CS;
- }
- void PT6961::initDisplay()
- {
- sendCmd(_DISPLAY_6X12);
- sendCmd(_AUTO_INCREMENT);
- initRAM();
- sendCmd(_DISPLAY_14_16);
- }
- // Initializes RAM to all zeros
- void PT6961::initRAM()
- {
- //first clear 8 bytes of the display RAM
- digitalWrite(_CS,LOW);
- shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
- for(int i=0; i<8; i++){
- shiftOut(_DIN, _CLK, LSBFIRST, 0x00);
- }
- digitalWrite(_CS,HIGH);
- }
- // Use to send command based on enumeration
- void PT6961::sendCmd(char cmd)
- {
- digitalWrite(_CS,LOW);
- shiftOut(_DIN, _CLK, LSBFIRST, cmd);
- digitalWrite(_CS,HIGH);
- }
- void PT6961::sendDigit(char digit, char val)
- {
- digitalWrite(_CS,LOW);
- shiftOut(_DIN, _CLK, LSBFIRST, digit);
- shiftOut(_DIN, _CLK, LSBFIRST, val);
- digitalWrite(_CS,HIGH);
- }
- void PT6961::sendNum(int num, char colon)
- {
- int digit1 = num / 1000;
- int digit2 = (num % 1000) / 100;
- int digit3 = (num % 100) / 10;
- int digit4 = (num % 10);
-
- sendDigits(digit1,digit2,digit3,digit4,colon);
- }
- void PT6961::sendDigits(char digit1, char digit2, char digit3, char digit4, char colon)
- {
- const char DISP[17] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x58, 0x5e, 0x79, 0x71, 0x61};
-
- digitalWrite(_CS,LOW);
- shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
-
- if(colon == 1)
- {
- shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit1] | 0x80);
- }
- else
- {
- shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit1]);
- }
- shiftOut(_DIN, _CLK, LSBFIRST, 0xC2);
- if(colon == 1)
- {
- shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit2] | 0x80);
- }
- else
- {
- shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit2]);
- }
-
- shiftOut(_DIN, _CLK, LSBFIRST, 0xC4);
- shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit3]);
- shiftOut(_DIN, _CLK, LSBFIRST, 0xC6);
- shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit4]);
- digitalWrite(_CS,HIGH);
- }
複製代碼
PT6961.h
- /*
- PT6961.h - Library for communicating with PT6961 LED driver.
- Created by Garrett Blanton January, 16, 2013.
- Released into the public domain.
- */
- #ifndef PT6961_h
- #define PT6961_h
- #include "Arduino.h"
- class PT6961
- {
- public:
-
- PT6961(int DIN, int CLK, int CS);
- void initDisplay();
- void initRAM();
- void sendCmd(char cmd);
- void sendDigit(char digit, char val);
- void sendNum(int num, char colon);
- void sendDigits(char digit1, char digit2, char digit3, char digit4, char colon);
-
- const static char _DISPLAY_6X12 = 0x02;
- const static char _DISPLAY_7X11 = 0x03;
- const static char _AUTO_INCREMENT = 0x40;
- const static char _FIXED_ADDRESS = 0x44;
- const static char _DISPLAY_OFF = 0x80;
- const static char _DISPLAY_1_16 = 0x88;
- const static char _DISPLAY_2_16 = 0x89;
- const static char _DISPLAY_4_16 = 0x8A;
- const static char _DISPLAY_10_16 = 0x8B;
- const static char _DISPLAY_11_16 = 0x8C;
- const static char _DISPLAY_12_16 = 0x8D;
- const static char _DISPLAY_13_16 = 0x8E;
- const static char _DISPLAY_14_16 = 0x8F;
-
- private:
-
- int _DIN;
- int _CLK;
- int _CS;
-
- };
- #endif
複製代碼
|
|