From 9f486dc735e5788a956c93d75681924aad287d65 Mon Sep 17 00:00:00 2001 From: downeyboy Date: Thu, 13 Jun 2019 19:24:38 +0800 Subject: [PATCH] fix : merge two tubes & four tubes --- HT16K33_driver.cpp | 73 +++ HT16K33_driver.h | 95 ++++ README.md | 35 +- examples/display_basic/display_basic.ino | 40 +- .../display_custom_4.ino} | 33 +- .../display_scroll_number.ino | 21 +- .../display_scroll_string.ino | 21 +- .../number_increment_2/number_increment_2.ino | 84 +++ grove_dual_alphanumeric_display.cpp | 485 ++++++++---------- grove_dual_alphanumeric_display.h | 124 +---- grove_quad_alphanumeric_display.cpp | 318 ++++++++++++ grove_quad_alphanumeric_display.h | 132 +++++ 12 files changed, 1045 insertions(+), 416 deletions(-) create mode 100644 HT16K33_driver.cpp create mode 100644 HT16K33_driver.h rename examples/{display_custom/display_custom.ino => display_custom_4/display_custom_4.ino} (69%) create mode 100644 examples/number_increment_2/number_increment_2.ino create mode 100644 grove_quad_alphanumeric_display.cpp create mode 100644 grove_quad_alphanumeric_display.h diff --git a/HT16K33_driver.cpp b/HT16K33_driver.cpp new file mode 100644 index 0000000..8563db3 --- /dev/null +++ b/HT16K33_driver.cpp @@ -0,0 +1,73 @@ +/* + * HT16K33_driver.cpp + * A library for Grove - grove_quad_alphanumeric_display + * + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : Jerry Yip + * Create Time: 2018-06 + * Version : 0.1 + * Change Log : + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : downey + * Create Time: 2018-06 + * Version : 1.1 + * Change Log :for digital tube development. + * + * 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 +#include "HT16K33_driver.h" + + + +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(); +} + + + +void HT16K33::init(uint8_t addr) +{ + _addr = addr; + // turn on oscillator + writeBytes(_addr, 0x21, 0, (uint8_t *)NULL); +} + +/*brightness:0-15*/ +void HT16K33::setBrightness(uint8_t brightness) +{ + writeBytes(_addr, (0xE0 | brightness), 0, (uint8_t *)NULL); +} + + +void HT16K33::setBlinkRate(blink_type_t blink_type) +{ + writeBytes(_addr, (0x80 | 0x01 | (blink_type << 1)), 0, (uint8_t *)NULL); +} + diff --git a/HT16K33_driver.h b/HT16K33_driver.h new file mode 100644 index 0000000..b585a22 --- /dev/null +++ b/HT16K33_driver.h @@ -0,0 +1,95 @@ +/* + * HT16K33_driver.h + * A library for Grove - grove_quad_alphanumeric_display + * + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : Jerry Yip + * Create Time: 2018-06 + * Version : 0.1 + * Change Log : + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : downey + * Create Time: 2018-06 + * Version : 1.1 + * Change Log :for digital tube development. + * + * 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. + */ +#ifndef __HT16K33_DRIVER_H_ +#define __HT16K33_DRIVER_H_ + + +#include +#include "Wire.h" + + + + + +enum orientation_type_t +{ + DISPLAY_ROTATE_0 = 0, + DISPLAY_ROTATE_90, + DISPLAY_ROTATE_180, + DISPLAY_ROTATE_270, +}; + +enum action_type_t +{ + ACTION_SCROLLING = 0, + ACTION_SHIFT, +}; + +enum blink_type_t +{ + BLINK_OFF = 0, + BLINK_2HZ, + BLINK_1HZ, +}; + + +class HT16K33 { +public: + HT16K33(){} + void init(uint8_t addr); + + void setBlinkRate(blink_type_t blink_type); + + void setBrightness(uint8_t brightness); + + virtual void clear(); + + bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t* data); + +protected: + uint8_t _addr; +}; + + + + + +#endif + + + diff --git a/README.md b/README.md index aa2b8e5..ffca25b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,38 @@ -# Grove - Four Digital Tubes Display -*** +# Grove - alphanumeric Digital Tubes Display + +*** + ## Introduction of sensor -Grove - Four Digital Tubes Display,it can display number,and scrolling displaying. +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/display_custom.ino**. ->* **example/display_scroll_string/display_scroll_string.ino**:Display scrolling string which longer than 4. ->* **example/display_scroll_number/display_scroll_number.ino**:Display scrolling number which bigger than 9999. ->* **example/display_basic/display_basic.ino**:Basic static display demo. - +>* **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.** +``` +//#define DUAL_NUMERIC +``` + +comment it ,using qual alphanumeric Digital Tubes Display,otherwise ,using dual alphanumeric Digital Tubes Display. + +**defaule using qual alphanumeric Digital Tubes Display** + +*** + + This software is written by Jerry Yip for seeed studio and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
Contributing to this software is warmly welcomed. You can do this basically by
diff --git a/examples/display_basic/display_basic.ino b/examples/display_basic/display_basic.ino index 16e0a91..747a89f 100644 --- a/examples/display_basic/display_basic.ino +++ b/examples/display_basic/display_basic.ino @@ -29,31 +29,49 @@ * THE SOFTWARE. */ #include -#include "grove_dual_alphanumeric_display.h" -extern uint16_t g_display_font[]; -Digital_Tube tube4; +//#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 -#define SHINE_INTERVAL 1000 void setup() { Wire.begin(); - tube4.init(); - tube4.setBrightness(15); - tube4.setBlinkRate(BLINK_OFF); + tube.init(NUMERIC_I2C_ADDR); + tube.setBrightness(15); + tube.setBlinkRate(BLINK_OFF); } void loop() { - tube4.displayNum(123); + #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); - tube4.displayNum(4567); + tube.displayNum(4567); delay(2000); - tube4.displayString("ABCD"); + tube.displayString("ABCD"); delay(2000); - tube4.displayString("abcd"); + tube.displayString("abcd"); delay(2000); + + #endif } \ No newline at end of file diff --git a/examples/display_custom/display_custom.ino b/examples/display_custom_4/display_custom_4.ino similarity index 69% rename from examples/display_custom/display_custom.ino rename to examples/display_custom_4/display_custom_4.ino index 06d4538..709f47c 100644 --- a/examples/display_custom/display_custom.ino +++ b/examples/display_custom_4/display_custom_4.ino @@ -1,5 +1,5 @@ /* - * display_custom.ino + * display_custom_4.ino * Example for digital tube. * * Copyright (c) 2018 Seeed Technology Co., Ltd. @@ -29,35 +29,36 @@ * THE SOFTWARE. */ #include -#include "grove_dual_alphanumeric_display.h" -extern uint16_t g_display_font[]; -Digital_Tube tube4; - -#define SHINE_INTERVAL 1000 +/*********************************************************/ +/*****NOTICE : This example only for qual_alphanumeric****/ +/*********************************************************/ +#include "grove_quad_alphanumeric_display.h" +#define NUMERIC_I2C_ADDR 0x71 +Digital_Tube4 tube; void setup() { Wire.begin(); - tube4.init(); - tube4.setBrightness(15); - tube4.setBlinkRate(BLINK_1HZ); + tube.init(NUMERIC_I2C_ADDR); + tube.setBrightness(15); + tube.setBlinkRate(BLINK_1HZ); } void displayCustom() { - tube4.clearBuf(); - tube4.setTubeSingleChar(FIRST_TUBE,'t'); - tube4.setTubeSingleChar(SECOND_TUBE,'T'); - tube4.setTubeSingleNum(THIRD_TUBE,5); - tube4.setTubeSingleNum(FOURTH_TUBE,5); - tube4.setPoint(true,true); - tube4.display(); + tube.clearBuf(); + tube.setTubeSingleChar(FIRST_TUBE,'t'); + tube.setTubeSingleChar(SECOND_TUBE,'T'); + tube.setTubeSingleNum(THIRD_TUBE,5); + tube.setTubeSingleNum(FOURTH_TUBE,5); + tube.setPoint(true,true); + tube.display(); } void loop() diff --git a/examples/display_scroll_number/display_scroll_number.ino b/examples/display_scroll_number/display_scroll_number.ino index 4122b6c..fecd441 100644 --- a/examples/display_scroll_number/display_scroll_number.ino +++ b/examples/display_scroll_number/display_scroll_number.ino @@ -29,23 +29,32 @@ * THE SOFTWARE. */ #include -#include "grove_dual_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 -Digital_Tube tube4; void setup() { Wire.begin(); - tube4.init(); - tube4.setBrightness(15); - tube4.setBlinkRate(BLINK_OFF); + tube.init(NUMERIC_I2C_ADDR); + tube.setBrightness(15); + tube.setBlinkRate(BLINK_OFF); } void loop() { - tube4.displayNum(1234567,500); + tube.displayNum(1234567,500); delay(1000); } \ No newline at end of file diff --git a/examples/display_scroll_string/display_scroll_string.ino b/examples/display_scroll_string/display_scroll_string.ino index 6207b8f..26fe338 100644 --- a/examples/display_scroll_string/display_scroll_string.ino +++ b/examples/display_scroll_string/display_scroll_string.ino @@ -29,23 +29,32 @@ * THE SOFTWARE. */ #include -#include "grove_dual_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 -Digital_Tube tube4; void setup() { Wire.begin(); - tube4.init(); - tube4.setBrightness(15); - tube4.setBlinkRate(BLINK_OFF); + tube.init(NUMERIC_I2C_ADDR); + tube.setBrightness(15); + tube.setBlinkRate(BLINK_OFF); } void loop() { - tube4.displayString("ABCDEFGHJIYZ",500); + tube.displayString("ABCDEFGHJIYZ",500); delay(1000); } \ No newline at end of file diff --git a/examples/number_increment_2/number_increment_2.ino b/examples/number_increment_2/number_increment_2.ino new file mode 100644 index 0000000..8c54a1d --- /dev/null +++ b/examples/number_increment_2/number_increment_2.ino @@ -0,0 +1,84 @@ +/* + * number_increment_2.ino + * Driver for digital tube. + * + * Copyright (c) 2018 Seeed Technology Co., Ltd. + * Website : www.seeed.cc + * Author : downey + * Create Time: sep. 2018 + * 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 +#include "grove_dual_alphanumeric_display.h" + +/*********************************************************/ +/*****NOTICE : This example only for dual_alphanumeric****/ +/*********************************************************/ + +#define NUMERIC_I2C_ADDR 0x70 + +Digital_Tube2 tube; +char hex_str[255] = {0}; + +void setup() +{ + Wire.begin(); + tube.init(NUMERIC_I2C_ADDR); + tube.setBrightness(15); + tube.setBlinkRate(BLINK_OFF); + +} + +char* numToHexString(unsigned int num) +{ + if(num <= 0xf){ + sprintf(hex_str,"0%x",num); + for(int i=0;i<2;i++) + { + if(hex_str[i] >= 'a' && hex_str[i] <= 'z') + { + hex_str[i] -=0x20; + } + } + return hex_str; + } + sprintf(hex_str,"%x",num); + for(int i=0;i<2;i++) + { + if(hex_str[i] >= 'a' && hex_str[i] <= 'z') + { + hex_str[i] -=0x20; + } + } + return hex_str; +} + + +void loop() +{ + for(int i=0;i<0xff;i++) + { + tube.displayString(numToHexString(i),0); + delay(300); + } +} \ No newline at end of file diff --git a/grove_dual_alphanumeric_display.cpp b/grove_dual_alphanumeric_display.cpp index 833d4fe..61df3a0 100644 --- a/grove_dual_alphanumeric_display.cpp +++ b/grove_dual_alphanumeric_display.cpp @@ -1,6 +1,6 @@ /* - * Grove_LED_Matrix_Driver_HT16K33.h - * A library for Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix) + * grove_dual_alphanumeric_display.cpp + * A library for Grove - dual_alphanumeric_display * * Copyright (c) 2018 seeed technology inc. * Website : www.seeed.cc @@ -8,12 +8,6 @@ * Create Time: 2018-06 * Version : 0.1 * Change Log : - * Copyright (c) 2018 seeed technology inc. - * Website : www.seeed.cc - * Author : downey - * Create Time: 2018-06 - * Version : 1.1 - * Change Log :for digital tube development. * * The MIT License (MIT) * @@ -37,32 +31,9 @@ */ #include "grove_dual_alphanumeric_display.h" -#include "Wire.h" - -HT16K33::HT16K33() -{ -} - -void HT16K33::init(uint8_t addr) -{ - _addr = addr; - // turn on oscillator - writeBytes(_addr, 0x21, 0, (uint8_t *)NULL); -} - -/*brightness:0-15*/ -void HT16K33::setBrightness(uint8_t brightness) -{ - writeBytes(_addr, (0xE0 | brightness), 0, (uint8_t *)NULL); -} -void HT16K33::setBlinkRate(blink_type_t blink_type) -{ - writeBytes(_addr, (0x80 | 0x01 | (blink_type << 1)), 0, (uint8_t *)NULL); -} - -Digital_Tube::Digital_Tube() +Digital_Tube2::Digital_Tube2() { _orientation = DISPLAY_ROTATE_0; _offset_x = 0; @@ -73,259 +44,251 @@ Digital_Tube::Digital_Tube() _ms = 100; } -bool Digital_Tube::isLegalToDisplay(char byte) +bool Digital_Tube2::isLegalToDisplay(char byte) { - if( !((byte >= '.' && byte <= '9') || (byte >= 'A' && byte <= 'Z') || (byte >= 'a' && byte <= 'z') ) ) + if( !((byte >= '.' && byte <= '9') || (byte >= 'A' && byte <= 'Z') ) ) return false; return true; } -uint16_t g_display_font[]={ +uint16_t g_display_font_2[]={ // 0x0000, // display nothing. - 0x0080, // 'upper .' - 0x2000, // 'lower .' - 0x4478, // '0' - 0x0060, // '1' - 0x0758, // '2' - 0x0770, // '3' - 0x4360, // '4' - 0x4730, // '5' - 0x4738, // '6' - 0x0070, // '7' - 0x4778, // '8' - 0x4770, // '9' - 0x4378, // 'A' - 0x2d70, // 'B' - 0x4418, // 'C' - 0x2c70, // 'D' - 0x4718, // 'E' - 0x4318, // 'F' - 0x4538, // 'G' - 0x4368, // 'H' - 0x2c10, // 'I' - 0x0478, // 'J' - 0x2806, // 'K' - 0x4408, // 'L' - 0x40ea, // 'M' - 0x40ec, // 'N' - 0x4478, // 'O' - 0x4358, // 'P' - 0x447c, // 'Q' - 0x435c, // 'R' - 0x0494, // 'S' - 0x2810, // 'T' - 0x4468, // 'U' - 0x500a, // 'V' - 0x506c, // 'W' - 0x1086, // 'X' - 0x0882, // 'Y' - 0x1412, // 'Z' - 0x0000, // '/' ilegal num + 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 }; - -/**@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_Tube::displayNum(uint32_t num,uint32_t interval) +void Digital_Tube2::display_two_tube(char byte1,char byte2) { - char num_str[15] = {0}; - sprintf(num_str,"%ld",(uint32_t)num); - displayString(num_str,interval); + 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_Tube::shiftDisplay(char *origin_disp_buf,char new_item) +void Digital_Tube2::setDispBuf(TubeNum_2 num,char byte) { - 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++) + if((byte >='.' && byte <= '9')) { - setTubeBuf(i+1,g_display_font[get_char_index(temp[i])]); + _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= len) - { - for(int i=0;i 255 ) len = 255; - char origin_disp_buf[TUBE_COUNT]={0}; - for(int i=0;i>8; - } - if(lower_on){ - _buffer[10] |= g_display_font[1]; - _buffer[11] |= g_display_font[1]>>8; - } -} - - -void Digital_Tube::setTubeBuf(TubeNum tube_num,uint16_t value) -{ - - _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_Tube::setTubeSingleChar(TubeNum tube_num,char c) -{ - if(!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) ) - { - 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); -} - -/**@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_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); -} - - -void Digital_Tube::display_one_tube(TubeNum tube_num,uint16_t value) -{ - _buffer[tube_num*2] = value; - _buffer[tube_num*2+1] = value >> 8; - replace_bit12(tube_num,value&0x02,value&0x04); - writeBytes(_addr, 0x00, 16, _buffer); - delay(_ms); -} - - -void Digital_Tube::clearBuf() -{ - memset(_buffer,0,sizeof(_buffer)); -} - -int Digital_Tube::get_char_index(char c) -{ - if((c >= '0') && (c <= '9')) - { - return c-0x30+2; - } - else if((c >= 'A') && (c <= 'Z')) - { - return c-0x37+2; - } - else if((c >= 'a') && (c <= 'z')) - { - return c-0x57+2; - } - else - { - return '/'+2; - } -} - - - -void 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); @@ -335,6 +298,4 @@ bool HT16K33::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 } Wire.endTransmission(); } - - - +*/ diff --git a/grove_dual_alphanumeric_display.h b/grove_dual_alphanumeric_display.h index 86ea3eb..a188c3c 100644 --- a/grove_dual_alphanumeric_display.h +++ b/grove_dual_alphanumeric_display.h @@ -1,6 +1,6 @@ /* - * Grove_LED_Matrix_Driver_HT16K33.h - * A library for Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix) + * grove_dual_alphanumeric_display.h + * A library for Grove - dual_alphanumeric_display * * Copyright (c) 2018 seeed technology inc. * Website : www.seeed.cc @@ -8,12 +8,6 @@ * Create Time: 2018-06 * Version : 0.1 * Change Log : - * Copyright (c) 2018 seeed technology inc. - * Website : www.seeed.cc - * Author : downey - * Create Time: 2018-06 - * Version : 1.1 - * Change Log :for digital tube development. * * The MIT License (MIT) * @@ -36,126 +30,44 @@ * THE SOFTWARE. */ -#ifndef __GROVE_LED_MATRIX_DRIVER_HT16K33__ -#define __GROVE_LED_MATRIX_DRIVER_HT16K33__ +#ifndef __GROVE_DUAL_ALPHANUMERIC_DISPLAY_H__ +#define __GROVE_DUAL_ALPHANUMERIC_DISPLAY_H__ -//#include "I2Cdev.h" #include +#include "Wire.h" -#define HT16K33_DEFAULT_I2C_ADDR 0x71 +#include "HT16K33_driver.h" + +#define HT16K33_DEFAULT_I2C_ADDR 0x70 #define MAX_BIG_BUFFER_SIZE (8*20) -#define TUBE_COUNT 4 - -enum orientation_type_t -{ - DISPLAY_ROTATE_0 = 0, - DISPLAY_ROTATE_90, - DISPLAY_ROTATE_180, - DISPLAY_ROTATE_270, -}; - -enum action_type_t -{ - ACTION_SCROLLING = 0, - ACTION_SHIFT, -}; - -enum blink_type_t -{ - BLINK_OFF = 0, - BLINK_2HZ, - BLINK_1HZ, -}; typedef enum { - FIRST_TUBE = 1, SECOND_TUBE, - THIRD_TUBE, - FOURTH_TUBE, -}TubeNum; + FIRST_TUBE, +}TubeNum_2; -class HT16K33 { -public: - HT16K33(); - bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t* data); - - void init(uint8_t addr=HT16K33_DEFAULT_I2C_ADDR); - void setBlinkRate(blink_type_t blink_type); - - void setBrightness(uint8_t brightness); - - virtual void clear(); - -protected: - uint8_t _addr; -}; - -class Digital_Tube : public HT16K33 { +class Digital_Tube2 : public HT16K33 { public: - Digital_Tube(); + Digital_Tube2(); void clear(); - /**@brief Display number,If the param-num's len less than 4,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 displayNum(uint32_t num,uint32_t interval = 0); - /**@brief Display string,If the param-str's len less than 4,The tubes display static string,otherwise,it displays scroll string. - * When it displays scroll string,the param interval is scrolling interval(ms) .. - * @param str the str to display. - * @param interval :the interval of scroll string. - * */ - void displayString(char *str,uint32_t interval = 0); - /**@brief Display all part of digital tube. - * - * */ - void fulDisplay(); - - - /**@brief Clear _buffer,just clear. - * - * */ - void clearBuf(); - - - /**@brief Display the contents of _buffer. - * - * */ - void display(); + void displayNum(unsigned long int num,unsigned int interval); + void displayString(char *str,unsigned int interval); - /**@brief Specify the display char of a digital tube. - * @param tube_num The number of tube ,total 4. - * @param num ,The number to display - * */ - void setTubeSingleChar(TubeNum tube_num,char c); + void setDispBuf(TubeNum_2 num,char byte); + void displayFull(); + void display_two_tube(char byte1,char byte2); - /**@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 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); private: - 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,uint16_t value); - 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]; @@ -164,8 +76,6 @@ private: 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/grove_quad_alphanumeric_display.cpp b/grove_quad_alphanumeric_display.cpp new file mode 100644 index 0000000..60a7400 --- /dev/null +++ b/grove_quad_alphanumeric_display.cpp @@ -0,0 +1,318 @@ +/* + * grove_quad_alphanumeric_display.cpp + * A library for Grove - grove_quad_alphanumeric_display + * + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : Jerry Yip + * Create Time: 2018-06 + * Version : 0.1 + * Change Log : + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : downey + * Create Time: 2018-06 + * Version : 1.1 + * Change Log :for digital tube development. + * + * 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_quad_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[]={ + // 0x0000, // display nothing. + 0x0080, // 'upper .' + 0x2000, // 'lower .' + 0x4478, // '0' + 0x0060, // '1' + 0x0758, // '2' + 0x0770, // '3' + 0x4360, // '4' + 0x4730, // '5' + 0x4738, // '6' + 0x0070, // '7' + 0x4778, // '8' + 0x4770, // '9' + 0x4378, // 'A' + 0x2d70, // 'B' + 0x4418, // 'C' + 0x2c70, // 'D' + 0x4718, // 'E' + 0x4318, // 'F' + 0x4538, // 'G' + 0x4368, // 'H' + 0x2c10, // 'I' + 0x0478, // 'J' + 0x2806, // 'K' + 0x4408, // 'L' + 0x40ea, // 'M' + 0x40ec, // 'N' + 0x4478, // 'O' + 0x4358, // 'P' + 0x447c, // 'Q' + 0x435c, // 'R' + 0x0494, // 'S' + 0x2810, // 'T' + 0x4468, // 'U' + 0x500a, // 'V' + 0x506c, // 'W' + 0x1086, // 'X' + 0x0882, // 'Y' + 0x1412, // 'Z' + 0x0000, // '/' ilegal num +}; + + + +/**@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) +{ + char num_str[15] = {0}; + sprintf(num_str,"%ld",(uint32_t)num); + displayString(num_str,interval); +} + + + +void Digital_Tube4::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++) + { + setTubeBuf((TubeNum_4)(i+1),g_display_font[get_char_index(temp[i])]); + } + writeBytes(_addr, 0x00, 16, _buffer); + delay(_ms); +} + +/**@brief Display string,If the param-str's len less than 4(or equal to),The tubes display static string,otherwise,it displays scroll string. + * When it displays scroll string,the param interval is scrolling interval(ms) .. + * @param str the str to display. + * @param interval :the interval of scroll string. + * */ +void Digital_Tube4::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) + { + for(int i=0;i 255 ) len = 255; + char origin_disp_buf[TUBE_COUNT]={0}; + for(int i=0;i>8; + } + if(lower_on){ + _buffer[10] |= g_display_font[1]; + _buffer[11] |= g_display_font[1]>>8; + } +} + + +void Digital_Tube4::setTubeBuf(TubeNum_4 tube_num,uint16_t value) +{ + + _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) +{ + if(!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) ) + { + 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); +} + +/**@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) +{ + 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); +} + + +void Digital_Tube4::display_one_tube(TubeNum_4 tube_num,uint16_t value) +{ + _buffer[tube_num*2] = value; + _buffer[tube_num*2+1] = value >> 8; + replace_bit12(tube_num,value&0x02,value&0x04); + writeBytes(_addr, 0x00, 16, _buffer); + delay(_ms); +} + + +void Digital_Tube4::clearBuf() +{ + memset(_buffer,0,sizeof(_buffer)); +} + +int Digital_Tube4::get_char_index(char c) +{ + if((c >= '0') && (c <= '9')) + { + return c-0x30+2; + } + else if((c >= 'A') && (c <= 'Z')) + { + return c-0x37+2; + } + else if((c >= 'a') && (c <= 'z')) + { + return c-0x57+2; + } + else + { + return '/'+2; + } +} + + + +void Digital_Tube4::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_quad_alphanumeric_display.h new file mode 100644 index 0000000..83aa92c --- /dev/null +++ b/grove_quad_alphanumeric_display.h @@ -0,0 +1,132 @@ +/* + * grove_quad_alphanumeric_display.h + * A library for Grove - grove_quad_alphanumeric_display + * + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : Jerry Yip + * Create Time: 2018-06 + * Version : 0.1 + * Change Log : + * Copyright (c) 2018 seeed technology inc. + * Website : www.seeed.cc + * Author : downey + * Create Time: 2018-06 + * Version : 1.1 + * Change Log :for digital tube development. + * + * 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. + */ + +#ifndef __GROVE_QUAD_ALPHANUMERIC_DISPLAY_H__ +#define __GROVE_QUAD_ALPHANUMERIC_DISPLAY_H__ + +//#include "I2Cdev.h" +#include +#include "HT16K33_driver.h" + +#define HT16K33_DEFAULT_I2C_ADDR 0x71 +#define MAX_BIG_BUFFER_SIZE (8*20) + +#define TUBE_COUNT 4 + +typedef enum +{ + FIRST_TUBE = 1, + SECOND_TUBE, + THIRD_TUBE, + FOURTH_TUBE, +}TubeNum_4; + + +class Digital_Tube4 : public HT16K33 { + +public: + Digital_Tube4(); + + void clear(); + /**@brief Display number,If the param-num's len less than 4,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 displayNum(uint32_t num,uint32_t interval = 0); + + /**@brief Display string,If the param-str's len less than 4,The tubes display static string,otherwise,it displays scroll string. + * When it displays scroll string,the param interval is scrolling interval(ms) .. + * @param str the str to display. + * @param interval :the interval of scroll string. + * */ + void displayString(char *str,uint32_t interval = 0); + /**@brief Display all part of digital tube. + * + * */ + void fulDisplay(); + + + + /**@brief Clear _buffer,just clear. + * + * */ + void clearBuf(); + + + /**@brief Display the contents of _buffer. + * + * */ + void display(); + + /**@brief Specify the display char of a digital tube. + * @param tube_num The number of tube ,total 4. + * @param num ,The number to display + * */ + void setTubeSingleChar(TubeNum_4 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); + + /**@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); +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); + 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; + 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