Go Down

Topic: max 7219 rtc blinking the digits. (Read 565 times) previous topic - next topic

zeevy

I have a rtc with four 7 segment display driven by max7219 using the LedControl lib
is there any way to blink the any of the two digits ( either hours or minutes ) with out loosing the display data continuously?

this is need when i want to adjust the time, to know what i am adjusting (hours or minutes)

Paul__B

Is there any way to blink the any of the two digits ( either hours or minutes ) with out loosing the display data continuously?
Sure is!

this is need when i want to adjust the time, to know what i am adjusting (hours or minutes)
That sounds sensible.

Let's see your code (as per the instructions).

zeevy

Bellow is my code, i want to add few buttons so that i can change the date and time (not at written),


Code: [Select]
#include <TimerOne.h>
#include <Time.h>
#include <DS3232RTC.h>
#include <LedControl.h>
#include <Button.h>

#define DEBUG_LED       13

/*
 * Now we create a new LedControl.
 * We use pins 12,11 and 10 on the Arduino for the SPI interface
 * Pin 12 is connected to the DATA IN-pin of the first MAX7221
 * Pin 11 is connected to the CLK-pin of the first MAX7221
 * Pin 10 is connected to the LOAD(/CS)-pin of the first MAX7221   
 * There will only be a single MAX7221 attached to the arduino
 */
LedControl lc=LedControl(12,11,10,1);

tmElements_t datetime;

void setup(){

  pinMode(DEBUG_LED, OUTPUT); digitalWrite(DEBUG_LED, HIGH);
  delay(100);

  lc.shutdown(0,false);
  lc.setIntensity(0,5);
  lc.clearDisplay(0);

//  datetime.Hour = 12;
//  datetime.Minute = 01;
//  datetime.Second = 10;
//  datetime.Day = 24;
//  datetime.Month = 04;
//  datetime.Year = 2016 - 1970;
//  RTC.write(datetime);
    RTC.squareWave(SQWAVE_1_HZ);    //1 Hz square wave
}

unsigned long previousMillis = 0;
const long rtcDisplayInterval = 1000;

void loop(){

    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis >= rtcDisplayInterval || previousMillis == 0){
        previousMillis = currentMillis;
        display_time();
        digitalWrite(DEBUG_LED, !digitalRead(DEBUG_LED));
    }

}

void display_time(){
    RTC.read(datetime);
    print2Digit(datetime.Hour, 0, 1);
    print2Digit(datetime.Minute, 2, 3);
}

void print2Digit(int v, int a, int b) {
    lc.setDigit(0, b, (v%10), false);
    lc.setDigit(0, a, ((v/10)%10), false);
}

void print4Digit(int v) {
    lc.setDigit(0,3, (v%10), false);
    lc.setDigit(0,2, ((v/10)%10), false);
    lc.setDigit(0,1, ((v/100)%10), false);
    lc.setDigit(0,0, ((v/1000)%10), false);
}

Go Up