Перейти к содержимому



Dot Matrix Display 32x16 Red & Green (DIYJT) + Clock

Dot Matrix dual color Arduino Red&Green Clock DIYJT

  • Авторизуйтесь для ответа в теме
В теме одно сообщение

#1 admin

admin

    Администратор

  • Администраторы
  • 76 сообщений

Отправлено 03 Февраль 2014 - 21:28

This topic is a continuation of the development of software for the display.
You can order this module here http://dx.com/p/diyt...93#.Uu_CC9x7LpU

Original video is on www.youtube.com/watch?v=R10uR81O0YM

If you use my sketch you can obtain the result as on the picture

WP_20140203_002.jpg

The sketch
#include <Wire.h>
#include <RTClib.h>

/*
root_VNET 2014 http://mystd.ru
Digital Clock on DIYJT 32x16 Dual-color led dot matrix
*/

RTC_DS1307 RTC;

enum {
COLOR_RED = 1,
COLOR_GREEN = 2,
COLOR_ORANGE = 3,
};

const int aPin = 2; // row address bit 0
const int bPin = 3; // row address bit 1
const int cPin = 4; // row address bit 2
const int dPin = 5; // row address bit 3

const int oePin = 9; // output enable pin

const int redPin = 8; // data pin 1
const int greenPin = 7; // data pin 2

const int strPin = 11; // latch pin
const int sckPin = 12; // clock pin

int count = 0;
int number, i = 0;
int dig1, dig2, dig3, dig4 = 0;

byte pbuffer_r[4][16];
byte pbuffer_g[4][16];

// brutal font, zero element is 0; first element is 1 and so on...
byte digits[][16] = {
{B00000000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000000}, // 0
{B00000000, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00001100, B00000000}, // 1
{B00000000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B01100000, B01100000, B01100000, B01100000, B01111110, B01111110, B00000000}, // 2
{B00000000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000000}, // 3
{B00000000, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000000}, // 4
{B00000000, B01111110, B01111110, B01100000, B01100000, B01100000, B01100000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000000}, // 5
{B00000000, B01111110, B01111110, B01100000, B01100000, B01100000, B01100000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000000}, // 6
{B00000000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000000}, // 7
{B00000000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000000}, // 8
{B00000000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000000}, // 9
};

void draw_buffer(int draw_delay)
{
for(int row = 0; row < 16; row++)
{
digitalWrite(greenPin,HIGH);
digitalWrite(oePin, HIGH);
digitalWrite(aPin,row & B0001 );
digitalWrite(bPin,row & B0010 );
digitalWrite(cPin,row & B0100 );
digitalWrite(dPin,row & B1000 );
digitalWrite(strPin, LOW);
shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[0][row]);
shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[1][row]);
shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[2][row]);
shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[3][row]);
digitalWrite(strPin, HIGH);
digitalWrite(oePin, LOW);
delayMicroseconds(draw_delay); // delay for seeing red

digitalWrite(redPin,HIGH);
digitalWrite(oePin, HIGH);
digitalWrite(strPin, LOW);
shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[0][row]);
shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[1][row]);
shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[2][row]);
shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[3][row]);
digitalWrite(strPin, HIGH);
digitalWrite(oePin, LOW);
delayMicroseconds(draw_delay); // delay for seeing green
}
}

void ClearBuffer()
{
// clear buffer
memset(pbuffer_r,255,sizeof(pbuffer_r));
memset(pbuffer_g,255,sizeof(pbuffer_g));
}

// set pixel val = 0(off) or 1(on)
void SetPixel(byte x, byte y, byte val)
{
if(val & COLOR_RED)
{
pbuffer_r[x/byte(8)][y] &= ~(1 << 7 >> (x%8));
}
if(val & COLOR_GREEN)
{
pbuffer_g[x/byte(8)][y] &= ~(1 << 7 >> (x%8));
}
}

void printDigit(int x, int y, byte num, byte color)
{
for(byte i = 0; i < 16; i++)
{
byte line = digits[num][i];
byte k = 7;
while(line > 0)
{
byte bit = line % 2;
line /= 2;
if(bit) SetPixel(x + k ,y + i,color);
k--;
}
}
}

void setup()
{
//
Wire.begin();
RTC.begin();
//

//set pins to output because they are addressed in the main loop
pinMode(aPin, OUTPUT);
pinMode(bPin, OUTPUT);
pinMode(cPin, OUTPUT);
pinMode(dPin, OUTPUT);
pinMode(oePin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(strPin, OUTPUT);
pinMode(sckPin, OUTPUT);

digitalWrite(oePin, LOW);
// turn off the light
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, HIGH);
}

byte psec = 0, sec, cnt = 0;;

void loop()
{
//

DateTime now = RTC.now();
number = now.hour() * 100 + now.minute();
i = number;
dig1 = i/1000;
i = i-(dig1*1000);
dig2 = i/100;
i = i-(dig2*100);
dig3 = i/10;
i = i-(dig3*10);
dig4 = i;

sec = now.second();

//

ClearBuffer();
printDigit(0-1,0,dig1,COLOR_RED);
printDigit(0+7,0,dig2,COLOR_RED);
printDigit(0+17,0,dig3,COLOR_GREEN);
printDigit(0+24+1,0,dig4,COLOR_GREEN);

if(sec == psec)
{
if(cnt == 0)
{
SetPixel(15,7-3,COLOR_ORANGE);
SetPixel(15,8-3,COLOR_ORANGE);
SetPixel(16,7-3,COLOR_ORANGE);
SetPixel(16,8-3,COLOR_ORANGE);
SetPixel(15,7+3,COLOR_ORANGE);
SetPixel(15,8+3,COLOR_ORANGE);
SetPixel(16,7+3,COLOR_ORANGE);
SetPixel(16,8+3,COLOR_ORANGE);
}
else cnt--;
}
else
{
psec = sec;
cnt = 20;
}

// draw the screen ==================================================

draw_buffer(80);

// END draw the screen ==============================================

}


#2 admin

admin

    Администратор

  • Администраторы
  • 76 сообщений

Отправлено 04 Февраль 2014 - 22:33

Next sketch modification

WP_20140204_0021.jpg

#include <Wire.h>
#include <RTClib.h>
/*
root_VNET 2014 http://mystd.ru
Digital Clock on DIYJT 32x16 Dual-color led dot matrix
*/
RTC_DS1307 RTC;
enum {
  COLOR_RED = 1,
  COLOR_GREEN = 2,
  COLOR_ORANGE = 3,
};
const int aPin = 2;	   // row address bit 0
const int bPin = 3;	   // row address bit 1
const int cPin = 4;	   // row address bit 2
const int dPin = 5;	   // row address bit 3
const int oePin = 9;	 // output enable pin
const int redPin = 8;   // data pin 1
const int greenPin = 7;  // data pin 2
const int strPin = 11;  // latch pin
const int sckPin = 12;  // clock pin
int count = 0;
int number, i = 0;
int dig1, dig2, dig3, dig4 = 0;
byte pbuffer_r[4][16];
byte pbuffer_g[4][16];
// brutal font, zero element is 0; first element is 1 and so on...
byte digits[][8] = {
		{B01110,B11011,B11011,B11011,B11011,B11011,B01110,B0}, // 0
		{B00010,B00110,B01110,B00110,B00110,B00110,B00110,B0}, // 1
		{B01110,B11011,B00011,B00110,B01100,B11000,B11111,B0}, // 2
		{B01110,B11011,B00011,B01110,B00011,B11011,B01110,B0}, // 3
		{B00011,B00111,B01111,B11011,B11111,B00011,B00011,B0}, // 4
		{B11111,B11000,B11110,B00011,B00011,B11011,B01110,B0}, // 5
		{B01110,B11011,B11000,B11110,B11011,B11011,B01110,B0}, // 6
		{B11111,B00011,B00110,B01100,B01100,B01100,B01100,B0}, // 7
		{B01110,B11011,B11011,B01110,B11011,B11011,B01110,B0}, // 8
		{B01110,B11011,B11011,B01111,B00011,B11011,B01110,B0}, // 9
  };
byte font8x5[][5] =
{
  {B01110,B10001,B11111,B10001,B10001}, //A
  {B11110,B10001,B11110,B10001,B11110}, //B
  {B01110,B10001,B10000,B10001,B01110}, //C
  {B11110,B10001,B10001,B10001,B11110}, //D
  {B11111,B10000,B11110,B10000,B11111}, //E
  {B11111,B10000,B11110,B10000,B10000}, //F
  {B01110,B10000,B10011,B10001,B01110}, //G
  {B10001,B10001,B11111,B10001,B10001}, //H
  {B01110,B00100,B00100,B00100,B01110}, //I
  {B01110,B00100,B00100,B00100,B01100}, //J
  {B10001,B10010,B11100,B10010,B10001}, //K
  {B10000,B10000,B10000,B10000,B11111}, //L
  {B10001,B11011,B10101,B10001,B10001}, //M
  {B10001,B11001,B10101,B10011,B10001}, //N
  {B1110,B10001,B10001,B10001,B1110}, //O
  {B11110,B10001,B11110,B10000,B10000}, //P
  {B1110,B10001,B10101,B10010,B1101}, //Q
  {B11110,B10001,B11110,B10010,B10001}, //R
  {B1111,B10000,B1110,B1,B11110}, //S
  {B11111,B100,B100,B100,B100}, //T
  {B10001,B10001,B10001,B10001,B1110}, //U
  {B10001,B10001,B10001,B1010,B100}, //V
  {B10001,B10001,B10001,B10101,B1010}, //W
  {B10001,B1010,B100,B1010,B10001}, //X
  {B10001,B1010,B100,B100,B100}, //Y
  {B11111,B10,B100,B1000,B11111}, //Z
};
void draw_buffer(int draw_delay)
{
  for(int row = 0; row < 16; row++)
  {
		  digitalWrite(greenPin,HIGH);
		  digitalWrite(oePin, HIGH);
		  digitalWrite(aPin,row & B0001 );
		  digitalWrite(bPin,row & B0010 );
		  digitalWrite(cPin,row & B0100 );
		  digitalWrite(dPin,row & B1000 );
		  digitalWrite(strPin, LOW);
		  shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[0][row]);
		  shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[1][row]);
		  shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[2][row]);
		  shiftOut(redPin, sckPin, MSBFIRST, pbuffer_r[3][row]);
		  digitalWrite(strPin, HIGH);  
		  digitalWrite(oePin, LOW);
		  delayMicroseconds(draw_delay);  // delay for seeing red
		  digitalWrite(redPin,HIGH);
		  digitalWrite(oePin, HIGH);
		  digitalWrite(strPin, LOW);
		  shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[0][row]);
		  shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[1][row]);
		  shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[2][row]);
		  shiftOut(greenPin, sckPin, MSBFIRST, pbuffer_g[3][row]);
		  digitalWrite(strPin, HIGH);  
		  digitalWrite(oePin, LOW);
		  delayMicroseconds(draw_delay);  // delay for seeing green
  }
}
void ClearBuffer()
{
  // clear buffer
  memset(pbuffer_r,255,sizeof(pbuffer_r));
  memset(pbuffer_g,255,sizeof(pbuffer_g));
}
// set pixel val = 0(off) or 1(on)
void SetPixel(byte x, byte y, byte val)
{
  if(val & COLOR_RED)
  {
		  pbuffer_r[x/byte(8)][y] &= ~(1 << 7 >> (x%8));
  }
  if(val & COLOR_GREEN)
  {
		  pbuffer_g[x/byte(8)][y] &= ~(1 << 7 >> (x%8));
  }
}
void printDigit(int x, int y, byte num, byte color)
{
  for(byte i = 0; i < 8; i++)
  {
		  byte line = digits[num][i];
		  byte k = 5;
		  while(line > 0)
		  {
				byte bit = line % 2;
				line /= 2;
				if(bit) SetPixel(x + k ,y + i,color);
				k--;
		  }
  }
}
void printLetter(int x, int y, byte character, byte color)
{
  for(byte i = 0; i < 5; i++)
  {
		  byte line = font8x5[character-'A'][i];
		  byte k = 5;
		  while(line > 0)
		  {
				byte bit = line % 2;
				line /= 2;
				if(bit) SetPixel(x + k ,y + i,color);
				k--;
		  }
  }
}
void setup()
{
//
  Wire.begin();
  RTC.begin();
//
  //set pins to output because they are addressed in the main loop
  pinMode(aPin, OUTPUT);
  pinMode(bPin, OUTPUT); 
  pinMode(cPin, OUTPUT);
  pinMode(dPin, OUTPUT);
  pinMode(oePin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(strPin, OUTPUT);
  pinMode(sckPin, OUTPUT);
  digitalWrite(oePin, LOW);
  // turn off the light
  digitalWrite(greenPin, HIGH);
  digitalWrite(redPin, HIGH);
}
byte psec = 0, sec, cnt = 0;;
void loop()
{
//
  DateTime now = RTC.now();
  number = now.hour() * 100 + now.minute();
  i = number;
  dig1 = i/1000;
  i = i-(dig1*1000);
  dig2 = i/100;
  i = i-(dig2*100);
  dig3 = i/10;
  i = i-(dig3*10);
  dig4 = i;
  sec = now.second();
//
  ClearBuffer();
  printLetter(1,10,'H',COLOR_RED);
  printLetter(1+6,10,'E',COLOR_RED);
  printLetter(1+6+6,10,'L',COLOR_RED);
  printLetter(1+6+6+6,10,'L',COLOR_RED);
  printLetter(1+6+6+6+6,10,'O',COLOR_RED);
 
  printDigit(2,0,dig1,COLOR_GREEN);
  printDigit(8,0,dig2,COLOR_GREEN);
  printDigit(17,0,dig3,COLOR_GREEN);
  printDigit(23,0,dig4,COLOR_GREEN);
  if(sec == psec)
  {
		if(cnt == 0)
		{
			SetPixel(15,1,COLOR_ORANGE);
			SetPixel(15,2,COLOR_ORANGE);
			SetPixel(16,1,COLOR_ORANGE);
			SetPixel(16,2,COLOR_ORANGE);
			SetPixel(15,7-3,COLOR_ORANGE);
			SetPixel(15,8-3,COLOR_ORANGE);
			SetPixel(16,7-3,COLOR_ORANGE);
			SetPixel(16,8-3,COLOR_ORANGE);
		}
		else cnt--;
  }
  else
  {
	  psec = sec;
	  cnt = 20;
  }
// draw the screen ==================================================
  draw_buffer(80);
// END draw the screen ==============================================
}






Темы с аналогичным тегами Dot Matrix, dual color, Arduino, Red&Green, Clock, DIYJT

Количество пользователей, читающих эту тему: 0

0 пользователей, 0 гостей, 0 скрытых пользователей

Рейтинг@Mail.ru