There must be some fundamental procedure in coding that I don't understand.
I am trying to compact my code into a Uno, principally by divesting some of the work into another, but there is also some opportunity for streamlining. This particularly applies to the clock, which was always a bit ragged.
Thanks to a pearl of wisdom from michael_x
http://arduino.cc/forum/index.php/topic,106697.msg800464.html#msg800464I have been able to save about 4.5k from a 17 396 byte sketch, which might be just enough to win. However.....
The following compiles OK at 12,790
//Arduino 1.0+ Only
//Objective is to dispense with RTClib.h Orig version 17 396
/currently 25/2 compiles to 12 790
#include <SD.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte second, minute, hour, day, month, year;
char filename[30] ;
File myFile;
void setup(){
Serial.begin(9600);
Wire.begin();
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("init. failed!");
return;
}
Serial.print("init. OK");
}
void loop(){
printDate();
getFileName;
delay(1000);
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
byte second = bcdToDec(Wire.read());
byte minute = bcdToDec(Wire.read());
byte hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
byte day = bcdToDec(Wire.read());
byte month = bcdToDec(Wire.read());
byte year = bcdToDec(Wire.read());
}
void getFileName(){
char TimeDate[9];
sprintf(filename, "%04u%02u%02u.csv", year, month, day);
}
void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}
At the start I have
byte second, minute, hour, day, month, year;
and it will not compile without it.
On the strength of that, the line stays in, but I then proceed to remove the byte definition from the printDate subroutine. The sketch still complied OK, which is reasonable but the count went up from 12 790 to 12 920.
So what gives? I expected the sketch to be more efficient.