DMD Text and Clock using Bluetooth

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
Danimoji
Posts: 1
Joined: Tue Feb 21, 2017 6:16 pm

DMD Text and Clock using Bluetooth

Post by Danimoji » Sun Oct 29, 2017 4:38 am

Hello there, I am new to this forum and I would like to ask on how to make this project work. I am using 4 DMD, I HC-06 Module, 1 DS1307 and an Arduino UNO. How this works is when you send a text it loops on to the text but when I want to switch to clock I'll key in another word for example "T" like so. However when I tried using my code, nothing worked so I was hoping that the fine people of this forum will help me determine where I went wrong. Here's the code and sorry for bad english :

#include <SPI.h>
#include <DMD.h>
#include <SoftwareSerial.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#include <TimerOne.h>
#include<EEPROM.h>
#define max_char 100
#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 2
//SoftwareSerial mySerial(2,3);
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
//(tx,rx);;
String readdata;
String keyword="1";
int flagCLOCK=0;

char message[max_char]; // stores you message
char dataprocess[max_char];//////////////////////////////////////////////////////////////////////////////////////////
char r_char; // reads each character
byte index = 0; // defines the position into your array
int incomingByte;
int j=0;

int hourNow; //Self explanatory
int minuteNow;
int secondNow;
int dayNow;
int monthNow;
int yearNow;
int weekdayNow;
int mode = 4; // a variable to hold the mode


void ShowDisplayData(unsigned int uiMode )
{
switch(mode){
case 1:
//mode1Display(weekdayNow, dayNow, monthNow, yearNow, minuteNow, true, hourNow, secondNow);
mode1Display(minuteNow, true, hourNow);
break;
}
}

//void mode1Display(unsigned int uiWeekday,unsigned int uiDay, unsigned int uiMonth, unsigned int uiYear, unsigned int uiMinute, byte bColonOn, unsigned int uiHour, unsigned int uiSecond)
void mode1Display(unsigned int uiMinute, byte bColonOn, unsigned int uiHour)
{
// // Show day of week
// switch(uiWeekday){
// case 1:
// dmd.drawString( 1, 17, "Sun", 3, GRAPHICS_NORMAL );
// break;
// case 2:
// dmd.drawString( 1, 17, "Mon", 3, GRAPHICS_NORMAL );
// break;
// case 3:
// dmd.drawString( 1, 17, "Tue", 3, GRAPHICS_NORMAL );
// break;
// case 4:
// dmd.drawString( 1, 17, "Wed", 3, GRAPHICS_NORMAL );
// break;
// case 5:
// dmd.drawString( 1, 17, "Thu", 3, GRAPHICS_NORMAL );
// break;
// case 6:
// dmd.drawString( 1, 17, "Fri", 3, GRAPHICS_NORMAL );
// break;
// case 7:
// dmd.drawString( 1, 17, "Sat", 3, GRAPHICS_NORMAL );
// break;
// }
//
// //draw the day
// dmd.drawChar( 20, 17, '0'+((uiDay%100) /10), GRAPHICS_NORMAL ); // first digit
// dmd.drawChar( 26, 17, '0'+ (uiDay%10), GRAPHICS_NORMAL ); // second digit
//
// //draw the month
// switch(uiMonth){
// case 1:
// dmd.drawString( 33, 17, "Jan", 3, GRAPHICS_NORMAL );
// break;
// case 2:
// dmd.drawString( 33, 17, "Feb", 3, GRAPHICS_NORMAL );
// break;
// case 3:
// dmd.drawString( 33, 17, "Mar", 3, GRAPHICS_NORMAL );
// break;
// case 4:
// dmd.drawString( 33, 17, "Apr", 3, GRAPHICS_NORMAL );
// break;
// case 5:
// dmd.drawString( 33, 17, "May", 3, GRAPHICS_NORMAL );
// break;
// case 6:
// dmd.drawString( 33, 17, "Jun", 3, GRAPHICS_NORMAL );
// break;
// case 7:
// dmd.drawString( 33, 17, "Jul", 3, GRAPHICS_NORMAL );
// break;
// case 8:
// dmd.drawString( 33, 17, "Aug", 3, GRAPHICS_NORMAL );
// break;
// case 9:
// dmd.drawString( 33, 17, "Sep", 3, GRAPHICS_NORMAL );
// break;
// case 10:
// dmd.drawString( 33, 17, "Oct", 3, GRAPHICS_NORMAL );
// break;
// case 11:
// dmd.drawString( 33, 17, "Nov", 3, GRAPHICS_NORMAL );
// break;
// case 12:
// dmd.drawString( 33, 17, "Dec", 3, GRAPHICS_NORMAL );
// break;
// }
//
// //draw the year
// dmd.drawChar( 52, 17, '0'+((uiYear%100) /10), GRAPHICS_NORMAL ); // first digit
// dmd.drawChar( 58, 17, '0'+ (uiYear%10), GRAPHICS_NORMAL ); // second digit

//draw the time
dmd.selectFont(System5x7);
dmd.drawChar( 2, 25,'0'+((uiHour%100)/10), GRAPHICS_NORMAL ); // first digit
dmd.drawChar( 8, 25, '0'+ (uiHour%10), GRAPHICS_NORMAL ); // second digit
dmd.drawChar( 14, 25,':', GRAPHICS_NORMAL ); // colon
dmd.drawChar( 19, 25, '0'+((uiMinute%100) /10), GRAPHICS_NORMAL ); // third digit
dmd.drawChar( 25, 25, '0'+ (uiMinute%10), GRAPHICS_NORMAL ); // fourth digit
// dmd.drawChar( 31, 25,':', GRAPHICS_NORMAL ); // colon
// dmd.drawChar( 36, 25,'0'+((uiSecond%100)/10), GRAPHICS_NORMAL ); // fifth digit
//dmd.drawChar( 42, 25, '0'+ (uiSecond%10), GRAPHICS_NORMAL ); // sixth digit
//end of the display routine
}

void functionDMD()
{
dmd.clearScreen( true );
dmd.selectFont(Arial_black_16);
dmd.drawMarquee(message, max_char,(32*DISPLAYS_ACROSS)-1 ,0);
long start=millis();
long timer=start;
boolean ret=false;
while(!ret){
if ((timer+60) < millis()) { //without eeprom
ret=dmd.stepMarquee(-1,0);
timer=millis();
}
}
}

void ScanDMD()
{
dmd.scanDisplayBySPI();
}

void setup()
{
Serial.begin(9600);
//mySerial.begin(9600);
Wire.begin();
Timer1.initialize( 5000 );
Timer1.attachInterrupt( ScanDMD );
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
}

void loop()
{
hourNow = hour();
minuteNow = minute();
secondNow = second();
dayNow = day();
monthNow = month();
yearNow = year();
weekdayNow = weekday();

ShowDisplayData(mode);
///////////////////////////////////////////////////////
while(Serial.available()>0 ){
//the message can have up to 100 characters
if(index < (max_char-1))
{
r_char = Serial.read(); // Reads a character
//incomingByte = Serial.read();
readdata+=r_char;
message[index] = r_char; // Stores the character in message array
//EEPROM.write(index,message[index]);
index++; // Increment position
message[index] = '\0'; // Delete the last position
dataprocess[index] = '\0';
Serial.println(index);

}
}
//////////////////////////////////////////////////////
for (j=1;j<index;j++)
{
dataprocess[j-1]=message[j];
}

for (j=0;j<index;j++)
{
Serial.println(dataprocess[j]);
}
//Serial.println( "");
index=0;
if(readdata.length()>0)
{

if(message[0]!='~')
{
////////////////////////////////////////////////////////
flagCLOCK=1;
//////////////////////////////////////////////////////
}
if(message[0]=='~')
{

//////////////////////////////////////////////////////////////START
flagCLOCK=2;
//////////////////////////////////////////////////////////////END
}
//readdata="";
}
if(flagCLOCK==2)
{
if (Serial.available() > 0) {
// read the oldest byte in the mySerial buffer:
incomingByte = Serial.read();

//if (/*message[0] == '1' && */message[1] == '~')
if (incomingByte == '1')
{
mode = 1;
Serial.print("Mode: ");
Serial.println(mode);
dmd.clearScreen( true );
}

//if (/*message[0] == '1' &&*/ message[1] =='H')
if (incomingByte == 'H')
{
hourNow++;
if(hourNow > 23){hourNow = 0;}
setTime(hourNow,minuteNow,secondNow,dayNow,monthNow,yearNow);
RTC.set(now());
Serial.println("Increasing hour");
delay(100);
}

//if (/*message[0] == '1' &&*/ message[1] =='h')
if (incomingByte == 'h')
{
hourNow--;
if(hourNow < 0){hourNow = 23;}
setTime(hourNow,minuteNow,secondNow,dayNow,monthNow,yearNow);
RTC.set(now());
Serial.println("Decreasing hour");
delay(100);
}

//if (/*message[0] == '1' &&*/ message[1] =='M')
if (incomingByte == 'M')
{
minuteNow++;
if(minuteNow > 59){minuteNow = 0;}
setTime(hourNow,minuteNow,secondNow,dayNow,monthNow,yearNow);
RTC.set(now());
Serial.println("Increasing minute");
delay(100);
}

//if (/*message[0] == '1' && */message[1] =='m')
if (incomingByte == 'm')
{
minuteNow--;
if(minuteNow < 0){minuteNow = 59;}
setTime(hourNow,minuteNow,secondNow,dayNow,monthNow,yearNow);
RTC.set(now());
Serial.println("Decreasing minute");
delay(100);
}
}
}
else if (flagCLOCK==1)
{
functionDMD();//panggil DMD
}
}

Sayantan
Posts: 3
Joined: Sat Oct 27, 2018 12:31 pm

Re: DMD Text and Clock using Bluetooth

Post by Sayantan » Sat Oct 27, 2018 7:22 pm

Have you tried using dedicated tx and rx pin on the Arduino to communicate with the Bluetooth module because I had some problem earlier while utilising software serial library it doesn't worked for some reason.

Post Reply