Go Down

Topic: max7219 RTC 7-segment clock (Read 1 time) previous topic - next topic

josh97531

I got this piece of code of the internet that runs 8 7-segment displays to show the time it also uses a ds1307 RTC so the time is kept when it is switched off but it gets some error messages when I verify it the main one is it says "call of overloaded 'write(int)' is ambiguous" what does it mean
Code: [Select]
// Simple clock using DS1307 RTC chip, Arduino and
// MAX7219 LED display driver
// more information at http://wp.me/pQmjR-BK
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
#include "LedControl.h" //  need the library
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
float t=0;
int a,b;
LedControl lc=LedControl(12,11,10,1); // lc is our object
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
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
// Assumes you're passing in valid numbers
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.write(0);
  Wire.write(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));     
  Wire.write(decToBcd(dayOfWeek));
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
  Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.read() & 0x7f);
  *minute     = bcdToDec(Wire.read());
  *hour       = bcdToDec(Wire.read() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month      = bcdToDec(Wire.read());
  *year       = bcdToDec(Wire.read());
}
void setup()
{
  // the zero refers to the MAX7219 number, it is zero for 1 chip
  lc.shutdown(0,false);// turn off power saving, enables display
  lc.setIntensity(0,8);// sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();
  // Change these values to what you want to set your clock to.
  // You probably only want to set your clock once and then remove
  // the setDateDs1307 call.
  second = 0;
  minute = 56;
  hour = 9;
  dayOfWeek = 5;
  dayOfMonth = 9;
  month = 7;
  year = 10;
  //   setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

void loop()
{
    lc.setChar(0,2,'-',false);
    lc.setChar(0,5,'-',false);
    getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
    if (hour<10)
    {
       lc.setDigit(0,0,0,false);
       lc.setDigit(0,1,hour,false);
    } else if (hour>=10)
    {
      t=hour/10;
      a=int(t);
       lc.setDigit(0,0,a,false);
       t=hour%10;
       lc.setDigit(0,1,t,false);
    }
     if (minute<10)
    {
       lc.setDigit(0,3,0,false);
       lc.setDigit(0,4,minute,false);
    } else if (minute>=10)
    {
      t=minute/10;
      a=int(t);
       lc.setDigit(0,3,a,false);
       t=minute%10;
       lc.setDigit(0,4,t,false);
    }
       if (second<10)
    {
       lc.setDigit(0,6,0,false);
       lc.setDigit(0,7,second,false);
        } else if (second>=10)
    {
      t=second/10;
      a=int(t);
       lc.setDigit(0,6,a,false);
       t=second%10;
       lc.setDigit(0,7,t,false);
    }
}
 

PaulS

Quote
when I verify it the main one is it says "call of overloaded 'write(int)' is ambiguous" what does it mean

It says something vaguely like that, but with a lot more detail - like exactly which file and exactly which line. Those details are important.

MikeDX

This is an awful bug in 1.0 to say the least

Where you have

Code: [Select]

Wire.write(0);


replace it with
Code: [Select]

Wire.write(zero);


then at the top of your code, under int a,b
Code: [Select]


byte zero = 0x00;


and you are good to go ;)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy