Hello! In my project, using a display controlled by a TM1637, I want to make the two points on the middle of the screen blink (as every clock does).
The following example, provided by the library I'm using, makes the two points blink as I want (tm1637.point(POINT_ON/POINT_OFF);
is what enables/disbales the point):
#include <TimerOne.h>
#include "TM1637.h"
#define ON 1
#define OFF 0
int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};
unsigned char ClockPoint = 1;
unsigned char Update;
unsigned char halfsecond = 0;
unsigned char second;
unsigned char minute = 0;
unsigned char hour = 12;
#define CLK 2//pins definitions for TM1637 and can be changed to other ports
#define DIO 3
TM1637 tm1637(CLK,DIO);
void setup()
{
tm1637.set();
tm1637.init();
Timer1.initialize(500000);//timing for 500ms
Timer1.attachInterrupt(TimingISR);//declare the interrupt serve routine:TimingISR
}
void loop()
{
if(Update == ON)
{
TimeUpdate();
tm1637.display(TimeDisp);
}
}
void TimingISR()
{
halfsecond ++;
Update = ON;
if(halfsecond == 2){
second ++;
if(second == 60)
{
minute ++;
if(minute == 60)
{
hour ++;
if(hour == 24)hour = 0;
minute = 0;
}
second = 0;
}
halfsecond = 0;
}
// Serial.println(second);
ClockPoint = (~ClockPoint) & 0x01;
}
void TimeUpdate(void)
{
if(ClockPoint)tm1637.point(POINT_ON);
else tm1637.point(POINT_OFF);
TimeDisp[0] = hour / 10;
TimeDisp[1] = hour % 10;
TimeDisp[2] = minute / 10;
TimeDisp[3] = minute % 10;
Update = OFF;
}
I tried to do it as it was the famous "blink", but nothing works.
Here's what I have done:
#include "TM1637.h" // Library for the 4-Digit Display
#include "RTClib.h" // Library for the RTC
#include <SoftwareSerial.h>
#define CLK 6
#define DIO 7
TM1637 tm1637(CLK,DIO);
RTC_DS1307 RTC;
const int fotoRes = 2;
SoftwareSerial mySerial(10, 11);
void setup()
{
pinMode(fotoRes, INPUT);
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
tm1637.init();
}
void loop()
{
DateTime now = RTC.now();
tm1637.display(0,now.hour()/10);
tm1637.display(1,now.hour()%10);
tm1637.display(2,now.minute()/10);
tm1637.display(3,now.minute()%10);
tm1637.point(POINT_ON); //Like blink example.
delay(500);
tm1637.point(POINT_OFF);
delay(500);
}
EDIT: tm1637.set(0-7)
ONLY set the brightnes of the screen. What makes the two pints appear is tm1637.point(POINT_OFF/POINT_ON)
. I'm asking how can I do to make these two points blink. Thanks.
Arduino UNO R3, DigitalTube library by Grove
2 Answers 2
Calling the point()
method only updates a flag; you see the effect the next time you try to display a number. You can use something like this:
void show_time(DateTime &t){
tm1637.display(0,t.hour()/10);
tm1637.display(1,t.hour()%10);
tm1637.display(2,t.minute()/10);
tm1637.display(3,t.minute()%10);
}
void loop() {
DateTime now = RTC.now();
tm1637.point(POINT_ON);
show_time(now); // changes take effect here
delay(500);
tm1637.point(POINT_OFF);
show_time(now);
delay(500);
}
-
Using
delay();
makes thevoid loop()
waits x milis. So, it's a clock, and using that will make my clock go slow.spund3– spund32016年07月09日 11:40:29 +00:00Commented Jul 9, 2016 at 11:40 -
@spund3 Your question says you want it to be like the Blink example, which is what this is. Your example uses delay(). Have you tried running this code yet? If this isnt what you want then perhaps you should re-phrase your question.SoreDakeNoKoto– SoreDakeNoKoto2016年07月09日 12:55:26 +00:00Commented Jul 9, 2016 at 12:55
-
@spund3 Your question says you want it to be like the Blink example, which is what this is. Your example uses delay(). Have you tried running this code yet? If this isnt what you want then perhaps you should re-phrase your question.SoreDakeNoKoto– SoreDakeNoKoto2016年07月09日 13:13:16 +00:00Commented Jul 9, 2016 at 13:13
-
I was refering to the final result of the blink example, where the led blinks. I appreciate a lot your solution, but I've found mine yesterday. Thanks!spund3– spund32016年07月09日 13:57:52 +00:00Commented Jul 9, 2016 at 13:57
-
@spund3 Okay. The final result is still what you expect. You can run it to find out, so I can know if this is a valid answer for anyone else who has a similar question.SoreDakeNoKoto– SoreDakeNoKoto2016年07月09日 14:12:59 +00:00Commented Jul 9, 2016 at 14:12
I haven't used the TM1637 code, but I (think I) understand how it works.
In the original code is the following:
void setup()
{
tm1637.set();
tm1637.init();
But in your code you only do the following:
void setup()
{
...
tm1637.init();
Have you tried adding the tm1637.set();
line in?
-
Yes, and
tm1637.set(0-9)
only adjusts the brightness of the entire display. What enables/disables the points istm1637.point(POINT_OFF/POINT_ON
spund3– spund32016年07月05日 15:20:37 +00:00Commented Jul 5, 2016 at 15:20
tm1637.set(0-7)
is for adjusting the brightness of the display. If it's not declared on the scetch, the brightness for the display will be "typical_brightness" (2).set(7)
work? Does it make the display very bright, andset(1)
make it dim? If it doesn't even do that, then you've got a bigger problem - like maybe you haven't connectedCLK
to pin6
andDIO
to pin7
on your breadboard.tm1637.point(POINT_OFF);
.