diff --git a/README.md b/README.md index ffca25b..71c209e 100644 --- a/README.md +++ b/README.md @@ -5,30 +5,20 @@ ## Introduction of sensor Grove - alphanumeric Digital Tubes Display,Based on HT16K33,it can display number,and scrolling displaying. -**Support dual(two tubes)&qual(four tubes) alphanumeric Digital Tubes simultaneously.** -*** - -## Usage: -Download all the source files. -There are four examples for user to use. ->* **example/display_custom_4/display_custom_4.ino**.Only support for qual(four tubes) alphanumeric Digital Tubes. ->* **example/display_scroll_string/display_scroll_string.ino**:Display scrolling string which longer than 2(4).Support dual(two tubes)&qual(four tubes) alphanumeric Digital Tubes simultaneously ->* **example/display_scroll_number/display_scroll_number.ino**:Display scrolling number which bigger than 99(9999).Support dual(two tubes)&qual(four tubes) alphanumeric Digital Tubes simultaneously. ->* **example/display_basic/display_basic.ino**:Basic static display demo.Support dual(two tubes)&qual(four tubes) alphanumeric Digital Tubes simultaneously ->* **example/number_increment_2/number_increment_2.ino**,Only support for dual(two tubes) alphanumeric Digital Tubes. - ----- - -## select type of alphanumeric Digital Tubes Display -**You can switch dual/qual alphanumeric Digital Tubes Display by change the micro in every example.** +### Notice: +* Support dual(two tubes)&qual(four tubes) alphanumeric Digital Tubes simultaneously. use following API to select the type of display. ``` -//#define DUAL_NUMERIC -``` + tube.setTubeType(TYPE_4,I2C_ADDR_AFTER_CHANGE_FOUR); +``` +or + +``` + tube.setTubeType(TYPE_2,TYPE_2_DEFAULT_I2C_ADDR); +``` +* The example : < combine_two_displays.ino > shows how to combine two displays in one project. -comment it ,using qual alphanumeric Digital Tubes Display,otherwise ,using dual alphanumeric Digital Tubes Display. -**defaule using qual alphanumeric Digital Tubes Display** *** diff --git a/examples/combine_two_displays/combine_two_displays.ino b/examples/combine_two_displays/combine_two_displays.ino new file mode 100644 index 0000000..41e2b0a --- /dev/null +++ b/examples/combine_two_displays/combine_two_displays.ino @@ -0,0 +1,51 @@ +#include + +#include "grove_alphanumeric_display.h" + +Seeee_Digital_Tube tube1; +Seeee_Digital_Tube tube2; + +/** + * NOTICE:Every tubes display has the same default i2c address. + * if you want to combine two(or more)display in one project,you should change the i2c + * i2c address,by soldering the pad of display backside. + * please refer to our wiki to get more details. + * */ +#define I2C_ADDR_AFTER_CHANGE_FOUR 0x75 +#define I2C_ADDR_DEFAULT_FOUR 0x71 + + + +void setup() +{ + Wire.begin(); + + // If using four digital tubes, use this configuration. + tube1.setTubeType(TYPE_4,I2C_ADDR_AFTER_CHANGE_FOUR); + + tube1.setBrightness(15); + tube1.setBlinkRate(BLINK_OFF); + + // If using four digital tubes, use this configuration. + tube2.setTubeType(TYPE_4,I2C_ADDR_DEFAULT_FOUR); + + tube2.setBrightness(15); + tube2.setBlinkRate(BLINK_OFF); + +} + + +void loop() +{ + tube1.displayNum(1234); + delay(100); + + tube2.displayNum(5678); + delay(100); + + while(1); +} + + + + diff --git a/examples/display_basic/display_basic.ino b/examples/display_basic/display_basic.ino index 747a89f..f0e542f 100644 --- a/examples/display_basic/display_basic.ino +++ b/examples/display_basic/display_basic.ino @@ -30,48 +30,39 @@ */ #include +#include "grove_alphanumeric_display.h" -//#define DUAL_NUMERIC - -#ifdef DUAL_NUMERIC - #include "grove_dual_alphanumeric_display.h" - #define NUMERIC_I2C_ADDR 0x70 - Digital_Tube2 tube; -#else - #include "grove_quad_alphanumeric_display.h" - #define NUMERIC_I2C_ADDR 0x71 - Digital_Tube4 tube; -#endif - +Seeee_Digital_Tube tube; void setup() { Wire.begin(); - tube.init(NUMERIC_I2C_ADDR); + + // If using four digital tubes, use this configuration. + tube.setTubeType(TYPE_4,TYPE_4_DEFAULT_I2C_ADDR); + + // If using two digital tubes, use this configuration. + // tube.setTubeType(TYPE_2,TYPE_2_DEFAULT_I2C_ADDR); + tube.setBrightness(15); tube.setBlinkRate(BLINK_OFF); + } void loop() { - #ifdef DUAL_NUMERIC - tube.display_two_tube('.','C'); - delay(1000); - tube.displayNum(23,0); - delay(1000); - tube.displayString("AB",0); - delay(1000); - - #else - tube.displayNum(123); - delay(2000); - tube.displayNum(4567); - delay(2000); - tube.displayString("ABCD"); - delay(2000); - tube.displayString("abcd"); + + tube.displayNum(12); delay(2000); - #endif + tube.displayNum(4567,500); + delay(2000); + + tube.displayString("AB",500); + delay(2000); + + tube.displayString("abcd",500); + delay(2000); + } \ No newline at end of file diff --git a/examples/display_custom_4/display_custom_4.ino b/examples/display_custom/display_custom.ino similarity index 79% rename from examples/display_custom_4/display_custom_4.ino rename to examples/display_custom/display_custom.ino index 709f47c..610695e 100644 --- a/examples/display_custom_4/display_custom_4.ino +++ b/examples/display_custom/display_custom.ino @@ -34,19 +34,26 @@ /*********************************************************/ /*****NOTICE : This example only for qual_alphanumeric****/ /*********************************************************/ -#include "grove_quad_alphanumeric_display.h" -#define NUMERIC_I2C_ADDR 0x71 +#include "grove_alphanumeric_display.h" -Digital_Tube4 tube; +Seeee_Digital_Tube tube; void setup() { Wire.begin(); - tube.init(NUMERIC_I2C_ADDR); + + // If using two digital tubes, use this configuration. + // tube.setTubeType(TYPE_2,TYPE_2_DEFAULT_I2C_ADDR); + + // If using four digital tubes, use this configuration. + tube.setTubeType(TYPE_4,TYPE_4_DEFAULT_I2C_ADDR); + + tube.setBrightness(15); tube.setBlinkRate(BLINK_1HZ); + } @@ -55,9 +62,15 @@ void displayCustom() tube.clearBuf(); tube.setTubeSingleChar(FIRST_TUBE,'t'); tube.setTubeSingleChar(SECOND_TUBE,'T'); + + //if using two digital tubes,there's no third&fourth channel. + tube.setTubeSingleNum(THIRD_TUBE,5); tube.setTubeSingleNum(FOURTH_TUBE,5); - tube.setPoint(true,true); + + // The location of point is different between two&four digital tubes. + tube.setPoint(true,false); + tube.display(); } diff --git a/examples/display_scroll_number/display_scroll_number.ino b/examples/display_scroll_number/display_scroll_number.ino index fecd441..979b26d 100644 --- a/examples/display_scroll_number/display_scroll_number.ino +++ b/examples/display_scroll_number/display_scroll_number.ino @@ -29,24 +29,23 @@ * THE SOFTWARE. */ #include +#include "grove_alphanumeric_display.h" -//#define DUAL_NUMERIC -#ifdef DUAL_NUMERIC - #include "grove_dual_alphanumeric_display.h" - #define NUMERIC_I2C_ADDR 0x70 - Digital_Tube2 tube; -#else - #include "grove_quad_alphanumeric_display.h" - #define NUMERIC_I2C_ADDR 0x71 - Digital_Tube4 tube; -#endif +Seeee_Digital_Tube tube; + void setup() { Wire.begin(); - tube.init(NUMERIC_I2C_ADDR); + + // If using two digital tubes, use this configuration. + // tube.setTubeType(TYPE_2,TYPE_2_DEFAULT_I2C_ADDR); + + // If using four digital tubes, use this configuration. + tube.setTubeType(TYPE_4,TYPE_4_DEFAULT_I2C_ADDR); + tube.setBrightness(15); tube.setBlinkRate(BLINK_OFF); } diff --git a/examples/display_scroll_string/display_scroll_string.ino b/examples/display_scroll_string/display_scroll_string.ino index 26fe338..79f6e88 100644 --- a/examples/display_scroll_string/display_scroll_string.ino +++ b/examples/display_scroll_string/display_scroll_string.ino @@ -29,24 +29,22 @@ * THE SOFTWARE. */ #include +#include "grove_alphanumeric_display.h" -//#define DUAL_NUMERIC +Seeee_Digital_Tube tube; -#ifdef DUAL_NUMERIC - #include "grove_dual_alphanumeric_display.h" - #define NUMERIC_I2C_ADDR 0x70 - Digital_Tube2 tube; -#else - #include "grove_quad_alphanumeric_display.h" - #define NUMERIC_I2C_ADDR 0x71 - Digital_Tube4 tube; -#endif void setup() { Wire.begin(); - tube.init(NUMERIC_I2C_ADDR); + + // If using two digital tubes, use this configuration. + // tube.setTubeType(TYPE_2,TYPE_2_DEFAULT_I2C_ADDR); + + // If using four digital tubes, use this configuration. + tube.setTubeType(TYPE_4,TYPE_4_DEFAULT_I2C_ADDR); + tube.setBrightness(15); tube.setBlinkRate(BLINK_OFF); } @@ -55,6 +53,6 @@ void setup() void loop() { - tube.displayString("ABCDEFGHJIYZ",500); + tube.displayString("ABCDEFGHIJK",500); delay(1000); } \ No newline at end of file diff --git a/examples/number_increment_2/number_increment_2.ino b/examples/number_increment/number_increment.ino similarity index 85% rename from examples/number_increment_2/number_increment_2.ino rename to examples/number_increment/number_increment.ino index 8c54a1d..c8eb64c 100644 --- a/examples/number_increment_2/number_increment_2.ino +++ b/examples/number_increment/number_increment.ino @@ -29,21 +29,23 @@ * THE SOFTWARE. */ #include -#include "grove_dual_alphanumeric_display.h" +#include "grove_alphanumeric_display.h" -/*********************************************************/ -/*****NOTICE : This example only for dual_alphanumeric****/ -/*********************************************************/ -#define NUMERIC_I2C_ADDR 0x70 +Seeee_Digital_Tube tube; -Digital_Tube2 tube; -char hex_str[255] = {0}; +char hex_str[10]; void setup() { Wire.begin(); - tube.init(NUMERIC_I2C_ADDR); + + // If using two digital tubes, use this configuration. + // tube.setTubeType(TYPE_2,TYPE_2_DEFAULT_I2C_ADDR); + + // If using four digital tubes, use this configuration. + tube.setTubeType(TYPE_4,TYPE_4_DEFAULT_I2C_ADDR); + tube.setBrightness(15); tube.setBlinkRate(BLINK_OFF); @@ -79,6 +81,6 @@ void loop() for(int i=0;i<0xff;i++) { tube.displayString(numToHexString(i),0); - delay(300); + delay(100); } } \ No newline at end of file diff --git a/grove_quad_alphanumeric_display.cpp b/grove_alphanumeric_display.cpp similarity index 50% rename from grove_quad_alphanumeric_display.cpp rename to grove_alphanumeric_display.cpp index 60a7400..cf7cd42 100644 --- a/grove_quad_alphanumeric_display.cpp +++ b/grove_alphanumeric_display.cpp @@ -1,6 +1,6 @@ /* - * grove_quad_alphanumeric_display.cpp - * A library for Grove - grove_quad_alphanumeric_display + * grove_alphanumeric_display.cpp + * A library for Grove - grove_alphanumeric_display * * Copyright (c) 2018 seeed technology inc. * Website : www.seeed.cc @@ -36,29 +36,11 @@ * THE SOFTWARE. */ -#include "grove_quad_alphanumeric_display.h" +#include "grove_alphanumeric_display.h" #include "Wire.h" -Digital_Tube4::Digital_Tube4() -{ - _orientation = DISPLAY_ROTATE_0; - _offset_x = 0; - _offset_y = 0; - _cursor_start = 0; - _cursor_end = 0; - _cursor_steps = 1; - _ms = 100; -} - -bool Digital_Tube4::isLegalToDisplay(char byte) -{ - if( !((byte >= '.' && byte <= '9') || (byte >= 'A' && byte <= 'Z') || (byte >= 'a' && byte <= 'z') ) ) - return false; - return true; -} - -uint16_t g_display_font[]={ +uint16_t g_display_font4[]={ // 0x0000, // display nothing. 0x0080, // 'upper .' 0x2000, // 'lower .' @@ -103,12 +85,82 @@ uint16_t g_display_font[]={ +#define LAST_ITEM 38 +uint16_t g_display_font2[]={ + // 0x0000, // display nothing. + 0x4000, // '.' + 0x0000, // '/' display nothing. + 0xa145, // '0' + 0x8001, // '1' + 0x3107, // '2' + 0xb007, // '3' + 0x9043, // '4' + 0xb046, // '5' + 0xb146, // '6' + 0x8005, // '7' + 0xb147, // '8' + 0xb047, // '9' + 0x9147, // 'A' + 0xb415, // 'B' + 0x2144, // 'C' + 0xa415, // 'D' + 0x3146, // 'E' + 0x1146, // 'F' + 0xb144, // 'G' + 0x9143, // 'H' + 0x2414, // 'I' + 0xA101, // 'J' + 0x0c18, // 'K' + 0x2140, // 'L' + 0x8169, // 'M' + 0x8961, // 'N' + 0xa145, // 'O' + 0x1147, // 'P' + 0xa945, // 'Q' + 0x1947, // 'R' + 0x2824, // 'S' + 0x0414, // 'T' + 0xa141, // 'U' + 0x8821, // 'V' + 0x8b41, // 'W' + 0x0a28, // 'X' + 0x0428, // 'Y' + 0x220c, // 'Z' + 0x0000, // ilegal num +}; + + +Seeee_Digital_Tube::Seeee_Digital_Tube() +{ + + _ms = 100; +} + + +void Seeee_Digital_Tube::setTubeType(TubeType_t type,uint8_t addr) +{ + _type = type; + (_type == TYPE_2) ? (_tube_cnt = CNT_2) : (_tube_cnt = CNT_4); + (_type == TYPE_2) ? (disp_font_p = g_display_font2) : (disp_font_p = g_display_font4); + HT16K33::init(addr); +} + +bool Seeee_Digital_Tube::isLegalToDisplay(char byte) +{ + if( !((byte >= '.' && byte <= '9') || (byte >= 'A' && byte <= 'Z') || (byte >= 'a' && byte <= 'z') ) ) + return false; + return true; +} + + + + /**@brief Display number,If the param-num's len less than 4(or equal to),The tubes display static number,otherwise,it displays scroll number. * When it displays scroll number,the param interval is scrolling interval(ms) .. * @param num the number to display. * @param interval :the interval of scroll number. * */ -void Digital_Tube4::displayNum(uint32_t num,uint32_t interval) +void Seeee_Digital_Tube::displayNum(uint32_t num,uint32_t interval) { char num_str[15] = {0}; sprintf(num_str,"%ld",(uint32_t)num); @@ -117,15 +169,20 @@ void Digital_Tube4::displayNum(uint32_t num,uint32_t interval) -void Digital_Tube4::shiftDisplay(char *origin_disp_buf,char new_item) +void Seeee_Digital_Tube::shiftDisplay(char *origin_disp_buf,char new_item) { - char temp[TUBE_COUNT] = {0}; - memcpy(temp,&origin_disp_buf[1],TUBE_COUNT-1); - temp[TUBE_COUNT-1] = new_item; - memcpy(origin_disp_buf,temp,TUBE_COUNT); - for(int i =0;i< TUBE_COUNT;i++) + char temp[MAX_TUBE_COUNT] = {0}; + + memcpy(temp,&origin_disp_buf[1],_tube_cnt - 1); + + temp[_tube_cnt-1] = new_item; + + memcpy(origin_disp_buf,temp,_tube_cnt); + + for(int i =0;i< _tube_cnt;i++) { - setTubeBuf((TubeNum_4)(i+1),g_display_font[get_char_index(temp[i])]); + setTubeBuf((TubeNum)(i+1),temp[i]); + } writeBytes(_addr, 0x00, 16, _buffer); delay(_ms); @@ -136,36 +193,44 @@ void Digital_Tube4::shiftDisplay(char *origin_disp_buf,char new_item) * @param str the str to display. * @param interval :the interval of scroll string. * */ -void Digital_Tube4::displayString(char *str,uint32_t interval) +void Seeee_Digital_Tube::displayString(char *str,uint32_t interval) { - char first_tube_byte = 0,second_tube_byte = 0; int len = 0; clearBuf(); + len = strlen(str); - if(TUBE_COUNT >= len) + + if(_tube_cnt >= len) { for(int i=0;i 255 ) len = 255; - char origin_disp_buf[TUBE_COUNT]={0}; + char origin_disp_buf[MAX_TUBE_COUNT]={0}; + for(int i=0;i>8; + if( TYPE_4 == _type ) + { + //upper dot control + if(first_dot){ + _buffer[10] |= disp_font_p[0]; + _buffer[11] |= disp_font_p[0]>>8; + } + //lower dot control + if(second_dot){ + _buffer[10] |= disp_font_p[1]; + _buffer[11] |= disp_font_p[1]>>8; + } } - if(lower_on){ - _buffer[10] |= g_display_font[1]; - _buffer[11] |= g_display_font[1]>>8; + else if (TYPE_2 == _type) + { + if(first_dot) + _buffer[SECOND_TUBE*2] |= disp_font_p[0] >> 8; + + if(second_dot) + + _buffer[FIRST_TUBE*2] |= disp_font_p[0] >> 8; } + else{} } -void Digital_Tube4::setTubeBuf(TubeNum_4 tube_num,uint16_t value) +void Seeee_Digital_Tube::setTubeBuf(TubeNum tube_num,char byte) { + uint16_t value = disp_font_p[get_char_index(byte)]; + + if( TYPE_4 == _type ) + { + + + _buffer[tube_num*2] = value; + _buffer[tube_num*2+1] = value >> 8; + replace_bit12(tube_num,value&0x02,value&0x04); + } + else if (TYPE_2 == _type) + { + if(false == isLegalToDisplay(byte)) + { + byte = '/'; + } + //if first,set to 2,if second ,set to 1. To compatible with the hardware. + tube_num = (TubeNum) (((int)tube_num+1) & (~(int)tube_num)); + + if(byte >= 'a' && byte <= 'z') + { + byte -= 32; + } + + if((byte >='.' && byte <= '9')) + { + _buffer[tube_num*2] = disp_font_p[byte-'0'+2] >> 8; + _buffer[tube_num*2+1] = disp_font_p[byte-'0'+2]; + } + else + { + _buffer[tube_num*2] = disp_font_p[byte-'A'+10+2] >> 8; + _buffer[tube_num*2+1] = disp_font_p[byte-'A'+10+2]; + } + } - _buffer[tube_num*2] = value; - _buffer[tube_num*2+1] = value >> 8; - replace_bit12(tube_num,value&0x02,value&0x04); } + + /**@brief Specify the display char of a digital tube. * @param tube_num The number of tube ,total 4. * @param c ,The char to display * */ -void Digital_Tube4::setTubeSingleChar(TubeNum_4 tube_num,char c) +void Seeee_Digital_Tube::setTubeSingleChar(TubeNum tube_num,char c) { - if(!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) ) + if(!( ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || (c=='.') ) ) { return ; } - uint16_t value = g_display_font[get_char_index(c)]; - _buffer[tube_num*2] = value; - _buffer[tube_num*2+1] = value >> 8; - replace_bit12(tube_num,value&0x02,value&0x04); + if( TYPE_4 == _type ) + { + setTubeBuf(tube_num , c); + } + else if (TYPE_2 == _type) + { + if(tube_num > SECOND_TUBE) + return; + + setTubeBuf(tube_num ,c); + } + else + { + } } /**@brief Specify the display number of a digital tube. * @param tube_num The number of tube ,total 4. * @param num ,The number to display * */ -void Digital_Tube4::setTubeSingleNum(TubeNum_4 tube_num,char num) +void Seeee_Digital_Tube::setTubeSingleNum(TubeNum tube_num,char num) { if( !((num >= 0) && (num <= 9)) ) return ; - uint16_t value = g_display_font[get_char_index(num+0x30)]; - _buffer[tube_num*2] = value; - _buffer[tube_num*2+1] = value >> 8; - replace_bit12(tube_num,value&0x02,value&0x04); + if( TYPE_4 == _type ) + { + setTubeBuf(tube_num , num + 0x30); + } + else if (TYPE_2 == _type) + { + if(tube_num > SECOND_TUBE) + return; + + setTubeBuf(tube_num ,num + 0x30); + } + else + { + } + } -void Digital_Tube4::display_one_tube(TubeNum_4 tube_num,uint16_t value) +void Seeee_Digital_Tube::display_one_tube(TubeNum tube_num,uint16_t value) { _buffer[tube_num*2] = value; _buffer[tube_num*2+1] = value >> 8; @@ -270,12 +421,12 @@ void Digital_Tube4::display_one_tube(TubeNum_4 tube_num,uint16_t value) } -void Digital_Tube4::clearBuf() +void Seeee_Digital_Tube::clearBuf() { memset(_buffer,0,sizeof(_buffer)); } -int Digital_Tube4::get_char_index(char c) +int Seeee_Digital_Tube::get_char_index(char c) { if((c >= '0') && (c <= '9')) { @@ -291,28 +442,18 @@ int Digital_Tube4::get_char_index(char c) } else { - return '/'+2; + return LAST_ITEM; } } - -void Digital_Tube4::display() +void Seeee_Digital_Tube::display() { writeBytes(_addr, 0x00, 16, _buffer); delay(_ms); } -/* -bool HT16K33::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t* data) -{ - Wire.beginTransmission(devAddr); - Wire.write((uint8_t) regAddr); - for (uint8_t i = 0; i < length; i++) { - Wire.write((uint8_t) data[i]); - } - Wire.endTransmission(); -} -*/ + + diff --git a/grove_quad_alphanumeric_display.h b/grove_alphanumeric_display.h similarity index 76% rename from grove_quad_alphanumeric_display.h rename to grove_alphanumeric_display.h index 83aa92c..09faf36 100644 --- a/grove_quad_alphanumeric_display.h +++ b/grove_alphanumeric_display.h @@ -1,6 +1,6 @@ /* - * grove_quad_alphanumeric_display.h - * A library for Grove - grove_quad_alphanumeric_display + * grove_alphanumeric_display.h + * A library for Grove - grove_alphanumeric_display * * Copyright (c) 2018 seeed technology inc. * Website : www.seeed.cc @@ -43,10 +43,15 @@ #include #include "HT16K33_driver.h" -#define HT16K33_DEFAULT_I2C_ADDR 0x71 +// #define TYPE_4_DEFAULT_I2C_ADDR 0x75 +#define TYPE_4_DEFAULT_I2C_ADDR 0x71 +#define TYPE_2_DEFAULT_I2C_ADDR 0x70 + #define MAX_BIG_BUFFER_SIZE (8*20) -#define TUBE_COUNT 4 +#define MAX_TUBE_COUNT 4 + + typedef enum { @@ -54,13 +59,25 @@ typedef enum SECOND_TUBE, THIRD_TUBE, FOURTH_TUBE, -}TubeNum_4; +}TubeNum; + +typedef enum{ + TYPE_2, + TYPE_4, +}TubeType_t; -class Digital_Tube4 : public HT16K33 { +typedef enum{ + CNT_2 = 2, + CNT_4 = 4, +}TubeCnt_t; + +class Seeee_Digital_Tube : public HT16K33 { public: - Digital_Tube4(); + Seeee_Digital_Tube(); + + void setTubeType(TubeType_t type,uint8_t addr = TYPE_2_DEFAULT_I2C_ADDR); void clear(); /**@brief Display number,If the param-num's len less than 4,The tubes display static number,otherwise,it displays scroll number. @@ -82,7 +99,6 @@ public: void fulDisplay(); - /**@brief Clear _buffer,just clear. * * */ @@ -98,34 +114,37 @@ public: * @param tube_num The number of tube ,total 4. * @param num ,The number to display * */ - void setTubeSingleChar(TubeNum_4 tube_num,char c); + void setTubeSingleChar(TubeNum tube_num,char c); /**@brief Specify the display number of a digital tube. * @param tube_num The number of tube ,total 4. * @param num ,The number to display * */ - void setTubeSingleNum(TubeNum_4 tube_num,char num); + void setTubeSingleNum(TubeNum tube_num,char num); /**@brief Set two points status. * @prarm upper_on if true,the upper point light on ,otherwise turn off; * @prarm lower_on if true,the upper point light on ,otherwise turn off; * */ - void setPoint(bool upper_on,bool lower_on); + void setPoint(bool first_dot,bool second_dot); private: - void display_one_tube(TubeNum_4 tube_num,uint16_t value); - void replace_bit12(TubeNum_4 tube_num,bool bit1,bool bit2); - void setTubeBuf(TubeNum_4 tube_num,uint16_t value); + void display_one_tube(TubeNum tube_num,uint16_t value); + void replace_bit12(TubeNum tube_num,bool bit1,bool bit2); + void setTubeBuf(TubeNum tube_num,char byte); int get_char_index(char c); void shiftDisplay(char *origin_disp_buf,char new_item); // Low1 High1 Low2 High2 ... Low8 High8 uint8_t _buffer[16]; - uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE]; - uint16_t _cursor_start, _cursor_end, _cursor_steps; + //uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE]; + //uint16_t _cursor_start, _cursor_end, _cursor_steps; uint16_t _ms; - orientation_type_t _orientation; - int8_t _offset_x, _offset_y; + //orientation_type_t _orientation; + //int8_t _offset_x, _offset_y; bool isLegalToDisplay(char byte); + TubeType_t _type; + TubeCnt_t _tube_cnt; + uint16_t *disp_font_p; }; diff --git a/grove_dual_alphanumeric_display.cpp b/grove_dual_alphanumeric_display.cpp deleted file mode 100644 index 61df3a0..0000000 --- a/grove_dual_alphanumeric_display.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - * grove_dual_alphanumeric_display.cpp - * A library for Grove - dual_alphanumeric_display - * - * Copyright (c) 2018 seeed technology inc. - * Website : www.seeed.cc - * Author : Jerry Yip - * Create Time: 2018-06 - * Version : 0.1 - * Change Log : - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "grove_dual_alphanumeric_display.h" - - -Digital_Tube2::Digital_Tube2() -{ - _orientation = DISPLAY_ROTATE_0; - _offset_x = 0; - _offset_y = 0; - _cursor_start = 0; - _cursor_end = 0; - _cursor_steps = 1; - _ms = 100; -} - -bool Digital_Tube2::isLegalToDisplay(char byte) -{ - if( !((byte >= '.' && byte <= '9') || (byte >= 'A' && byte <= 'Z') ) ) - return false; - return true; -} - -uint16_t g_display_font_2[]={ - // 0x0000, // display nothing. - 0x4000, // '.' - 0x0000, // '/' display nothing. - 0xa145, // '0' - 0x8001, // '1' - 0x3107, // '2' - 0xb007, // '3' - 0x9043, // '4' - 0xb046, // '5' - 0xb146, // '6' - 0x8005, // '7' - 0xb147, // '8' - 0xb047, // '9' - 0x9147, // 'A' - 0xb415, // 'B' - 0x2144, // 'C' - 0xa415, // 'D' - 0x3146, // 'E' - 0x1146, // 'F' - 0xb144, // 'G' - 0x9143, // 'H' - 0x2414, // 'I' - 0xA101, // 'J' - 0x0c18, // 'K' - 0x2140, // 'L' - 0x8169, // 'M' - 0x8961, // 'N' - 0xa145, // 'O' - 0x1147, // 'P' - 0xa945, // 'Q' - 0x1947, // 'R' - 0x2824, // 'S' - 0x0414, // 'T' - 0xa141, // 'U' - 0x8821, // 'V' - 0x8b41, // 'W' - 0x0a28, // 'X' - 0x0428, // 'Y' - 0x220c, // 'Z' - 0x0000, // ilegal num -}; - - -void Digital_Tube2::display_two_tube(char byte1,char byte2) -{ - if(!isLegalToDisplay(byte1)) - { - byte1 = '/'; - } - if(!isLegalToDisplay(byte2)) - { - byte2 = '/'; - } - setDispBuf(FIRST_TUBE,byte1); //The order of tube is reversed - setDispBuf(SECOND_TUBE,byte2); - writeBytes(_addr, 0x00, 16, _buffer); - delay(_ms); -} - - -void Digital_Tube2::setDispBuf(TubeNum_2 num,char byte) -{ - if((byte >='.' && byte <= '9')) - { - _buffer[num*2+2] = g_display_font_2[byte-'0'+2] >> 8; - _buffer[num*2+3] = g_display_font_2[byte-'0'+2]; - } - else - { - _buffer[num*2+2] = g_display_font_2[byte-'A'+10+2] >> 8; - _buffer[num*2+3] = g_display_font_2[byte-'A'+10+2]; - } -} - -/**If the param num <100,The tubes display static number,otherwise,it displays scroll number. - * When it displays scroll number,the param interval is scrolling interval(ms) . - * - * */ - -void Digital_Tube2::displayNum(unsigned long int num,unsigned int interval) -{ - char first_tube_byte = 0,second_tube_byte = 0; - int i = 0; - int high_bit = 0; - char num_array[32] = {0}; - if(num > 99) - { - while(num) - { - num_array[i] = (num % 10)+0x30; - num /= 10; - i++; - } - for(;i >= 2;i-=2) - { - first_tube_byte = num_array[i-1]; - second_tube_byte = num_array[i-2]; - - if(!isLegalToDisplay(first_tube_byte)) - { - first_tube_byte = '/'; - } - if(!isLegalToDisplay(second_tube_byte)) - { - second_tube_byte = '/'; - } - setDispBuf(FIRST_TUBE,first_tube_byte); - setDispBuf(SECOND_TUBE,second_tube_byte); - writeBytes(_addr, 0x00, 16, _buffer); - delay(interval); - - } - if(1 == i){ - first_tube_byte = num_array[0]; - second_tube_byte = '/'; - setDispBuf(FIRST_TUBE,first_tube_byte); - setDispBuf(SECOND_TUBE,second_tube_byte); - writeBytes(_addr, 0x00, 16, _buffer); - delay(interval); - } - clear(); - - } - else - { - first_tube_byte = (num / 10) + 0x30; - second_tube_byte = (num % 10 ) + 0x30; - if(!isLegalToDisplay(first_tube_byte)) - { - first_tube_byte = '/'; - } - if(!isLegalToDisplay(second_tube_byte)) - { - second_tube_byte = '/'; - } - - setDispBuf(FIRST_TUBE,first_tube_byte); - setDispBuf(SECOND_TUBE,second_tube_byte); - - writeBytes(_addr, 0x00, 16, _buffer); - delay(_ms); - } -} - -/**If the param-str's len less than 2,The tubes display static string,otherwise,it displays scroll string. - * When it displays scroll string,the param interval is scrolling interval(ms) . - * Node:The library does not support lower case letters. - * */ -void Digital_Tube2::displayString(char *str,unsigned int interval) -{ - char first_tube_byte = 0,second_tube_byte = 0; - int len = 0; - len = strlen(str); - if(len < 2) - { - if(len == 1) - { - first_tube_byte = str[0]; - } - else - { - first_tube_byte = '/'; - } - second_tube_byte = '/'; - } - else if(2 == len) - { - first_tube_byte = str[0]; - second_tube_byte = str[1]; - if(!isLegalToDisplay(first_tube_byte)) - { - first_tube_byte = '/'; - } - if(!isLegalToDisplay(second_tube_byte)) - { - second_tube_byte = '/'; - } - - setDispBuf(FIRST_TUBE,first_tube_byte); - setDispBuf(SECOND_TUBE,second_tube_byte); - - writeBytes(_addr, 0x00, 16, _buffer); - delay(_ms); - } - else - { - if(len >255 ) len = 255; - for(int i=0;i -#include "Wire.h" - -#include "HT16K33_driver.h" - -#define HT16K33_DEFAULT_I2C_ADDR 0x70 -#define MAX_BIG_BUFFER_SIZE (8*20) - - - -typedef enum -{ - SECOND_TUBE, - FIRST_TUBE, -}TubeNum_2; - - - - -class Digital_Tube2 : public HT16K33 { - -public: - Digital_Tube2(); - - void clear(); - - - void displayNum(unsigned long int num,unsigned int interval); - void displayString(char *str,unsigned int interval); - - void setDispBuf(TubeNum_2 num,char byte); - void displayFull(); - void display_two_tube(char byte1,char byte2); - -private: - // Low1 High1 Low2 High2 ... Low8 High8 - uint8_t _buffer[16]; - uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE]; - uint16_t _cursor_start, _cursor_end, _cursor_steps; - uint16_t _ms; - orientation_type_t _orientation; - int8_t _offset_x, _offset_y; - bool isLegalToDisplay(char byte); -}; - -#endif //__GROVE_LED_MATRIX_DRIVER_HT16K33__ \ No newline at end of file diff --git a/keywords.txt b/keywords.txt index 5febc80..a021167 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,16 +1,17 @@ ####################################### -# Syntax Coloring Map For Grove - Four Digital Tubes Display +# Syntax Coloring Map For Grove -alphanumeric display ####################################### ####################################### # Datatypes (KEYWORD1) ####################################### -Matrix_8x8 KEYWORD1 +Seeee_Digital_Tube KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### init KEYWORD2 + setTubeType KEYWORD2 setBlinkRate KEYWORD2 setBrightness KEYWORD2 displayString KEYWORD2 diff --git a/library.properties b/library.properties index d181554..42d3f83 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ -name=Grove - Four Digital Tubes Display +name=Grove - Grove alphanumeric display version=0.0.1 author=Seeed Studio maintainer=Seeed Studio -sentence=Arduino library to use control Grove - Four Digital Tubes Display -paragraph=Arduino library to use control Grove - Four Digital Tubes Display +sentence=Arduino library to use control Grove - Grove alphanumeric display +paragraph=Arduino library to use control Grove - Grove alphanumeric display category=Sensors url= architectures=* \ No newline at end of file