Hi everyone,
First of all, thanks for view my help request and second, i will try to explain all my doubts correctly.
I'm building a clock and it works correctly but i want to add two new things that are:
1 button for select the hours or the minutes
1 button for increment so i can adjust the time correctly.
I know that in my code i can adjust it but i want a way to do it manually.
Here's my code and sorry for it being in portuguese.
#include <RTClib.h> // i think i don't need this
#include <SevSeg.h>
#include <Wire.h>
#define DS1307_ADDRESS 0x68
SevSeg display7seg;
int valor = 0;
byte zero = 0x00;
unsigned long timer;
void setup()
{
Serial.begin(9600);
Wire.begin();
//this line can be removed after setting the hours and minutes.
//SelecionaDataeHora(); //tradution = selectDataandhour
//type of the display.
int displayType = COMMON_CATHODE;
//definition of pines
int digit1 = 10; //Pino Digito1 do display
int digit2 = 11; //Pino Digito2 do display
int digit3 = 12; //Pino Digito3 do display
int digit4 = 13; //Pino Digito4 do display
//Pinos ligados aos segmentos A - H
int segA = 2; //Pino segmento A
int segB = 3; //Pino segmento B
int segC = 4; //Pino segmento C
int segD = 5; //Pino segmento D
int segE = 6; //Pino segmento E
int segF = 7; //Pino segmento F
int segG = 8; //Pino segmento G
int segDP= 9; //Pino segmento H
//Define o numero de digitos do display
int numberOfDigits = 4;
//Inicializa o display
display7seg.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP);
//Nivel de brilho do display
display7seg.SetBrightness(100);
timer = millis();
}
void loop()
{
char tempString[10]; //Used for sprintf
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int segundos = ConverteparaDecimal(Wire.read());
int minutos = ConverteparaDecimal(Wire.read());
int horas = ConverteparaDecimal(Wire.read() & 0b111111);
sprintf(tempString, "%02d%02d", horas, minutos);
display7seg.DisplayString(tempString, 3);
Serial.print(segundos);
Serial.print("\n");
}
void SelecionaDataeHora() //Seta a data e a hora do DS1307
{
byte segundos = 10; //Valores de 0 a 59
byte minutos = 37; //Valores de 0 a 59
byte horas = 11; //Valores de 0 a 23
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //Stop no CI para que o mesmo possa receber os dados
//As linhas abaixo escrevem no CI os valores de
//data e hora que foram colocados nas variaveis acima
Wire.write(ConverteParaBCD(segundos));
Wire.write(ConverteParaBCD(minutos));
Wire.write(ConverteParaBCD(horas));
Wire.write(zero);
Wire.endTransmission();
}
byte ConverteParaBCD(byte val)
{
//Converte o número de decimal para BCD
return ( (val/10*16) + (val%10) );
}
byte ConverteparaDecimal(byte val)
{
//Converte de BCD para decimal
return ( (val/16*10) + (val%16) );
}
that's it.
hope you can help me. thanks !