سلام بر دوستان
من یک برنامه از توی نت پیدا کردم که میاد ساعت تاریخ و دما میحط رو در نمایشگر نمایش میده
عکس :
متاسفانه این برنامه با این که خیلی عالی هست ولی مشکلاتی داره
1 - دکمه تنظیمات ساعت تاریخ نداره
2 - ساعت قابلیت کوک شدت برای الارم رو نداره
میخواستم ببینم دوستان کسی هست در این زمینه بتونه کمک کنه
ممنون میشم



[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <U8glib.h>
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <DS3232RTC.h>
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <Streaming.h>
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <Time.h>
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <Wire.h>
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "DateConvL.h"
uint16_t current_year, current_month, current_day;
DateConvL dateC;
//A linha abaixo define as conexoes do display e deve ser
//ajustada conforme o modelo utilizado
U8GLIB_KS0108_128 u8g(22, 23, 24, 25, 26, 27, 28, 29, 37, 33, 34, 36, 35); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16


int X2 = 0;
int Y2 = 0;
int X3 = 0;
int Y3 = 0;
float angulo = 0;
int posicao = 0;
int posicaoh = 0;
int temperatura =0;
int min_temp = 500;
int max_temp = -500;


int ScreenWith = 128;
int ScreenWithC = 96;
int ScreenHeight = 64;
int ScreenHeightC = 32;
[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] botao 3


int estado_botao = 0;
int btn_afzayesh=0;
int btn_kahesh=0;


char* dia_da_semana[]={
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};


void tela_1()
{
u8g.drawRFrame(0, 0, 128, 64, 3);
//Mostra temperatura
u8g.setPrintPos(20, 27);
u8g.print(temperatura);
u8g.drawStr( 42, 27, "C");
u8g.drawCircle(37, 31, 2);
mostra_relogio_digital();
//Mostra relogio analogico
fundo_relogio();
//Atualiza Ponteiro de horas
desenha_ponteiro(hour()-1, 12.0, 10);
//Atualiza Ponteiro de minutos
desenha_ponteiro(minute()-5, 60.0, 19);
//Atualiza Ponteiro de segundos
desenha_ponteiro(second()-5, 60, 21);
}


void tela_2()
{
u8g.drawRFrame(0, 0, 128, 64, 3);
u8g.drawRFrame(68, 4, 55, 56, 2);
mostra_relogio_digital();
u8g.setFont(u8g_font_5x8);
u8g.drawStr( 78, 35, "MIN");
u8g.drawStr( 78, 53, "MAX");
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(25, 37);
u8g.print(dia_da_semana[(weekday()-1)]);
//Mostra temperatura atual
u8g.setPrintPos(83, 19);
u8g.print(temperatura);
u8g.drawStr( 105, 19, "C");
u8g.drawCircle(100, 12, 2);
//Mostra temperatura minima
u8g.setPrintPos(98, 36);
u8g.print(min_temp);
u8g.drawCircle(113, 29, 2);
//Mostra temperatura maxima
u8g.setPrintPos(98, 54);
u8g.print(max_temp);
u8g.drawCircle(113, 47, 2);
}


void desenha_ponteiro(float valor, float rotacao, int Radius)
{
angulo = valor * 2.0 * 3.1415 / rotacao - 1,5707;
X2 = ScreenWithC + Radius * cos(angulo);
Y2 = ScreenHeightC + Radius * sin(angulo);
u8g.drawLine(ScreenWithC, ScreenHeightC, X2, Y2);
}


void fundo_relogio()
{
u8g.drawCircle(ScreenWithC, ScreenHeightC, 27);
u8g.drawCircle(ScreenWithC, ScreenHeightC, 1);
u8g.setFont(u8g_font_6x13);
u8g.setFontPosTop();
u8g.drawStr(90, 9, "12");
u8g.drawStr(114, 25, "3");
u8g.drawStr(94, 44, "6");
u8g.drawStr(74, 25, "9");


for(int traco_minuto = 0; traco_minuto<12; traco_minuto++)
{
//Desenha linhas relogio analogico
angulo = traco_minuto / 12.0 * 2 * 3.1415;
X2 = ScreenWithC + 25 * cos(angulo);
Y2 = ScreenHeightC + 25 * sin(angulo);
X3 = ScreenWithC + 25 * cos(angulo);
Y3 = ScreenHeightC + 25 * sin(angulo);
u8g.drawLine(X2, Y2, X3, Y3);
}
}


void mostra_relogio_digital()
{
//Mostra a data
u8g.setFont(u8g_font_5x8);
u8g.setPrintPos(8, 48);
u8g.print(dateC.global_year, DEC);
u8g.drawStr( 29, 48, "/");
u8g.setPrintPos(35, 48);
u8g.print(dateC.global_month, DEC);
u8g.drawStr( 48, 48, "/");
u8g.setPrintPos(55, 48);
u8g.print(dateC.global_day, DEC);
////////////////////////////////////////////////////////////
u8g.setPrintPos(8, 58);
u8g.print(year());
u8g.drawStr( 29, 58, "/");
u8g.setPrintPos(35, 58);
u8g.print(month());
u8g.drawStr( 48, 58, "/");
u8g.setPrintPos(55, 58);
u8g.print(day());
////////////////////////////////////////////////////////////
//Mostra hora e minutos
u8g.drawRBox(3, 4, 62, 21,2);
u8g.setColorIndex(0);
u8g.setFont(u8g_font_fub17);
u8g.drawStr(29,21,":");
//Acerta a posicao do digito caso a hora
//seja menor do que 10
if (hour() < 10)
{
u8g.drawStr(3,23,"0");
posicaoh = 16;
}
else posicaoh = 3;
u8g.setPrintPos(posicaoh, 23);
u8g.print(hour());
//Acerta a posicao do digito caso o minuto
//seja menor do que 10
if (minute() < 10)
{
u8g.drawStr(38,23,"0");
posicao = 51;
}
else posicao = 38;
u8g.setPrintPos(posicao ,23);
u8g.print(minute());
u8g.setColorIndex(1);
}


void setup()
{
pinMode(3, INPUT_PULLUP);
SetCurrentDate();
Serial.begin(9600);
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
setSyncProvider(RTC.get);
Serial << F("RTC Sync");
if (timeStatus() != timeSet) Serial << F(" FAIL!");
Serial << endl;
}


void loop()
{
dateC.ToShamsi(current_year,current_month,current_day);
temperatura = RTC.temperature() / 4.;
if (temperatura >= max_temp)
{
max_temp = temperatura;
}
if (temperatura <= min_temp)
{
min_temp = temperatura;
}
static time_t tLast;
time_t t;
tmElements_t tm;


//Verifica se foi setado um novo horario
//Formato: ano, mes, dia, hora, minuto, segundo
if (Serial.available() >= 12) {
int y = Serial.parseInt();
if (y >= 100 && y < 1000)
Serial<<F("Erro: Ano deve ter dois ou quatro digitos!") <<endl;
else {
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else //(y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = Serial.parseInt();
tm.Day = Serial.parseInt();
tm.Hour = Serial.parseInt();
tm.Minute = Serial.parseInt();
tm.Second = Serial.parseInt();
t = makeTime(tm);
RTC.set(t);
setTime(t);
Serial << F("Horario modificado para: ");
printDateTime(t);
Serial << endl;
while (Serial.available() > 0) Serial.read();
}
}
t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
Serial << endl;
}


//Verifica se o botao foi pressionado
boolean valor_botao = digitalRead(3);
if (valor_botao != 1)
{
while(digitalRead(3) != 1)
{
delay(100);
}
// Inverte o estado
estado_botao = !estado_botao;
}
////////////////////////////////////////////////////////////////////////////////////
u8g.firstPage();


////////////////////////////////////////////////////////////////////////////////////
//picture loop
u8g.firstPage();
do {
if (estado_botao == 0)
{
tela_1();
}
if (estado_botao == 1)
{
tela_2();
}
}
while( u8g.nextPage() );
delay(10);
}


//Mostra data e hora na serial
void printDateTime(time_t t)
{
printI00(day(t), 0);
Serial << monthShortStr(month(t)) << _DEC(year(t));
Serial << ' ';
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}


//Correcao para imprimir "00" ao inves de "0" caso
//o valor seja menor do que 10
void printI00(int val, char delim)
{
if (val < 10) Serial << '0';
Serial << _DEC(val);
if (delim > 0) Serial << delim;
return;
}
String SetCurrentDate()
{
char const *date = __DATE__;
char s_month[5];
int _month, _day, _year;
static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
sscanf(date, "%s %d %d", s_month, &current_day, &current_year);
current_month = ((strstr(month_names, s_month)-month_names)/3) + 1;
}




مهمان عزیز شما حق دیدن لینک ها را ندارید

عضویت