Show Posts
Pages: [1] 2
1  Using Arduino / Storage / EEPROM & magnetic field on: October 25, 2012, 07:46:20 pm
Will magnetic field of 12v DC micro motor mess up or destroy the memory of EEPROM chip if place it  2...3 cm away from the chip ?
2  Using Arduino / Programming Questions / Re: extracting from string on: September 20, 2012, 09:38:54 am
Thank you !
3  Using Arduino / Programming Questions / Re: extracting from string on: September 20, 2012, 09:25:21 am
So how to correct my code?
Please help.
Can it be done this way?
Code:
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
 
}

void loop() {
  // indexOf() returns the position (i.e. index) of a particular character

  String sensorstringEC = "5000,32800,32.7";
  int firstComma = sensorstringEC.indexOf(',');
  Serial.println("The index of ',' in the string " + sensorstringEC + " is " + firstComma);
String EC = sensorstringEC.substring(0,firstComma);
Serial.println("The first reading of " + sensorstringEC + " is " + EC);
 char bufEC[EC.length()];
   EC.toCharArray(bufEC, EC.length()+1);
  float EC_reading = atof(bufEC);
   Serial.println(EC_reading);   
  // do nothing while true:
  while(true);
}
4  Using Arduino / Programming Questions / Re: extracting from string on: September 20, 2012, 08:44:03 am
Thank you.
It works, but instead of 5000 it gives me 500. Why?
Code:
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
 
}

void loop() {
  // indexOf() returns the position (i.e. index) of a particular character

  String sensorstringEC = "5000,32800,32.7";
  int firstComma = sensorstringEC.indexOf(',');
  Serial.println("The index of ',' in the string " + sensorstringEC + " is " + firstComma);
String EC = sensorstringEC.substring(0,firstComma);
Serial.println("The first reading of " + sensorstringEC + " is " + EC);
 char bufEC[EC.length()];
   EC.toCharArray(bufEC, EC.length());
  float EC_reading = atof(bufEC);
   Serial.println(EC_reading);  
  // do nothing while true:
  while(true);
}
5  Using Arduino / Programming Questions / Re: extracting from string on: September 20, 2012, 06:45:30 am
OK, can convert into int.
For me is more important to know how to extract the first reading.
I am using following code:
Code:
/*
This software was made to demonstrate how to quickly get your Atlas Scientific product running on the Arduino platform.
An Arduino MEGA 2560 board was used to test this code.
This code was written in the Arudino 1.0 IDE
Modify the code to fit your system.
**Type in a command in the serial monitor and the Atlas Scientific product will respond.**
**The data from the Atlas Scientific product will come out on the serial monitor.**
Code efficacy was NOT considered, this is a demo only.
The TX3 line goes to the RX pin of your product.
The RX3 line goes to the TX pin of your product.
Make sure you also connect to power and GND pins to power and a common ground.
Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the baud rate to 38400.
Remember, select carriage return from the drop down menu next to the baud rate selection; not "both NL & CR".
*/



String inputstring = "";                                                       //a string to hold incoming data from the PC
String sensorstring = "";                                                      //a string to hold the data from the Atlas Scientific product
boolean input_stringcomplete = false;                                          //have we received all the data from the PC
boolean sensor_stringcomplete = false;                                         //have we received all the data from the Atlas Scientific product


  void setup(){                                                                //set up the hardware
     Serial.begin(38400);                                                      //set baud rate for the hardware serial port_0 to 38400
     Serial3.begin(38400);                                                     //set baud rate for software serial port_3 to 38400
     inputstring.reserve(5);                                                   //set aside some bytes for receiving data from the PC
     sensorstring.reserve(30);                                                 //set aside some bytes for receiving data from Atlas Scientific product
     }
 
 
 
   void serialEvent() {                                                         //if the hardware serial port_0 receives a char             
               char inchar = (char)Serial.read();                               //get the char we just received
               inputstring += inchar;                                           //add it to the inputString
               if(inchar == '\r') {input_stringcomplete = true;}                //if the incoming character is a <CR>, set the flag
              } 


  void serialEvent3(){                                                         //if the hardware serial port_3 receives a char
              char inchar = (char)Serial3.read();                              //get the char we just received
              sensorstring += inchar;                                          //add it to the inputString
              if(inchar == '\r') {sensor_stringcomplete = true;}               //if the incoming character is a <CR>, set the flag
             }



 void loop(){                                                                   //here we go....
     
  if (input_stringcomplete){                                                   //if a string from the PC has been recived in its entierty
      Serial3.print(inputstring);                                              //send that string to the Atlas Scientific product
      inputstring = "";                                                        //clear the string:
      input_stringcomplete = false;                                            //reset the flage used to tell if we have recived a completed string from the PC
      }

if (sensor_stringcomplete)  //if a string from the Atlas Scientific product has been received in its entirety
 {
   
   Serial.println(sensorstring);
      sensorstring = "";                                                       //clear the string:
      sensor_stringcomplete = false; }                                          //reset the flage used to tell if we have recived a completed string from the Atlas Scientific product
      }
6  Using Arduino / Programming Questions / Re: extracting from string on: September 20, 2012, 06:35:18 am
Thank you for reply.
But I am new to programming,
so can you please explain in more detail.
Sorry for poor English.
7  Using Arduino / Programming Questions / extracting from string on: September 20, 2012, 06:00:31 am
   Data output of my EC probe circuit   is a comma separated  String as shown below:
5000, 32800, 32.7 <CR>
This data is (up to 17) ASCII digits representing   EC/TDS/Salinity and ending with a carriage return(ASCII 13).
I need to extract the first reading (5000) and convert it into float.
Please advise me on the above.

   I also have  pH probe  circuit .
 Output  example is as shown below:
4.60 <CR>
To transform String into float I am using following  code ( it works, no problem):
Code:
if (sensorPH_stringcomplete){                                                 
 //if a string from the Atlas Scientific product has been recived in its entierty
    char buf[sensorstringPH.length()];
   sensorstringPH.toCharArray(buf, sensorstringPH.length());
  float pH_reading = atof(bufPH);
   Serial.println(pH_reading);                                               
//send that string to to the PC's serial monitor
}
8  Using Arduino / Programming Questions / Re: Atlas Scientific pH kit code modification on: August 26, 2012, 02:55:24 am
Thank you very much.
9  Using Arduino / Programming Questions / Atlas Scientific pH kit code modification on: August 25, 2012, 10:16:35 pm
I have Atlas Scientific pH kit.  
https://www.atlas-scientific.com/product_pages/kits/ph-kit.html#ecwid:
Arduino Mega Sample Code:
Code:
/*
This software was made to demonstrate how to quickly get your Atlas Scientific product running on the Arduino platform.
An Arduino MEGA 2560 board was used to test this code.
This code was written in the Arudino 1.0 IDE
Modify the code to fit your system.
**Type in a command in the serial monitor and the Atlas Scientific product will respond.**
**The data from the Atlas Scientific product will come out on the serial monitor.**
Code efficacy was NOT considered, this is a demo only.
The TX3 line goes to the RX pin of your product.
The RX3 line goes to the TX pin of your product.
Make sure you also connect to power and GND pins to power and a common ground.
Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the baud rate to 38400.
Remember, select carriage return from the drop down menu next to the baud rate selection; not "both NL & CR".
*/



String inputstring = "";                                                       //a string to hold incoming data from the PC
String sensorstring = "";                                                      //a string to hold the data from the Atlas Scientific product
boolean input_stringcomplete = false;                                          //have we received all the data from the PC
boolean sensor_stringcomplete = false;                                         //have we received all the data from the Atlas Scientific product


  void setup(){                                                                //set up the hardware
     Serial.begin(38400);                                                      //set baud rate for the hardware serial port_0 to 38400
     Serial3.begin(38400);                                                     //set baud rate for software serial port_3 to 38400
     inputstring.reserve(5);                                                   //set aside some bytes for receiving data from the PC
     sensorstring.reserve(30);                                                 //set aside some bytes for receiving data from Atlas Scientific product
     }
 
 
 
   void serialEvent() {                                                         //if the hardware serial port_0 receives a char              
               char inchar = (char)Serial.read();                               //get the char we just received
               inputstring += inchar;                                           //add it to the inputString
               if(inchar == '\r') {input_stringcomplete = true;}                //if the incoming character is a <CR>, set the flag
              }  


  void serialEvent3(){                                                         //if the hardware serial port_3 receives a char
              char inchar = (char)Serial3.read();                              //get the char we just received
              sensorstring += inchar;                                          //add it to the inputString
              if(inchar == '\r') {sensor_stringcomplete = true;}               //if the incoming character is a <CR>, set the flag
             }



 void loop(){                                                                   //here we go....
    
  if (input_stringcomplete){                                                   //if a string from the PC has been recived in its entierty
      Serial3.print(inputstring);                                              //send that string to the Atlas Scientific product
      inputstring = "";                                                        //clear the string:
      input_stringcomplete = false;                                            //reset the flage used to tell if we have recived a completed string from the PC
      }

 if (sensor_stringcomplete){                                                   //if a string from the Atlas Scientific product has been recived in its entierty
      Serial.println(sensorstring);                                            //send that string to to the PC's serial monitor
      sensorstring = "";                                                       //clear the string:
      sensor_stringcomplete = false;                                           //reset the flage used to tell if we have recived a completed string from the Atlas Scientific product
      }
 }


In order to get continuous reading from ph stamp it is necessary to send C<CR> command using Serial Monitor.
OK, fine. But every time if I off and then on the board I have to send command again to get ph reading. For me this is problem as I plan to use stamp in portable ph controller. Is there any way to trigger continuous mode when arduino is not connected to computer, without using Serial Monitor?
 
Thank you.
10  Using Arduino / Programming Questions / Re: Real Time Clock code update to Arduino 1.0 on: August 17, 2012, 06:03:45 am

This library DS1307.h is modified  for v1.0:
http://arduino.cc/forum/index.php?topic=93077.0
11  Using Arduino / Programming Questions / Re: Real Time Clock code update to Arduino 1.0 on: August 09, 2012, 08:54:48 am
Error message:
In file included from C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:26,
                 from C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Stream.h:26,
                 from C:\Users\user\Desktop\arduino-1.0\libraries\DHT/../Wire/Wire.h:24,
                 from C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:3:
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp: In member function 'void DS1307::read()':
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:23: error: call of overloaded 'write(int)' is ambiguous
C:\Users\user\Desktop\arduino-1.0\libraries\DHT/../Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:31: error: 'class TwoWire' has no member named 'receive'
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp: In member function 'void DS1307::save()':
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:39: error: call of overloaded 'write(int)' is ambiguous
C:\Users\user\Desktop\arduino-1.0\libraries\DHT/../Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)
12  Using Arduino / Programming Questions / Re: Real Time Clock code update to Arduino 1.0 on: August 09, 2012, 08:53:59 am
File DS1307.h:
Code:
  DS1307.h - library for DS1307 rtc
*/


// ensure this library description is only included once
#ifndef DS1307_h
#define DS1307_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"

#else
#include "WProgram.h"
#include "WConstants.h"
#endif


// include types & constants of Wire ic2 lib
#include <../Wire/Wire.h>

#define DS1307_SEC 0
#define DS1307_MIN 1
#define DS1307_HR 2
#define DS1307_DOW 3
#define DS1307_DATE 4
#define DS1307_MTH 5
#define DS1307_YR 6

#define DS1307_BASE_YR 2000

#define DS1307_CTRL_ID B1101000  //DS1307

 // Define register bit masks
#define DS1307_CLOCKHALT B10000000

#define DS1307_LO_BCD  B00001111
#define DS1307_HI_BCD  B11110000

#define DS1307_HI_SEC  B01110000
#define DS1307_HI_MIN  B01110000
#define DS1307_HI_HR   B00110000
#define DS1307_LO_DOW  B00000111
#define DS1307_HI_DATE B00110000
#define DS1307_HI_MTH  B00110000
#define DS1307_HI_YR   B11110000

// library interface description
class DS1307
{
  // user-accessible "public" interface
  public:
    DS1307();
    void get(int *, boolean);
    int get(int, boolean);
void set(int, int);
    void start(void);
    void stop(void);

  // library-accessible "private" interface
  private:
    byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
void read(void);
void save(void);
};

extern DS1307 RTC;

#endif
13  Using Arduino / Programming Questions / Re: Real Time Clock code update to Arduino 1.0 on: August 09, 2012, 08:10:24 am
This is error message:
I

In file included from C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:26,
                 from C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Stream.h:26,
                 from C:\Users\user\Desktop\arduino-1.0\libraries\DHT/../Wire/Wire.h:24,
                 from C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:3:
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp: In member function 'void DS1307::read()':
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:23: error: call of overloaded 'write(int)' is ambiguous
C:\Users\user\Desktop\arduino-1.0\libraries\DHT/../Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:31: error: 'class TwoWire' has no member named 'receive'
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp: In member function 'void DS1307::save()':
C:\Users\user\Desktop\arduino-1.0\libraries\DS1307\DS1307.cpp:39: error: call of overloaded 'write(int)' is ambiguous
C:\Users\user\Desktop\arduino-1.0\libraries\DHT/../Wire/Wire.h:55: note: candidates are: virtual size_t TwoWire::write(uint8_t)
C:\Users\user\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)
14  Using Arduino / Programming Questions / Re: Real Time Clock code update to Arduino 1.0 on: August 09, 2012, 08:08:44 am
This is how I change DS1307.h file:
Code:
/*
  DS1307.h - library for DS1307 rtc
*/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"

#else
#include "WProgram.h"
#include "WConstants.h"
#endif

// ensure this library description is only included once
#ifndef DS1307_h
#define DS1307_h



// include types & constants of Wire ic2 lib
#include <../Wire/Wire.h>

#define DS1307_SEC 0
#define DS1307_MIN 1
#define DS1307_HR 2
#define DS1307_DOW 3
#define DS1307_DATE 4
#define DS1307_MTH 5
#define DS1307_YR 6

#define DS1307_BASE_YR 2000

#define DS1307_CTRL_ID B1101000  //DS1307

 // Define register bit masks
#define DS1307_CLOCKHALT B10000000

#define DS1307_LO_BCD  B00001111
#define DS1307_HI_BCD  B11110000

#define DS1307_HI_SEC  B01110000
#define DS1307_HI_MIN  B01110000
#define DS1307_HI_HR   B00110000
#define DS1307_LO_DOW  B00000111
#define DS1307_HI_DATE B00110000
#define DS1307_HI_MTH  B00110000
#define DS1307_HI_YR   B11110000

// library interface description
class DS1307
{
  // user-accessible "public" interface
  public:
    DS1307();
    void get(int *, boolean);
    int get(int, boolean);
void set(int, int);
    void start(void);
    void stop(void);

  // library-accessible "private" interface
  private:
    byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
void read(void);
void save(void);
};

extern DS1307 RTC;

#endif

This is how I change DS1307.cpp file:
Code:
extern "C" {
#include <../Wire/Wire.h>
}
#include "DS1307.h"

DS1307::DS1307()
{
  Wire.begin();
}

DS1307 RTC=DS1307();

// PRIVATE FUNCTIONS

// Aquire data from the RTC chip in BCD format
// refresh the buffer
void DS1307::read(void)
{
  // use the Wire lib to connect to tho rtc
  // reset the resgiter pointer to zero
  Wire.beginTransmission(DS1307_CTRL_ID);
  Wire.write(0x00);
  Wire.endTransmission();

  // request the 7 bytes of data    (secs, min, hr, dow, date. mth, yr)
  Wire.requestFrom(DS1307_CTRL_ID, 7);
  for(int i=0; i<7; i++)
  {
    // store data in raw bcd format
    rtc_bcd[i]=Wire.receive();
  }
}

// update the data on the IC from the bcd formatted data in the buffer
void DS1307::save(void)
{
  Wire.beginTransmission(DS1307_CTRL_ID);
  Wire.write(0x00); // reset register pointer
  for(int i=0; i<7; i++)
  {
    Wire.write(rtc_bcd[i]);
  }
  Wire.endTransmission();
}


// PUBLIC FUNCTIONS
void DS1307::get(int *rtc, boolean refresh)   // Aquire data from buffer and convert to int, refresh buffer if required
{
  if(refresh) read();
  for(int i=0;i<7;i++)  // cycle through each component, create array of data
  {
    rtc[i]=get(i, 0);
  }
}

int DS1307::get(int c, boolean refresh)  // aquire individual RTC item from buffer, return as int, refresh buffer if required
{
  if(refresh) read();
  int v=-1;
  switch(c)
  {
  case DS1307_SEC:
    v=(10*((rtc_bcd[DS1307_SEC] & DS1307_HI_SEC)>>4))+(rtc_bcd[DS1307_SEC] & DS1307_LO_BCD);
    break;
  case DS1307_MIN:
    v=(10*((rtc_bcd[DS1307_MIN] & DS1307_HI_MIN)>>4))+(rtc_bcd[DS1307_MIN] & DS1307_LO_BCD);
    break;
  case DS1307_HR:
    v=(10*((rtc_bcd[DS1307_HR] & DS1307_HI_HR)>>4))+(rtc_bcd[DS1307_HR] & DS1307_LO_BCD);
    break;
  case DS1307_DOW:
    v=rtc_bcd[DS1307_DOW] & DS1307_LO_DOW;
    break;
  case DS1307_DATE:

    
       v=rtc_bcd[DS1307_DATE]/16 * 10 +  rtc_bcd[DS1307_DATE] % 16;
    
    break;
  case DS1307_MTH:
    v=(10*((rtc_bcd[DS1307_MTH] & DS1307_HI_MTH)>>4))+(rtc_bcd[DS1307_MTH] & DS1307_LO_BCD);
    break;
  case DS1307_YR:

    
      v=2000 + rtc_bcd[DS1307_YR]/16 * 10 + rtc_bcd[DS1307_YR] % 16;
    
    break;

  } // end switch
  return v;
}

void DS1307::set(int c, int v)  // Update buffer, then update the chip
{
  switch(c)
  {
  case DS1307_SEC:
    if(v<60 && v>-1)
    {
      //preserve existing clock state (running/stopped)
      int state=rtc_bcd[DS1307_SEC] & DS1307_CLOCKHALT;
      rtc_bcd[DS1307_SEC]=state | ((v / 10)<<4) + (v % 10);
    }
    break;
  case DS1307_MIN:
    if(v<60 && v>-1)
    {
      rtc_bcd[DS1307_MIN]=((v / 10)<<4) + (v % 10);
    }
    break;
  case DS1307_HR:
    // TODO : AM/PM  12HR/24HR
    if(v<24 && v>-1)
    {
      rtc_bcd[DS1307_HR]=((v / 10)<<4) + (v % 10);
    }
    break;
  case DS1307_DOW:
    if(v<8 && v>-1)
    {
      rtc_bcd[DS1307_DOW]=v;
    }
    break;
  case DS1307_DATE:
    if(v<32 && v>-1)
    {
      rtc_bcd[DS1307_DATE]=((v / 10)<<4) + (v % 10);
    }
    break;
  case DS1307_MTH:
    if(v<13 && v>-1)
    {
      rtc_bcd[DS1307_MTH]=((v / 10)<<4) + (v % 10);
    }
    break;
  case DS1307_YR:
    if(v<50 && v>-1)
    {
      rtc_bcd[DS1307_YR]=((v / 10)<<4) + (v % 10);
    }
    break;
  } // end switch
  save();
}

void DS1307::stop(void)
{
  // set the ClockHalt bit high to stop the rtc
  // this bit is part of the seconds byte
  rtc_bcd[DS1307_SEC]=rtc_bcd[DS1307_SEC] | DS1307_CLOCKHALT;
  save();
}

void DS1307::start(void)
{
  // unset the ClockHalt bit to start the rtc
  // TODO : preserve existing seconds
  rtc_bcd[DS1307_SEC]=0;
  save();
}


15  Using Arduino / Programming Questions / Re: Real Time Clock code update to Arduino 1.0 on: August 09, 2012, 06:39:42 am
Sorry my English. I don't understand what concretely I did not do what supposed to do.
You ask me to show how I modified library code and what was error message.
So I did.
I can not understand what is wrong.  This is why I ask forum.

At the very beginning there was one more question:
There  is one  strange thing. Code dos not work if I remove   #include <DHT.h>  .  Why?
Pages: [1] 2