odd question?? difference between byte n and byte *n ???

Go To Last Post
27 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to work with a DS1307 library. in the library it has the following to set the RTC :
DS1307.h {snippet}

void setTime(byte *seconds, byte *minute, byte *hour, byte *AMPM);

and according to the Readme.TXT file to set
the time .. use this format :

RTC.setTime(seconds,minutes,hours);

but I get an

error: invalid conversion from 'byte' to 'byte*'

SO... the million dollar question .. what is the purpose of the "*" in the Library ?????

Any help .. thanks....

Note: the whole library can be found here:
https://github.com/brokenlcd/Ard...

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yikes. If you went thru Comp Sci school they would make you learn an assembly language for an old simple computer with an accumulator and an index register. Lets say 16 bits each. The index register holds The Address Of the Operand that gets loaded into the Accumulator. The dudes that wrote c in 73 were dec pdp8 programmers and that computer had some accumulators and index registers, so in c, there is a 'pointer' that gets the address of a port or a byte in memory, like the beginning of a table, and you read the byte at where the pointer is pointing by saying dat = *n; I will now turn the mic over to all the comp scis to confuse you further. Thankyou.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As a general rule, you can send values to a "Set()" method.
But you need to send addresses to a "Get()" method.

However, your partivcular library has chosen to use addresses to a Set() method. e.g.

byte hours = 20, minutes = 2, seconds = 38;

RTC.setTime(&seconds, &minutes, &hours); 

A 'normal' method would be:

RTC.normalsetTime(38, 2, 20); 

It really annoys me when people avoid spaces. They really do make your code more readable. i.e. you can see the '&'

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok... I learned the OLD 8051 in hex MANY years ago ....

So what I think you are talking about is the library is trying to set up a pointer in a memory register for EACH of the variables .... that way it can be called at any time from anywhere in the software. .... do I have that right ?

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

do I have that right

No need. You can just pass the address of the variable, as in David's example...
Quote:

byte hours = 20, minutes = 2, seconds = 38;

RTC.setTime(&seconds, &minutes, &hours);

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

SO... the million dollar question .. what is the purpose of the "*" in the Library ?????

Are you asking what, in general, the * denotes in C code in the context given? (Answer: A pointer to something rather that that something itself.)

Or are you asking why the library uses pointers as parameters?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can ONLY take addresses of variables:

RTC.setTime(&seconds, &minutes, &hours);

Note that you can NOT do this:

RTC.setTime(&38, &2, &20); 

However, with a normal Set() method, you can use variables or literal values:

RTC.normalsetTime(38, 2, 20); 
RTC.normalsetTime(seconds, minutes, hours); 

With a GET() method you can only return one value. If you want to receive more than one value, you have to use pointers. i.e. addresses.

Ok, you can return the address of a structure or the actual structure itself. This is sometimes a good way to do things.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok I see there are multiple functions
for the same call:

void setTime(byte &seconds, byte &minute, byte &hour, byte &AMPM);

void setTime(byte *seconds, byte *minute, byte *hour) { setTime(seconds, minute, hour, NULL); }

The second function does not have the * but it is called the same ....

can I remove the *'s in the whole library .h & .ccp files ... all Im wanting to do is to is to have a clock to track precisely the amount of time passed to be able to calculate WattHours and AmpHours in a battery charger/tester... would rather not use the millis() due to drift and some charge and discharge cycles take 20 hours. Millis() can overflow, and I don't want to have to retest just cause I caught a cycle in an overflow.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Darnit ... the first function should have been

void setTime(byte *seconds, byte *minute, byte *hour, byte *AMPM);

I was trying it with the & instead of * ....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK .. so ... hmmm...

In my program I should call

RTC.setTime( &seconds, &minutes, &hours); ??

ok .. then how to I shift load the data into the address pointer ...

or since I am not needing the Time and Date at a moments notice.... should I re write the library .. so that there is no pointers and that I will need to call the DS1307 to get the time each time.

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I dare say if you get rid of the pointers, then you'll learn the reason why they're used. I'd suggest you get a good book on C and understand the reasons. As such, if you've done 8051 asm you'll know of dptr(data pointer) and the indirect addressing of @R0. C is effectively no different.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I understand the purpose ... just not the usage... I am still trying to learn C and understanding all the nuances of coding ....my "Embedded C Programming and the Atmel AVR" has been a god send.... but ... the problem still is ....

All I want is to be able to set the time ... or reset it to 0:00:00 so I can track the time easily.

I have my the types of variables in the program (regarding the DS1307) as BYTE.. .. here is my code

/*
 * DS1307.h
 * Kyle Isom 
 *
 * Arduino library to use DS1307
 * I2C address is hardcoded as 110100 - the data sheet implicitly states
 * that only one DS1307 can be on the bus.
 *
 * Should load the Wire library if it is not already loaded. The Wire library
 * is released under the LGPL, and was written by Nicholas Zambetti.
 *
 * released under a BSD license
 *
 *  Copyright 2010 Kyle Isom. All rights reserved.
 *  
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions are met:
 *  
 *     1. Redistributions of source code must retain the above copyright notice, 
 *        this list of conditions and the following disclaimer.
 *  
 *     2. Redistributions in binary form must reproduce the above copyright 
 *        notice, this list of conditions and the following disclaimer in the 
 *        documentation and/or other materials provided with the distribution.
 *  
 *  THIS SOFTWARE IS PROVIDED BY KYLE ISOM ``AS IS'' AND ANY EXPRESS OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
 *  EVENT SHALL KYLE ISOM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *  
 *  The views and conclusions contained in the software and documentation are 
 *  those of the authors and should not be interpreted as representing official 
 *  policies, either expressed or implied, of Kyle Isom. 
 */

#ifndef __DS1307_H
#define __DS1307_H

#include "Arduino.h"



#define    DS1307_ADDR     0x68
#define    DS1307CH        0x07
#define    DS1307_SEC      0x7F
#define    DS1307_MODE     0x06
#define    DS1307_24HR     0x3F   
#define    DS1307_AMPM     0x20
#define    DS1307_12HR     0x1F
#define    DS1307_EPOCH    2000

 
 class DS1307 {
    public:
        /* constructor */
        // Pass a true if the DS1307 is the only I2C device on the bus
        DS1307(boolean singleDevice = false, boolean twentyfourhour = true);
        
        /* read function */
        boolean isEnabled(void);
        boolean check24Hour(void);
        void getTime(boolean AMPM, byte *seconds, byte *minute, byte *hour);
        void getTime(byte *seconds, byte *minute, byte *hour) { getTime(NULL, seconds, minute, hour); }
        void getDate(byte *day, byte *month, byte *year);
        void dayOfWeek(byte *weekday);
        void getDTC(byte *AMPM, byte *seconds, byte *minute, byte *hour, byte *weekday, byte *day, byte *month, byte *year);
        void getDTC(byte *seconds, byte *minute, byte *hour, byte *weekday, byte *day, byte *month, byte *year);
        
        /* write functions */
        void enableClock(void);
        void disableClock(void);
        void set24(void);
        void set12(void);
        void setup(void);
        void setTime(byte &seconds, byte &minute, byte &hour, byte &M);
        void setTime(byte *seconds, byte *minute, byte *hour) { setTime(seconds, minute, hour, NULL); }
        void setDate(byte *day, byte *month, byte *year);
        void setDayOfWeek(byte *weekday);
        void setDTC(byte *seconds, byte *minute, byte *hour, byte *weekday, byte *day, byte *month, byte *year);
        void setDTC(byte *seconds, byte *minute, byte *hour, byte *day, byte *month, byte *year);
        
        /* conversion functions */
        byte bcd_to_dec(byte data);
        byte dec_to_bcd(byte data);

    private:
        boolean twentyfour;
        
        void getHour24(byte hour);
        void getHour12(boolean AMPM, byte hour);
 };
 
#endif

I know it is not pretty .. but it is a menu for a LCD using the MCP23018 16bit I/O expander. and I have been creating it in sections.... the first layer of the menu all works great ... and the inputting the Time and Date works ....it is just when I have added RTC.setTime() that I have the error :
error: invalid conversion from 'byte' to 'byte*'
any suggestions ???

Thanks to bobgardner,david.prentice,theusch,JohanEkdahl and Kartman

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ARGH .. i am having one heck of a day .. sorry here is my program code ....not the DS1307.h

#include   // lcd using MCP23018 Library
#include 
#include   // DS1307 Libary
#include 
#include 		// INA219 voltage and current monitor
// ######### Function list  #######
LiquidTWI2 lcd(0x20,0);// inits LCD
DS1307 RTC;   // Inits the ds1307 as 'RTC'
INA219 monitor; // inits a single ina219 as 'monitor'
// ########## Define #######
//#define IntPin 5
byte IntPin = 5;
//#define INA219 64 // 0x40
byte INA219 = 0x40;
//#define DS1307 104 //0x68;
byte DS1207 = 0x68;
//#define EEprom 64 //0x50;
byte EEprom = 0x50;

// ############## Variables ############
boolean charge=true;
boolean keypress = true; // triggered by interrupt
byte StHr =12;
byte StTm, StM, StS, seconds, minutes, hours = 0;

byte SdD = 1;
byte SdM = 1;
byte SdY = 10;
byte st = 1;  // set time pointer
byte bl = 0;
int reading; // button variable
int capture; // interrupt ioportA reading
byte menu = 1; //  Main menu options		1,2,3,4,5
byte menu1 = 1; // Options Pointer		  	1,2,3
byte menu2 = 1; // Volts/Cell Pointer		1,2,3,4
byte menu3 = 1; // # of cells Pointer		1,2,3,4,5
byte menu4 = 1; // Ah Rating  Pointer		1,2,3,4,5,6,7
int Vbat ;
int Ibat ;
int AH ;
int timeStart;
int totalTime;
int temp;
byte StMin;
//pinMode(cPin,OUTPUT); // Charge enable pin
//pinMode(dPin,OUTPUT); // Discharge Enable Pin

void I1(){ // called  on Interrupt 
  //reading = lcd.readRegister(0x12);
  keypress = true; 
}

void setup()
{
  lcd.begin(20, 4);  		// setup lcd
  Serial.begin(19200); 		// setup serial for debugging
  pinMode(5,INPUT);    		// setup pin 5 as input (INT1)
  lcd.setRegister(0x00,0xFF); //sets IOa 0-6 inputs and 7 as output
  lcd.setRegister(0x0C,0xFF); // set pull ups on IOa
  lcd.setRegister(0x04,0xFF);  // enable Interrupts for GPIOA
  lcd.setRegister(0x06,0xFF);  // sets DEFAUT VAL 
  lcd.setRegister(0x08,0xFF);  // compare to Default Value
  temp = lcd.readRegister(MCP23017_GPIOA);// clears interrupt if present
  //####### boot screen ########
  lcd.setCursor(0,0);
  lcd.print("  Battery Tester");
  lcd.setCursor(0,1);
  lcd.print("   & Charger");
  delay(2000);
  lcd.clear();
  // ######## boot screen finished #######
  RTC.setup();  // Enables clock
  attachInterrupt(1,I1,FALLING); // inits INT1 for falling pointed to I1
// ##############  setup INA219 ########
  monitor.begin(INA219);
  monitor.configure(0,3,10,10,7); // 16V, Gain-8, Bus-4Avg, Shunt-4Avg,Mode-cont
  monitor.calibrate(.025,.5,20,5); // Shunt resistor, Vshunt MAX, Vbus Max, Imax

    }  // void setup() end

    void loop()
    {
      if (keypress == true & (menu < 5)) readButtons(); //Reads buttons and manages menu movement
      if (keypress == true & (menu < 5)) updateMenu(); // Updates Display for menu movement
      if (keypress == true & (menu > 4)) system();  // run operation & reads button for Operation
      if (keypress == true & (menu > 4)) updateDisplay();// updates Operational Display
     // if (menu>4) updateDisplay();

      if (LOW == digitalRead(IntPin)) temp = lcd.readRegister(MCP23017_GPIOA);
      //Serial.println("loop");
    }

void  readButtons(){  //read buttons status
  reading = lcd.readButtons();// reads present button reg
  capture = lcd.readRegister(MCP23017_INTCAPA);// clears interrupt
  while (lcd.readRegister(MCP23017_GPIOA)== capture){
  }// compares interrupt capture and present button reg (DEBOUNCE)

  switch(reading){
  case 2: //enter
    Serial.println("ENTER");
    if (3 == menu1) {menu = 5;} else {menu++;}
    break;
  case 1: // down
    Serial.println("up");
    if (1 == menu){if (3 ==menu1) menu1=1; else menu1++; }
    if (2 == menu){if (3 ==menu2) menu2=1; else menu2++; }
    if (3 == menu){if (5 ==menu3) menu3=1; else menu3++; }
    if (4 == menu){if (7 ==menu4) menu4=1; else menu4++; }
    break;
  case 4:
    Serial.println("down");
    if (1 == menu){if (1 ==menu1) menu1=3; else menu1--; }
    if (2 == menu){if (1 ==menu2) menu2=3; else menu2--; }
    if (3 == menu){if (1 ==menu3) menu3=5; else menu3--; }
    if (4 == menu){if (1 ==menu4) menu4=7; else menu4--; }
    break;
  case 8:
    Serial.println("Esc");
    menu=1;
    lcd.setCursor(0,1); 
    lcd.print("                    "); // clears old display
    break;
  case 10: // Back light toggle
    Serial.println("Esc & Enter: BackLight Control");
    lcd.setBacklight(bl);
    bl= !bl;
    break;
  default:
    break;
  }
  //if (3==menu1 & menu)
  delay(50);
} //void readButtons() end

void updateMenu()  { 
  Serial.print("update Menu");
  lcd.setCursor(0,0);  
  lcd.print("Choose Items Below");
  if (2 == menu){   // ****** THESE SET UP THE DISPLAY AFTER SELECTION *****
    lcd.setCursor(0,0); 
    lcd.print("                    ");
    lcd.setCursor(0,0);
    if (1 == menu1)lcd.print("   TEST BATTERY   ");
    if (2 == menu1)lcd.print("  CHARGE BATTERY  ");
    //if (3 == menu1) menu =5 ;//lcd.print("     SET TIME     ");
  }
  if (3 == menu) {
    lcd.setCursor(0,1); lcd.print("     "); lcd.setCursor(0,1);
    if (1 == menu2)lcd.print("1.2V");
    if (2 == menu2)lcd.print("4.2V");
    if (3 == menu2)lcd.print("12V");
  }
  if (4 == menu) {
    lcd.setCursor(5,1); lcd.print("       "); lcd.setCursor(6,1);
    if (1 == menu3) lcd.print("x1");
    if (2 == menu3) lcd.print("x2");
    if (3 == menu3) lcd.print("x3");
    if (4 == menu3) lcd.print("x4");
    if (5 == menu3) lcd.print("x6"); 
  }
  if (5 == menu) {
    lcd.setCursor(8,1); lcd.print("     "); lcd.setCursor(8,1);
    if (1 == menu4) lcd.print(" .5AH - 1AH");
    if (2 == menu4) lcd.print("  1AH - 3AH");
    if (3 == menu4) lcd.print("  3AH - 7AH");
    if (4 == menu4) lcd.print(" 7AH - 10AH");
    if (5 == menu4) lcd.print("10AH - 15AH");
    if (6 == menu4) lcd.print("15AH - 20AH");
    if (7 == menu4) lcd.print("20AH - 25AH");  
  }
  lcd.setCursor(0,2);
  lcd.print("                    ");
  lcd.setCursor(0,2);
  switch (menu){ // ****** THESE ARE THE CHOICES IN MENU ******
  case 1:
    lcd.print("  OPTIONS  :");
    lcd.setCursor(0,3); 
    lcd.print("              "); 
    lcd.setCursor(0,3);
    if (1 == menu1) lcd.print("  TEST BATTERY  ");
    if (2 == menu1) lcd.print(" CHARGE BATTERY ");
    if (3 == menu1) lcd.print("    SET TIME    ");
    break;
  case 2:
    lcd.print("Volts / Cell");
    lcd.setCursor(0,3); 
    lcd.print("                  "); 
    lcd.setCursor(0,3);
    if (1 == menu2) lcd.print("1.2V");
    if (2 == menu2) lcd.print("4.2V");
    if (3 == menu2) lcd.print(" 12V");
    break;
  case 3:
    lcd.print("# of Cells");
    lcd.setCursor(0,3); 
    lcd.print("                  "); 
    lcd.setCursor(0,3);
    if (1 == menu3) lcd.print(" 1 ");   
    if (2 == menu3) lcd.print(" 2 ");
    if (3 == menu3) lcd.print(" 3 ");
    if (4 == menu3) lcd.print(" 4 ");
    if (5 == menu3) lcd.print(" 6 ");
    break;
  case 4:
    lcd.print(" AH Rating");
    lcd.setCursor(0,3); 
    lcd.print("                  "); 
    lcd.setCursor(0,3);
    if (1 == menu4) lcd.print(" .5AH - 1AH ");
    if (2 == menu4) lcd.print("  1AH - 3AH ");
    if (3 == menu4) lcd.print("  3AH - 7AH ");
    if (4 == menu4) lcd.print(" 7AH - 10AH ");
    if (5 == menu4) lcd.print(" 10AH - 15AH");
    if (6 == menu4) lcd.print(" 15AH - 20AH");
    if (7 == menu4) lcd.print(" 20AH - 25AH");
    break;

  default:
    break;
  }

  keypress = false;

  Serial.print(menu);
  Serial.print(" : ");
  Serial.print(menu1);
  Serial.print(" : ");
  Serial.print(menu2);
  Serial.print(" : ");
  Serial.print(menu3);
  Serial.print(" : ");
  Serial.print(menu4);
  Serial.println("  ");
  //Serial.println(menu4);

} // void updateMenu() end

void updateDisplay(){

  switch(menu1) { 
  case 1:	//TEST BATTERY
    lcd.setCursor(0,0);
    lcd.print(" TESTING BATTERY ");
    lcd.setCursor(0,2);
    if (false ==charge) {lcd.print("Vbat   Ibat   AH "); }
    if (true == charge){lcd.print("Charging Batt First"); }
  break;
  case 2:	// Charge battery
  break;
  case 3: // set time and date
	if (st<4) {
		lcd.setCursor(0,0);lcd.print("    SET TIME");lcd.setCursor(15,0);Clock();
		lcd.setCursor(5,1);lcd.print("      ");
		if (StHr>9){lcd.setCursor(4,1);lcd.print(StHr);}
		else lcd.setCursor(5,1);lcd.print(StHr);
		lcd.setCursor(6,1);lcd.print(":");
		lcd.setCursor(7,1);lcd.print(StTm);
		lcd.setCursor(8,1);lcd.print(StM);
		lcd.setCursor(5,2);lcd.print("      ");
		if (1==st){lcd.setCursor(5,2);lcd.print("^");}
		if (2==st){lcd.setCursor(7,2);lcd.print("^");}
		if (3==st){lcd.setCursor(8,2);lcd.print("^");}
	}// end time setting display
	if (st>3) {
		lcd.setCursor(0,0);lcd.print("      SET DATE");lcd.setCursor(5,1);lcd.print("               ");
		lcd.setCursor(8,1);Clock();
		lcd.setCursor(5,2);lcd.print("               ");lcd.setCursor(5,2);
		(SdM < 10) ? lcd.print("0") : lcd.print(" ");
		lcd.print(SdM); 
		printDigits(SdD);printDigits(SdY);
		if (4==st){lcd.setCursor(6,3);lcd.print("^");}
		if (5==st){lcd.setCursor(9,3);lcd.print("^");}
		if (6==st){lcd.setCursor(12,3);lcd.print("^");}	
	} // end date setting display
		
  break;
 default:
   break;
  }
   keypress = false;
} // updateDisplay() end

void system(){ // runs operations And read buttons
lcd.clear();
  reading = lcd.readButtons();// reads present button reg
  capture = lcd.readRegister(MCP23017_INTCAPA);// clears interrupt
  while (lcd.readRegister(MCP23017_GPIOA)== capture){
  }
  Serial.print("system : "); Serial.print(reading); Serial.print("  :  "); Serial.print(menu1); Serial.print("  :  "); Serial.print(st);
  Serial.print("  :  "); Serial.print(StHr); Serial.print("  :  "); Serial.print(StTm);Serial.print("  :  "); Serial.println(StM);
 
  if (1 == menu1){} // testing
	//if (charge == true)
	//digitalwrite(cPin,High);
	
  if (2 == menu1) {// charging
	}
  if (3 == menu1) {//TIME SET
	switch(reading){
	case 2: // enter
                Serial.println("enter");
		st++;
		break;
	case 1: //up
                Serial.println("up");
		if (1==st){ if (23==StHr) StHr=0; else StHr++;}
		if (2==st){ if (5==StTm) StTm=0; else StTm++;} 
		if (3==st){ if (9==StM) StM=0; else StM++;}
		if (4==st){ if (12==SdM) SdM=1; else SdM++;}
		if (5==st){  // days adjustments
			if (1==SdM||3==SdM||5==SdM||7==SdM||8==SdM||10==SdM||12==SdM) // Months with 31 days
				{if (31==SdD) SdD=1; else SdD++;}
			if (4==SdM||6==SdM||9==SdM||11==SdM)  // months with 30 days
				{if (30==SdD) SdD=1; else SdD++;}
			if (2==SdM)   						  // month with 29 days possible due to leap years
				{if (29==SdM) SdD=1; else SdD++;}
			} // # of days in each month adjustment
		if (6==st){ if (99==SdY) SdY=1; else SdY++;}
		break;
	case 4: // down
                Serial.println("down");
		if (1==st){ if (0==StHr) StHr=23; else StHr--;}
		if (2==st){ if (0==StTm) StTm=5; else StTm--;} 
		if (3==st){ if (0==StM) StM=9; else StM--;}
		if (4==st){ if (1==SdM) SdM=12; else SdM--;}
		if (5==st){
			if (1==SdM||3==SdM||5==SdM||7==SdM||8==SdM||10==SdM||12==SdM) // months with 31 days
				{if (1==SdD) SdD=31; else SdD--;}
			if (4==SdM||6==SdM||9==SdM||11==SdM)
				{if (1==SdD) SdD=30; else SdD--;}
			if (2==SdM)
				{if (1==SdM) SdD=29; else SdD--;}
			} // # of days in each month adjustment
		if (6==st){ if (99==SdY) SdY=1; else SdY++;}
		break;
	case 8: //esc
                Serial.println("esc");
		menu = 1;
		lcd.clear();
		break;
	default:
		break;
		}
      if (4==st) {
        seconds = StS;
        minutes = ((StTm*10)+StM);
        hours = StHr;
        RTC.setTime(seconds,minutes,hours);
        } //updates RTC time
	  if (7==st) {RTC.setDate(SdD,SdM,SdY); menu = 1;}// updates RTC DATE and returns to Main Menu
	}
} // end void system() 

void Clock(){
  lcd.print(hour());
  printDigits(minute());
  printDigits(second());
}
void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  lcd.print(":");
  if(digits < 10) lcd.print("0");
  lcd.print(digits);
}
void Date(){
	printDigits(month());
	printDigits(day());
	printDigits(year());
}// end Date

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put a & in front of each variable.
Eg &seconds
That translates to the address of the variable seconds. The address is the pointer.
Conversely, if you're given a pointer and you want to access the variable it points to, then use *
Which you could translate to Access the variable AT that address.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
. I am still trying to learn C and understanding all the nuances of coding

Try a site/book about C++ as the function interface you gave (and the fact it is overloaded) are both C++, not just C operations.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok .. I got the RTC.setTime() part to work,
Was:

RTC.setTime(seconds,minutes,hours); 

The complier would erro on that line. I changed it to:

RTC.setTime(seconds,minutes,hours,NULL)); 

as in the DS1307.h library and I get an error but it does not stop on that line .... but just two lines down
the line

if (7==st) {RTC.setDate(SdD,SdM,SdY); menu = 1;}

it gets hung up on with ....
355: error: invalid conversion from 'byte' to 'byte*'
Same Error BUT if I add '&' before each variable I just get an Error Compiling :

Quote:

In file included from Charger_tester.ino:4:
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h: In member function 'void DS1307::setTime(byte*, byte*, byte*)':
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h:82: error: invalid conversion from 'byte*' to 'byte'
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h:82: error: initializing argument 1 of 'void DS1307::setTime(byte, byte, byte, byte)'
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h:82: error: invalid conversion from 'byte*' to 'byte'
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h:82: error: initializing argument 2 of 'void DS1307::setTime(byte, byte, byte, byte)'
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h:82: error: invalid conversion from 'byte*' to 'byte'
I:\Electronics files\arduino-1.0.5\Arduino\libraries\DS1307/DS1307.h:82: error: initializing argument 3 of 'void DS1307::setTime(byte, byte, byte, byte)'
Charger_tester.ino: In function 'void loop()':
Charger_tester.ino:84: warning: suggest parentheses around comparison in operand of &
Charger_tester.ino:85: warning: suggest parentheses around comparison in operand of &
Charger_tester.ino:86: warning: suggest parentheses around comparison in operand of &
Charger_tester.ino:87: warning: suggest parentheses around comparison in operand of &

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think if you take some time to study the method declarations and look at the types of the vars you are passing then the answer will appear.

go through and write them both out on a piece of paper and the mismatch will probably jump out at you.

The warning

Quote:
Charger_tester.ino:85: warning: suggest parentheses around comparison in operand of &
is just asking you to be very explicit with your comparison. It is a hint that you might have done something that you did not intend.

regards
Greg

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

... Thank you for all your help .... Im thinking of reverting to a different Library ...
I understand What the point is ... but just not the context...or all the rule and how to manipulate it ...

But I do wish to thank everyone that assisted...

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Note: the whole library can be found here:
https://github.com/brokenlcd/Ard...

I had a look at that. I see in DS1307.h:

        void setTime(byte *seconds, byte *minute, byte *hour, byte *AMPM);
        void setTime(byte *seconds, byte *minute, byte *hour) { setTime(seconds, minute, hour, NULL); }

This is very odd. Had the author never heard of C++ default parameters? It would not give me that great a warm and cosy feeling about this code if they missed the fact that they could simply have implemented:

        void setTime(byte *seconds, byte *minute, byte *hour, byte *AMPM = NULL);

Having a look round. There is another Arduino DS1307 library here:

http://www.pjrc.com/teensy/td_li...

That looks pretty interesting I think - you get to use the natural time.h style functionality as found in POSIX systems everywhere.

EDIT: By the way, above, you quoted:

void setTime(byte &seconds, byte &minute, byte &hour, byte &M);

void setTime(byte *seconds, byte *minute, byte *hour) { setTime(seconds, minute, hour, NULL); } 

which is actually different code to what I found in the current repository. Are you using an old version? The use of & in the first of these is a C++ only feature to pass a reference.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
This is very odd. Had the author never heard of C++ default parameters?
More than that, why are the parameters pointers in the first place? This is a set function after all. The function itself only dereferences the pointers anyways. It does not attempt (nor should it attempt) to alter the values.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no the quote was from me testing and trying to get it to work . the Original DS1307.h uses * not & ... I was just experimenting as I understand What a pointer is and an Address of the pointer ... but .... not all the context to it ....
Just feel like I see all the pieces to the puzzle .. but just can't see how they interconnect...

Michael

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

but just can't see how they interconnect...

Google "C pass by value versus pass by reference" for any number of articles that will tell you when * (in the interface) and & (in the parameter list) might be used. It's generally to update an "output" which is why we all think it a little strange that a function that only takes inputs might be using it.

As I say here (often) the problem with C code on the internet is that you never have a guarantee of provenance. You cannot easily tell (without experience) is something is a work of genius or a POS.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

It's generally to update an "output"

Or to pass a large or huge parameter.

I have always found it a sad thing that very few programming languages have separate mechanisms for specifying
- Parameter modified on return, and
- Parameter passed by reference
but that might be a consequence of my teaching days and over and over having to go through this "fuzzy semantics" of pass by reference.

I guess in C I do not miss it that much because the language is really just half of a high-level language...

(Cant recall which language, but I am fairly sure I dealt with one where parameters where qualified with "in", "out" or "inout". IIRC it was then up to the compiler to optimize the passing mechanism. Modula-2, perhaps?).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

(Cant recall which language, but I am fairly sure I dealt with one where parameters where qualified with "in", "out" or "inout".

Our coding standard simply mandates that in the comment on each parameter:

return_code_t
process_packet (
  char * buff, // [IN/OUT] initial data to be updates
  int len,     // [IN] length of data
  int *plen    // [OUT] actual number of bytes processed
) {
  // stuff

kind of thing. Actually to my ever dying shame there's also a specific order for IN's and OUT's but I cannot off-hand remember what it is!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote:

Cant recall which language, but I am fairly sure I dealt with one where parameters where qualified with "in", "out" or "inout".

It's Ada.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you again, Everyone.

I still have more research to read to help me understand it, But you have given me a great starting point.

Regarding the DS1307.h library ...
I have switched to a different library .. DS1307RTC .
It is a little more involved but it appears to be working and no ERROR COMPILING messages...

I know there is a Menu style library ... but the two I found did not play well with an I2C I/O LCD setup.

I would be curious on any suggestions as to my coding...

Thanks alot.

Michael