diff --git a/LedKeypad.cpp b/LedKeypad.cpp index 249e9a1..f88cc7d 100644 --- a/LedKeypad.cpp +++ b/LedKeypad.cpp @@ -1,45 +1,83 @@ -/*! -* @file LedKeypad.cpp -* @brief LedKeypad.cpp LedKeypad.cpp Prepared for the LedKeypad library function for displaying numbers and letters -* -* LedKeypad.cpp Prepared for the LedKeypad library function for displaying numbers and letters -* -* @author linfeng(490289303@qq.com) -* @version V1.0 -* @date 2015-12-11 -*/ #include "LedKeypad.h" +#include + +char LedKeypad::onlineTime[2]={0,0}; ///< time:onlineTime[0],minute time_online[1]hour +uint8_t LedKeypad::dotFlag = 0; ///< +uint8_t LedKeypad::brightness = 0; ///5){ - lastTime=nowTime; - keyNumber=keyRead(); - if(keyNumber){ - keyCount++; - if(keyCount==10)keyOk=keyNumber; - if(keyCount>10)keyCount=11; - }else{ - keyCount=0; - } + lastTime=nowTime; + keyNumber=keyRead(); + if(keyNumber){ + keyCount++; + if(keyCount==10)keyOk=keyNumber; + if(keyCount>10)keyCount=11; + }else{ + keyCount=0; + } } return(keyOk); } @@ -224,18 +261,29 @@ char LedKeypad::getKey(void) */ char LedKeypad::letterTransform(char letter) { - - if(letter < 10){ - return letter; - }else if(letter <= 45){ - return 16; - }else if(letter<58){ - return(letter-48); - }else if(letter<91){ - return(letter-55); - }else if(letter < 123){ - return(letter-87); - } + + if(letter == 32){ + return 35; //Z no char + } else if(letter == 42){ + return 36; + }else if(letter == 45){ + return 37; + }else if(letter == 95){ + return 38; + }else if(letter == 39){ + return 39; + }else if(letter == 34){ + return 40; + }else if(letter < 10){ + return letter; + }else if(letter<58){ + return(letter-48); + }else if(letter<91){ + return(letter-55); + }else if(letter < 123){ + return(letter-87); + } + } /*! * @brief Display data @@ -246,16 +294,16 @@ char LedKeypad::letterTransform(char letter) */ void LedKeypad::display(int data) { - char number[4]; - ledByteVal_[0] = data/1000; - data %= 1000; - ledByteVal_[1] = data/100; - data %= 100; - ledByteVal_[2]=data/10; - ledByteVal_[3]=data%10; - for(int i=0;i<4;i++){ - display(i,ledByteVal_[i]); - } + char number[4]; + ledByteVal_[0] = data/1000; + data %= 1000; + ledByteVal_[1] = data/100; + data %= 100; + ledByteVal_[2]=data/10; + ledByteVal_[3]=data%10; + for(int i=0;i<4;i++){ + display(i,ledByteVal_[i]); + } } /*! * @brief Display character @@ -264,19 +312,18 @@ void LedKeypad::display(int data) * * @return void */ -void LedKeypad::display(int addr,char data) +void LedKeypad::display(uint8_t addr,char data) { - unsigned char i = 1; - i <<= addr; - data = letterTransform(data); - Serial.println(dotFlag); - ledByteVal_[addr]=data; - if(i&dotFlag){ - tm1650Send(ledByte[addr],ledVal[data]+0x80); - }else{ - tm1650Send(ledByte[addr],ledVal[data]); - } - + unsigned char i = 1; + i <<= addr; + data = letterTransform(data); + ledByteVal_[addr]=data; + if(i&dotFlag){ + tm1650Send(ledByte[addr],getLedVal(data)|0x80); + }else{ + tm1650Send(ledByte[addr],getLedVal(data)); + } + } /*! * @brief Display string @@ -287,14 +334,20 @@ void LedKeypad::display(int addr,char data) */ void LedKeypad::display(const char* buf_) { - for(int i=0;i<4;i++){ - ledByteVal_[i] = *buf_++; - display(i,ledByteVal_[i]); - ledByteVal_[i] = letterTransform(ledByteVal_[i]); - tm1650Send(ledByte[i],ledVal[ledByteVal_[i]]); - } + for(int i=0;i<4;i++){ + ledByteVal_[i] = *buf_++; + display(i,ledByteVal_[i]); + } +} + +void LedKeypad::clear() +{ + for(int i=0;i<4;i++){ + tm1650Send(ledByte[i],0x00); + } } + LedKeypad ledkeypad; diff --git a/LedKeypad.h b/LedKeypad.h index 9bcdf21..f3684c5 100644 --- a/LedKeypad.h +++ b/LedKeypad.h @@ -7,18 +7,28 @@ * @author linfeng(490289303@qq.com) * @version V1.0 * @date 2015-12-11 +* +* alex at AgroMe.com 2021-09-23: +* - extended charset to full latin ascii alphabet +* - some useful special chars +* - changed RAM char table to PROGMEM +* - added a clear method to clear and shut off display +* - changed unsigned char to uint8_t for portability, clarity and avoid confusion with char +* - more re-use of the display(uint8_t addr,char data) method to simplify code +* - tabs to spaces +* - added README */ #ifndef __LedKeypad__H #define __LedKeypad__H #include "Arduino.h" -#define KEY_DOWN 1 -#define KEY_LEFT 2 -#define KEY_UP 3 -#define KEY_RIGHT 4 -#define KEY_SELECT 5 -#define KEY_NULL 0 +#define KEY_DOWN 1 +#define KEY_LEFT 2 +#define KEY_UP 3 +#define KEY_RIGHT 4 +#define KEY_SELECT 5 +#define KEY_NULL 0 class LedKeypad @@ -26,38 +36,37 @@ class LedKeypad public: LedKeypad(){}; void begin(void); - char keyRead(void); + uint8_t keyRead(void); char getKey(void); void clrKey(void); char letterTransform(char letter); void tm1650Begin(void); void tm1650Stop(void); - void tm1650Write(unsigned char oneByte); - void tm1650Send(unsigned char addr,unsigned char data); - void setBrightness(unsigned char brightness); + void tm1650Write(uint8_t oneByte); + void tm1650Send(uint8_t addr,uint8_t data); + void setBrightness(uint8_t brightness); void display(int data); - void display(int addr,char data); + void display(uint8_t addr,char data); void display(const char* buf_); - void dotShow(char temp); - void dotVanish(char temp); - + void dotShow(uint8_t addr); + void dotVanish(uint8_t addr); + void clear(); + unsigned char getLedVal(unsigned char ch); + private: #define SCL_pin 19 #define SDA_pin 18 - unsigned char keyOk; - unsigned char keyCount; + uint8_t keyOk; + uint8_t keyCount; char ledByteVal_[4]; ///. Contact: 490289303@qq.com ******************************************************************************/ - \ No newline at end of file + diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cefe34 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# LedKeypad +Library to drive DFRobot DFR0382 Shield for Arduino + +Supports full Latin alphabet per ASCII namely: +* 0-9 +* A-Z +* a-z + +With some exceptions given limitations of 7-segment. These will be blank: +* K or k +* M or m +* V,W,X and Z + +These special characters are provided: +* \* will display the degree symbol º +* \- will display the dash +* _ will display the underscore +* ' will display a single quote +* " will display a double quote + +See example code for actual usage. + +# Author +linfeng(490289303@qq.com)\ +Original version V1.0\ +Date 2015-12-11 + +# Contributions and Changes +Alejandro Imass\ +Version 1.1 +Date 2021-09-23 +* extended charset to full latin ascii alphabet +* some useful special chars +* changed RAM char table to PROGMEM +* added a clear method to clear and shut off display +* changed unsigned char to uint8_t for portability, clarity and avoid confusion with char +* more re-use of the display(uint8_t addr,char data) method to simplify code +* tabs to spaces +* added README \ No newline at end of file