Necesitas tener la libreria SLCD en la carpeta /libraries creo recordar que un par o tres posts despues del código que has copiado hay un zip de jmcadsl donde posteó las librerias que el había utilizado, las copias todas dentro y a compilar.
Follow along with the video below to see how to install our site as a web app on your home screen.
Nota: Es posible que esta función no esté disponible en algunos navegadores.
Hola para todos:
Estoy empezando con el Arduino.
Tengo montado el reloj rtc ds1307, ademas de pantalla serial.
Intento empezar con el codigo usando lo que en esta pagina tenemos pero no logro que funcione. Me da errores de compilado.
Alguien con caridad me podría ayudar por favor.
Estoy muy agradecido y por favor no paréis.
Mi placa Arduino Uno. El LCd el de Sparkfun serial16x2.
Un abrazo
El error me da esto.
sketch_nov29a.cpp:186:24: error: SLCD.h: No such file or directory
sketch_nov29a.cpp: In function 'void loop()':
sketch_nov29a:163: error: expected primary-expression before '/' token
sketch_nov29a:163: error: 'Pausa' was not declared in this scope
sketch_nov29a:163: error: expected `;' before 'durante'
sketch_nov29a.cpp: At global scope:
sketch_nov29a:171: error: 'SLCD' does not name a type
sketch_nov29a.cpp: In function 'byte decToBcd(byte)':
sketch_nov29a:173: error: redefinition of 'byte decToBcd(byte)'
sketch_nov29a:29: error: 'byte decToBcd(byte)' previously defined here
sketch_nov29a.cpp: In function 'byte bcdToDec(byte)':
sketch_nov29a:177: error: redefinition of 'byte bcdToDec(byte)'
sketch_nov29a:35: error: 'byte bcdToDec(byte)' previously defined here
sketch_nov29a.cpp: In function 'void setup()':
sketch_nov29a:184: error: redefinition of 'void setup()'
sketch_nov29a:91: error: 'void setup()' previously defined here
sketch_nov29a:187: error: 'lcd' was not declared in this scope
sketch_nov29a.cpp: In function 'void Lcdini()':
sketch_nov29a:197: error: 'lcd' was not declared in this scope
sketch_nov29a.cpp: In function 'void lcdoff()':
sketch_nov29a:203: error: 'lcd' was not declared in this scope
sketch_nov29a.cpp: In function 'void FadeLcd()':
sketch_nov29a:212: error: 'lcd' was not declared in this scope
sketch_nov29a:216: error: 'lcd' was not declared in this scope
sketch_nov29a.cpp: In function 'void loop()':
sketch_nov29a:235: error: redefinition of 'void loop()'
sketch_nov29a:112: error: 'void loop()' previously defined here
sketch_nov29a.cpp: In function 'void getDateDs1307(byte*, byte*, byte*, byte*, byte*, byte*, byte*)':
sketch_nov29a:254: error: redefinition of 'void getDateDs1307(byte*, byte*, byte*, byte*, byte*, byte*, byte*)'
sketch_nov29a:71: error: 'void getDateDs1307(byte*, byte*, byte*, byte*, byte*, byte*, byte*)' previously defined here
sketch_nov29a.cpp: In function 'void InfoLcd()':
sketch_nov29a:280: error: 'lcd' was not declared in this scope
//
// CONTROLADOR ACUARIO V2.0 de jmcadsl
//FASE 1 - RELOJ
///////////////////////////////////////////////////////////////////////////
#include <Wire.h> // Esta es la libreria de comunicacion I2C
#define DS1307_I2C_ADDRESS 0x68
// Convierte números normales decimales a BCD (binario decimal codificado)
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convierte BCD (binario decimal codificado) a números normales decimales
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second));
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
// Establece la fecha y la hora del reloj
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
/*
// la primera vez debemos poner en hora, active esta parte y luego vuelva a quitarla
second = 00;
minute = 51;
hour = 20;
dayOfWeek = 2;
dayOfMonth = 30;
month = 11;
year = 10;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
*/
}
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
Serial.print("20");
if (year < 10) Serial.print("0");
Serial.print(year, DEC);
Serial.print("/");
if (month < 10) Serial.print("0");
Serial.print(month, DEC);
Serial.print("/");
if (dayOfMonth < 10) Serial.print("0");
Serial.print(dayOfMonth, DEC);
Serial.print(" ");
if (hour < 10) Serial.print("0");
Serial.print(hour, DEC);
Serial.print(":");
if (minute < 10) Serial.print("0");
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10) Serial.print("0");
Serial.print(second, DEC);
Serial.print(" Dia de la semana:");
Serial.println(dayOfWeek, DEC);
switch (dayOfWeek)
{
case 1:
Serial.println(" Lunes");
break;
case 2:
Serial.println(" Martes");
break;
case 3:
Serial.println(" Miercoles");
break;
case 4:
Serial.println(" Jueves");
break;
case 5:
Serial.println(" Viernes");
break;
case 6:
Serial.println(" Sabado");
break;
case 7:
Serial.println(" Domingo");
break;
}
delay(1000); //Pausa durante 1 segundo
}
////////////////////////////////////// FASE 2 INCLUSION RELOJ EN DISPLAY ///////////////////////////////////
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <SLCD.h> //LCD
#define numRows 2 //LCD filas
#define numCols 16 //LCD columnas
SLCD lcd = SLCD(numRows, numCols); //LCD
byte decToBcd(byte val)//RELOJ
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;//RELOJ
void setup()
{
Wire.begin(); //RELOJ
lcd.init(); //LCD
Serial.begin(9600); //LCD
}
//FUNCIONES SECUNDARIAS
//Iniciar LCD
void Lcdini ()
{
lcd.displayOn();
lcd.clear();
}
void lcdoff()
{
lcd.displayOff();
lcd.brightness(0);
}
// borra pantalla con fade
void FadeLcd()
{
for (char i=99; i>=4; i -= 5) {
lcd.brightness(i);
delay(50);
}
lcd.clear();
for (char i=0; i<100; i += 5) {
lcd.brightness(i);
delay(50);
}
}
// Pausa 3 segundos
void p ()
{
delay (3000);
}
//BUCLE PRINCIPAL
void loop ()
{
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); // LEEMOS LA HORA
InfoLcd(); //Informacion cada hora en pantalla lcd
}
// FUNCIONES PRINCIPALES
// Establece la fecha y el tiempo del ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
// INFORMACION EN PANTALLA LCD
void InfoLcd ()
{
//Nombre proyecto
Lcdini();
lcd.print("L&S NANO-REEF", 0, 2);
lcd.print("VER 2.0", 1, 4);
p();
FadeLcd(); // borra pantalla con fade
// ahora para mostrar fecha y hora
p();//pausa 3segundos
lcd.print("Hora:",0,1);
if (hour < 10) Serial.print("0");
Serial.print(hour, DEC);
Serial.print(":");
if (minute < 10) Serial.print("0");
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10) Serial.print("0");
Serial.print(second, DEC);
switch (dayOfWeek)
{
case 1:
lcd.print("Lun , ",1,0);
break;
case 2:
lcd.print("Mar , ",1,0);
break;
case 3:
lcd.print("Mie , ",1,0);
break;
case 4:
lcd.print("Jue , ",1,0);
break;
case 5:
lcd.print("Vie , ",1,0);
break;
case 6:
lcd.print("Sab , ",1,0);
break;
case 7:
lcd.print("Dom , ",1,0);
break;
}
Serial.print(dayOfMonth, DEC);
Serial.print("/");
if (month < 10) Serial.print("0");
Serial.print(month, DEC);
Serial.print("/");
Serial.print("20");
if (year < 10) Serial.print("0");
Serial.print(year, DEC);
p();
FadeLcd(); // borra pantalla con fade
lcdoff();
}
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <SLCD.h> //LCD
#define numRows 2 //LCD filas
#define numCols 16 //LCD columnas
SLCD lcd = SLCD(numRows, numCols); //LCD
byte decToBcd(byte val)//RELOJ
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;//RELOJ
void setup()
{
Wire.begin(); //RELOJ
lcd.init(); //LCD
Serial.begin(9600); //LCD
}
//FUNCIONES SECUNDARIAS
//Iniciar LCD
void Lcdini ()
{
lcd.displayOn();
lcd.clear();
}
void lcdoff()
{
lcd.displayOff();
lcd.brightness(0);
}
// borra pantalla con fade
void FadeLcd()
{
for (char i=99; i>=4; i -= 5) {
lcd.brightness(i);
delay(50);
}
lcd.clear();
for (char i=0; i<100; i += 5) {
lcd.brightness(i);
delay(50);
}
}
// Pausa 3 segundos
void p ()
{
delay (3000);
}
//BUCLE PRINCIPAL
void loop ()
{
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); // LEEMOS LA HORA
InfoLcd(); //Informacion cada hora en pantalla lcd
}
// FUNCIONES PRINCIPALES
// Establece la fecha y el tiempo del ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
// INFORMACION EN PANTALLA LCD
void InfoLcd ()
{
//Nombre proyecto
Lcdini();
lcd.print("L&S NANO-REEF", 0, 2);
lcd.print("VER 2.0", 1, 4);
p();
FadeLcd(); // borra pantalla con fade
// ahora para mostrar fecha y hora
p();//pausa 3segundos
lcd.print("Hora:",0,1);
if (hour < 10) Serial.print("0");
Serial.print(hour, DEC);
Serial.print(":");
if (minute < 10) Serial.print("0");
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10) Serial.print("0");
Serial.print(second, DEC);
switch (dayOfWeek)
{
case 1:
lcd.print("Lun , ",1,0);
break;
case 2:
lcd.print("Mar , ",1,0);
break;
case 3:
lcd.print("Mie , ",1,0);
break;
case 4:
lcd.print("Jue , ",1,0);
break;
case 5:
lcd.print("Vie , ",1,0);
break;
case 6:
lcd.print("Sab , ",1,0);
break;
case 7:
lcd.print("Dom , ",1,0);
break;
}
Serial.print(dayOfMonth, DEC);
Serial.print("/");
if (month < 10) Serial.print("0");
Serial.print(month, DEC);
Serial.print("/");
Serial.print("20");
if (year < 10) Serial.print("0");
Serial.print(year, DEC);
p();
FadeLcd(); // borra pantalla con fade
lcdoff();
}
hola he encontrado esta fuente dimmeable para led.
como lo veis
Hola Jmerino.
El codigo funciona. Una pregunta.
¿ Por que los cambios de pantalla de L&s nano reef a la hora son como a saltos?.
Luego entiendo que el display debería de mostrar también el día, con por ejemplo Jue. Creo que eso le indicamos en la ultima parte del programa.
No me aparece.
Espero no ser un plasta con tanta consulta.
Un abrazo.
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <SLCD.h> //LCD
#define numRows 2 //LCD filas
#define numCols 16 //LCD columnas
SLCD lcd = SLCD(numRows, numCols); //LCD
byte decToBcd(byte val)//RELOJ
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;//RELOJ
void setup()
{
Wire.begin(); //RELOJ
lcd.init(); //LCD
Serial.begin(9600); //LCD
}
//BUCLE PRINCIPAL
void loop ()
{
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); // LEEMOS LA HORA
InfoLcd(); //Informacion cada hora en pantalla lcd
}
// FUNCIONES PRINCIPALES
// Establece la fecha y el tiempo del ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
// INFORMACION EN PANTALLA LCD
void InfoLcd ()
{
//Nombre proyecto
lcd.print("INFINITY-REEF", 0, 2);
lcd.print("VER 2.0", 1, 4);
delay(2000);
lcd.clear(); // borra pantalla
// ahora para mostrar fecha y hora
lcd.print("Hora:",0,1);
if (hour < 10) Serial.print("0");
Serial.print(hour, DEC);
Serial.print(":");
if (minute < 10) Serial.print("0");
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10) Serial.print("0");
Serial.print(second, DEC);
switch (dayOfWeek)
{
case 1:
lcd.print("Lun , ",1,0);
break;
case 2:
lcd.print("Mar , ",1,0);
break;
case 3:
lcd.print("Mie , ",1,0);
break;
case 4:
lcd.print("Jue , ",1,0);
break;
case 5:
lcd.print("Vie , ",1,0);
break;
case 6:
lcd.print("Sab , ",1,0);
break;
case 7:
lcd.print("Dom , ",1,0);
break;
}
Serial.print(dayOfMonth, DEC);
Serial.print("/");
if (month < 10) Serial.print("0");
Serial.print(month, DEC);
Serial.print("/");
Serial.print("20");
if (year < 10) Serial.print("0");
Serial.print(year, DEC);
}