completely rewrite the driver.

using one class to descripe two kinds of display.
add two displays used simultaneously example.
use : setTubeType() to select which type of display is going to be used.
add : add comment ,modify configuration files.
This commit is contained in:
downeyboy
2019-07-03 14:21:35 +08:00
parent 9f486dc735
commit 76fc3bab28
13 changed files with 394 additions and 571 deletions

View File

@@ -5,30 +5,20 @@
## Introduction of sensor ## Introduction of sensor
Grove - alphanumeric Digital Tubes Display,Based on HT16K33,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.**
*** ### Notice:
* Support dual(two tubes)&qual(four tubes) alphanumeric Digital Tubes simultaneously. use following API to select the type of display.
## 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 <DUAL_NUMERIC> in every example.**
``` ```
//#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**
*** ***

View File

@@ -0,0 +1,51 @@
#include <Wire.h>
#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);
}

View File

@@ -30,48 +30,39 @@
*/ */
#include <Wire.h> #include <Wire.h>
#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() void setup()
{ {
Wire.begin(); 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.setBrightness(15);
tube.setBlinkRate(BLINK_OFF); tube.setBlinkRate(BLINK_OFF);
} }
void loop() 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(12);
tube.displayNum(123); delay(2000);
delay(2000);
tube.displayNum(4567); tube.displayNum(4567,500);
delay(2000); delay(2000);
tube.displayString("ABCD");
delay(2000); tube.displayString("AB",500);
tube.displayString("abcd"); delay(2000);
tube.displayString("abcd",500);
delay(2000); delay(2000);
#endif
} }

View File

@@ -34,19 +34,26 @@
/*********************************************************/ /*********************************************************/
/*****NOTICE : This example only for qual_alphanumeric****/ /*****NOTICE : This example only for qual_alphanumeric****/
/*********************************************************/ /*********************************************************/
#include "grove_quad_alphanumeric_display.h" #include "grove_alphanumeric_display.h"
#define NUMERIC_I2C_ADDR 0x71
Digital_Tube4 tube; Seeee_Digital_Tube tube;
void setup() void setup()
{ {
Wire.begin(); 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.setBrightness(15);
tube.setBlinkRate(BLINK_1HZ); tube.setBlinkRate(BLINK_1HZ);
} }
@@ -55,9 +62,15 @@ void displayCustom()
tube.clearBuf(); tube.clearBuf();
tube.setTubeSingleChar(FIRST_TUBE,'t'); tube.setTubeSingleChar(FIRST_TUBE,'t');
tube.setTubeSingleChar(SECOND_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(THIRD_TUBE,5);
tube.setTubeSingleNum(FOURTH_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(); tube.display();
} }

View File

@@ -29,24 +29,23 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <Wire.h> #include <Wire.h>
#include "grove_alphanumeric_display.h"
//#define DUAL_NUMERIC
#ifdef DUAL_NUMERIC Seeee_Digital_Tube tube;
#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() void setup()
{ {
Wire.begin(); 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.setBrightness(15);
tube.setBlinkRate(BLINK_OFF); tube.setBlinkRate(BLINK_OFF);
} }

View File

@@ -29,24 +29,22 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <Wire.h> #include <Wire.h>
#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() void setup()
{ {
Wire.begin(); 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.setBrightness(15);
tube.setBlinkRate(BLINK_OFF); tube.setBlinkRate(BLINK_OFF);
} }
@@ -55,6 +53,6 @@ void setup()
void loop() void loop()
{ {
tube.displayString("ABCDEFGHJIYZ",500); tube.displayString("ABCDEFGHIJK",500);
delay(1000); delay(1000);
} }

View File

@@ -29,21 +29,23 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <Wire.h> #include <Wire.h>
#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[10];
char hex_str[255] = {0};
void setup() void setup()
{ {
Wire.begin(); 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.setBrightness(15);
tube.setBlinkRate(BLINK_OFF); tube.setBlinkRate(BLINK_OFF);
@@ -79,6 +81,6 @@ void loop()
for(int i=0;i<0xff;i++) for(int i=0;i<0xff;i++)
{ {
tube.displayString(numToHexString(i),0); tube.displayString(numToHexString(i),0);
delay(300); delay(100);
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
* grove_quad_alphanumeric_display.cpp * grove_alphanumeric_display.cpp
* A library for Grove - grove_quad_alphanumeric_display * A library for Grove - grove_alphanumeric_display
* *
* Copyright (c) 2018 seeed technology inc. * Copyright (c) 2018 seeed technology inc.
* Website : www.seeed.cc * Website : www.seeed.cc
@@ -36,29 +36,11 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "grove_quad_alphanumeric_display.h" #include "grove_alphanumeric_display.h"
#include "Wire.h" #include "Wire.h"
Digital_Tube4::Digital_Tube4() uint16_t g_display_font4[]={
{
_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. // 0x0000, // display nothing.
0x0080, // 'upper .' 0x0080, // 'upper .'
0x2000, // 'lower .' 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. /**@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) .. * When it displays scroll number,the param interval is scrolling interval(ms) ..
* @param num the number to display. * @param num the number to display.
* @param interval :the interval of scroll number. * @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}; char num_str[15] = {0};
sprintf(num_str,"%ld",(uint32_t)num); 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}; char temp[MAX_TUBE_COUNT] = {0};
memcpy(temp,&origin_disp_buf[1],TUBE_COUNT-1);
temp[TUBE_COUNT-1] = new_item; memcpy(temp,&origin_disp_buf[1],_tube_cnt - 1);
memcpy(origin_disp_buf,temp,TUBE_COUNT);
for(int i =0;i< TUBE_COUNT;i++) 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); writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms); delay(_ms);
@@ -136,36 +193,44 @@ void Digital_Tube4::shiftDisplay(char *origin_disp_buf,char new_item)
* @param str the str to display. * @param str the str to display.
* @param interval :the interval of scroll string. * @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; int len = 0;
clearBuf(); clearBuf();
len = strlen(str); len = strlen(str);
if(TUBE_COUNT >= len)
if(_tube_cnt >= len)
{ {
for(int i=0;i<len;i++) for(int i=0;i<len;i++)
{ {
setTubeBuf((TubeNum_4)(TUBE_COUNT-len+i+1),g_display_font[get_char_index(str[i])]); //Convert number to char; //setTubeBuf((TubeNum)(_tube_cnt-len+i+1),disp_font_p[get_char_index(str[i])]); //Convert number to char;
setTubeBuf((TubeNum)(_tube_cnt-len+i+1),str[i]); //Convert number to char;
} }
writeBytes(_addr, 0x00, 16, _buffer); writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms); delay(_ms);
} }
else else
{ {
if(len > 255 ) len = 255; if(len > 255 ) len = 255;
char origin_disp_buf[TUBE_COUNT]={0}; char origin_disp_buf[MAX_TUBE_COUNT]={0};
for(int i=0;i<len;i++) for(int i=0;i<len;i++)
{ {
shiftDisplay(origin_disp_buf,str[i]); shiftDisplay(origin_disp_buf,str[i]);
delay(interval); delay(interval);
} }
for(int i=0;i<_tube_cnt;i++)
{
shiftDisplay(origin_disp_buf,0);
delay(interval);
}
} }
} }
void Digital_Tube4::clear() void Seeee_Digital_Tube::clear()
{ {
memset(_buffer, 0, sizeof(_buffer)); memset(_buffer, 0, sizeof(_buffer));
writeBytes(_addr, 0x00, 16, _buffer); writeBytes(_addr, 0x00, 16, _buffer);
@@ -173,7 +238,7 @@ void Digital_Tube4::clear()
} }
void Digital_Tube4::fulDisplay() void Seeee_Digital_Tube::fulDisplay()
{ {
uint8_t buf[16] = {0}; uint8_t buf[16] = {0};
memcpy(_buffer,buf,sizeof(buf)); memcpy(_buffer,buf,sizeof(buf));
@@ -182,25 +247,41 @@ void Digital_Tube4::fulDisplay()
delay(_ms); delay(_ms);
} }
/** Because of the difference of the hardware design of two kinds of display(two & four tubes).
void Digital_Tube4::replace_bit12(TubeNum_4 tube_num,bool bit1,bool bit2) * two digital tubes use _buffer[2,3,4,5] to control display.
* four digital tubes use _buffer[2,3,4,5,6,7,8,9,10,11] to control display.
*
**/
void Seeee_Digital_Tube::replace_bit12(TubeNum tube_num,bool bit1,bool bit2)
{ {
switch(tube_num) switch(tube_num)
{ {
case FIRST_TUBE: case FIRST_TUBE:
_buffer[10] &= ~(1 << 4);
_buffer[10] &= ~(1<<3);
_buffer[10] |= (bit1<<4); _buffer[10] |= (bit1<<4);
_buffer[10] |= (bit2<<3); _buffer[10] |= (bit2<<3);
break; break;
case SECOND_TUBE: case SECOND_TUBE:
_buffer[10] &= ~(1 << 6);
_buffer[11] &= ~(1 << 6);
_buffer[10] |= (bit1<<6); _buffer[10] |= (bit1<<6);
_buffer[11] |= (bit2<<6); _buffer[11] |= (bit2<<6);
break; break;
case THIRD_TUBE: case THIRD_TUBE:
_buffer[10] &= ~(1 << 5);
_buffer[11] &= ~(1 << 1);
_buffer[10] |= (bit1<<5); _buffer[10] |= (bit1<<5);
_buffer[11] |= (bit2<<1); _buffer[11] |= (bit2<<1);
break; break;
case FOURTH_TUBE: case FOURTH_TUBE:
_buffer[11] &= ~(1 << 2);
_buffer[11] &= ~(1 << 0);
_buffer[11] |= (bit1<<2); _buffer[11] |= (bit1<<2);
_buffer[11] |= (bit2<<0); _buffer[11] |= (bit2<<0);
break; break;
@@ -208,59 +289,129 @@ void Digital_Tube4::replace_bit12(TubeNum_4 tube_num,bool bit1,bool bit2)
} }
} }
void Digital_Tube4::setPoint(bool upper_on,bool lower_on) void Seeee_Digital_Tube::setPoint(bool first_dot,bool second_dot)
{ {
if(upper_on){ if( TYPE_4 == _type )
_buffer[10] |= g_display_font[0]; {
_buffer[11] |= g_display_font[0]>>8; //upper dot control
if(first_dot){
_buffer[10] |= disp_font_p[0];
_buffer[11] |= disp_font_p[0]>>8;
} }
if(lower_on){ //lower dot control
_buffer[10] |= g_display_font[1]; if(second_dot){
_buffer[11] |= g_display_font[1]>>8; _buffer[10] |= disp_font_p[1];
_buffer[11] |= disp_font_p[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] = value;
_buffer[tube_num*2+1] = value >> 8; _buffer[tube_num*2+1] = value >> 8;
replace_bit12(tube_num,value&0x02,value&0x04); 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];
}
}
}
/**@brief Specify the display char of a digital tube. /**@brief Specify the display char of a digital tube.
* @param tube_num The number of tube ,total 4. * @param tube_num The number of tube ,total 4.
* @param c ,The char to display * @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 ; return ;
} }
uint16_t value = g_display_font[get_char_index(c)]; if( TYPE_4 == _type )
_buffer[tube_num*2] = value; {
_buffer[tube_num*2+1] = value >> 8; setTubeBuf(tube_num , c);
replace_bit12(tube_num,value&0x02,value&0x04); }
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. /**@brief Specify the display number of a digital tube.
* @param tube_num The number of tube ,total 4. * @param tube_num The number of tube ,total 4.
* @param num ,The number to display * @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)) ) if( !((num >= 0) && (num <= 9)) )
return ; return ;
uint16_t value = g_display_font[get_char_index(num+0x30)]; if( TYPE_4 == _type )
_buffer[tube_num*2] = value; {
_buffer[tube_num*2+1] = value >> 8; setTubeBuf(tube_num , num + 0x30);
replace_bit12(tube_num,value&0x02,value&0x04); }
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] = value;
_buffer[tube_num*2+1] = value >> 8; _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)); 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')) if((c >= '0') && (c <= '9'))
{ {
@@ -291,28 +442,18 @@ int Digital_Tube4::get_char_index(char c)
} }
else else
{ {
return '/'+2; return LAST_ITEM;
} }
} }
void Seeee_Digital_Tube::display()
void Digital_Tube4::display()
{ {
writeBytes(_addr, 0x00, 16, _buffer); writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms); 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();
}
*/

View File

@@ -1,6 +1,6 @@
/* /*
* grove_quad_alphanumeric_display.h * grove_alphanumeric_display.h
* A library for Grove - grove_quad_alphanumeric_display * A library for Grove - grove_alphanumeric_display
* *
* Copyright (c) 2018 seeed technology inc. * Copyright (c) 2018 seeed technology inc.
* Website : www.seeed.cc * Website : www.seeed.cc
@@ -43,10 +43,15 @@
#include <Arduino.h> #include <Arduino.h>
#include "HT16K33_driver.h" #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 MAX_BIG_BUFFER_SIZE (8*20)
#define TUBE_COUNT 4 #define MAX_TUBE_COUNT 4
typedef enum typedef enum
{ {
@@ -54,13 +59,25 @@ typedef enum
SECOND_TUBE, SECOND_TUBE,
THIRD_TUBE, THIRD_TUBE,
FOURTH_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: public:
Digital_Tube4(); Seeee_Digital_Tube();
void setTubeType(TubeType_t type,uint8_t addr = TYPE_2_DEFAULT_I2C_ADDR);
void clear(); void clear();
/**@brief Display number,If the param-num's len less than 4,The tubes display static number,otherwise,it displays scroll number. /**@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(); void fulDisplay();
/**@brief Clear _buffer,just clear. /**@brief Clear _buffer,just clear.
* *
* */ * */
@@ -98,34 +114,37 @@ public:
* @param tube_num The number of tube ,total 4. * @param tube_num The number of tube ,total 4.
* @param num ,The number to display * @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. /**@brief Specify the display number of a digital tube.
* @param tube_num The number of tube ,total 4. * @param tube_num The number of tube ,total 4.
* @param num ,The number to display * @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. /**@brief Set two points status.
* @prarm upper_on if true,the upper point light on ,otherwise turn off; * @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; * @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: private:
void display_one_tube(TubeNum_4 tube_num,uint16_t value); void display_one_tube(TubeNum tube_num,uint16_t value);
void replace_bit12(TubeNum_4 tube_num,bool bit1,bool bit2); void replace_bit12(TubeNum tube_num,bool bit1,bool bit2);
void setTubeBuf(TubeNum_4 tube_num,uint16_t value); void setTubeBuf(TubeNum tube_num,char byte);
int get_char_index(char c); int get_char_index(char c);
void shiftDisplay(char *origin_disp_buf,char new_item); void shiftDisplay(char *origin_disp_buf,char new_item);
// Low1 High1 Low2 High2 ... Low8 High8 // Low1 High1 Low2 High2 ... Low8 High8
uint8_t _buffer[16]; uint8_t _buffer[16];
uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE]; //uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE];
uint16_t _cursor_start, _cursor_end, _cursor_steps; //uint16_t _cursor_start, _cursor_end, _cursor_steps;
uint16_t _ms; uint16_t _ms;
orientation_type_t _orientation; //orientation_type_t _orientation;
int8_t _offset_x, _offset_y; //int8_t _offset_x, _offset_y;
bool isLegalToDisplay(char byte); bool isLegalToDisplay(char byte);
TubeType_t _type;
TubeCnt_t _tube_cnt;
uint16_t *disp_font_p;
}; };

View File

@@ -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<len;i += 2)
{
first_tube_byte = str[i];
second_tube_byte = str[i+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(interval);
if(i+2 == len-1)
{
first_tube_byte = str[len-1];
second_tube_byte = '/';
setDispBuf(FIRST_TUBE,first_tube_byte);
setDispBuf(SECOND_TUBE,second_tube_byte);
writeBytes(_addr, 0x00, 16, _buffer);
delay(interval);
break;
}
}
}
}
void Digital_Tube2::displayFull()
{
for(int i=0;i<4;i++)
{
_buffer[i+2] = 0xff;
}
writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}
void Digital_Tube2::clear()
{
memset(_buffer, 0, sizeof(_buffer));
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();
}
*/

View File

@@ -1,81 +0,0 @@
/*
* grove_dual_alphanumeric_display.h
* 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.
*/
#ifndef __GROVE_DUAL_ALPHANUMERIC_DISPLAY_H__
#define __GROVE_DUAL_ALPHANUMERIC_DISPLAY_H__
#include <Arduino.h>
#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__

View File

@@ -1,16 +1,17 @@
####################################### #######################################
# Syntax Coloring Map For Grove - Four Digital Tubes Display # Syntax Coloring Map For Grove -alphanumeric display
####################################### #######################################
####################################### #######################################
# Datatypes (KEYWORD1) # Datatypes (KEYWORD1)
####################################### #######################################
Matrix_8x8 KEYWORD1 Seeee_Digital_Tube KEYWORD1
####################################### #######################################
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
####################################### #######################################
init KEYWORD2 init KEYWORD2
setTubeType KEYWORD2
setBlinkRate KEYWORD2 setBlinkRate KEYWORD2
setBrightness KEYWORD2 setBrightness KEYWORD2
displayString KEYWORD2 displayString KEYWORD2

View File

@@ -1,9 +1,9 @@
name=Grove - Four Digital Tubes Display name=Grove - Grove alphanumeric display
version=0.0.1 version=0.0.1
author=Seeed Studio author=Seeed Studio
maintainer=Seeed Studio <techsupport@seeed.cc> maintainer=Seeed Studio <techsupport@seeed.cc>
sentence=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 - Four Digital Tubes Display paragraph=Arduino library to use control Grove - Grove alphanumeric display
category=Sensors category=Sensors
url= url=
architectures=* architectures=*