1

The display.

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

  • Instead of showing us someone else's code that does work, why not show us your code that doesn't work? We can't help you with your code if you show us something completely different. – Majenko Jul 5 '16 at 11:47
  • By delaying for 500ms you are going to take longer than 1second to complete loop(), so the clock will drift quite rapidly and you will see it jumping 2 seconds at a time. You haven't issued a tm1637.set(); call, is that relevant? – Code Gorilla Jul 5 '16 at 12:10
  • 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). – spund3 Jul 5 '16 at 12:23
  • OK, but does set(7) work? Does it make the display very bright, and set(1) make it dim? If it doesn't even do that, then you've got a bigger problem - like maybe you haven't connected CLK to pin 6 and DIO to pin 7 on your breadboard. – John Burger Jul 6 '16 at 1:45
  • Solution: After a lot of time, I've found the solution to it. Just I have to check if the seconds given are even. If seconds are even, enable both points using tm1637.point(POINT_OFF);. – spund3 Jul 9 '16 at 11:42
1

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 the void loop() waits x milis. So, it's a clock, and using that will make my clock go slow. – spund3 Jul 9 '16 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. – TisteAndii Jul 9 '16 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. – TisteAndii Jul 9 '16 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 Jul 9 '16 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. – TisteAndii Jul 9 '16 at 14:12
-1

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 is tm1637.point(POINT_OFF/POINT_ON – spund3 Jul 5 '16 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.