Show Posts
Pages: 1 ... 71 72 [73] 74 75 ... 100
1081  Using Arduino / Programming Questions / Re: if ( var) ? on: October 19, 2011, 11:36:10 pm
Yes thats what I finally came to, the confusion was that I was reading the comment as being just related to its line, (  if ( key ) ),not the previous functions of the keypad library.
Often the comment precedes the code it refers to.

Thanks guys, I can go back to bed now !
1082  Using Arduino / Programming Questions / Re: if ( var) ? on: October 19, 2011, 10:37:53 pm
Hmm the brains a bit wooly at 5am,  perhaps I will ask the wife when she gets up, her mind works like this  :-)

 if NO_KEY were to be the previous value of key, I could understand the idea of " did something change? "  but it is not declared or used in the example.

It looks to me as though this is simply going to be true for any keypress ( other than 0 )  even if it is the same value, so where is the " did something change? "

Unless the keypad.h does not allow a subsequent value to be the same?
 Which could explain it, the comment would be more about the operation of the library, rather than about the if(key) which is what I was trying to understand ?
1083  Using Arduino / Programming Questions / Re: if ( var) ? on: October 19, 2011, 10:07:52 pm
its the " did something change? "  comment that has me confused...

If my key is always =  1,  then the if statement will be true, even though nothing has changed, but if it changes to 0, then it will be false, even though something changed ??

1084  Using Arduino / Programming Questions / if ( var) ? on: October 19, 2011, 09:47:53 pm
I am a bit confused with this part of the keypad code, and its' comment 

 if(key)    // same as if(key != NO_KEY)- did something change?


I tried checking it in the reference section for the if statement, and it is not mentioned, but it does say , while warning about using a single = ,  that

" This is because C evaluates the statement if (x=10) as follows: 10 is assigned to x (remember that the single equal sign is the assignment operator), so x now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to TRUE, since any non-zero number evaluates to TRUE. "

Which seems to mean that  if(key) is any value other than zero, it will be TRUE, whether it has changed or not ?

1085  Using Arduino / Project Guidance / Re: too many RTC libraries? Sorted . on: October 10, 2011, 08:19:48 pm
( Just posting this in case somebody gets to this thread from a search and wants to see the outcome )

Finally its all working great, I went back to breaking the long unidays ( unix/86400 ) into higher and lower bytes to store in the RTC  eprom,  joining them again to make the previous events " unix days"

The elapsed days are simply a subtraction of the old and new days,

I convert that back to seconds to extract the DDMMYY to display as the previous event day with:-

prevunisecs = prevunidays * 86400;
    time_t t = prevunisecs;
     dayint = day(t);
    monthint = month (t);
    yearint = year (t);

The beauty now this way is that I have an up and down button on the remote, that increments ( or decrements ) the prevunidays ( and stores it each push ) and the user sees the elapsed days and the displayed date changing in unison with automatic month adjustments on the date, and when the elapsed days reaches 99 it freezes, but the date continues decreasing.

Just when you think you are getting on well with learning this new stuff, something as simple as this project, ( and the time I have spent on it,)  reminds you that you know so little !
But I am enjoying the learning...
1086  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 10, 2011, 03:09:34 pm
After 3 days of confused attempts, I did at one time manage to get the conversion from unix to yymmdd working, though I have lost my sketch when the pc crashed again  smiley-mad    but I think I can get that going again.


The other half is still eluding me,  just converting yymmgg to unix.    I just want to create an unsigned long that I can use for calculations.

The elapsed time is not needed, I can do this with the unix time, but I need to be able to use the results of both conversions independantly.

  I have read all the libraries,  but I usually end up with   "tm not declared " , or many other errors,  I do not understand" &tm" , or find any basic explanations of use of the time elements.

1087  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 10, 2011, 01:43:23 am
I understand the seconds, etc, it was just the syntax of  " tmElements_t &tm1, tmElements_t &tm2  " that confused me a bit, I am sure I can manage it now.
Thanks for the help, sometimes reading through libraries like Time have too many unknowns for learners to see what is happening.
1088  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 09, 2011, 02:41:10 pm
I saw the help you gave re the same question a ferw weeks back i.e.

unsigned long timeDiff( tmElements_t &tm1, tmElements_t &tm2)
{
  return makeTime(tm2) - makeTime(tm1);
}

But it doesnt mean anything to a newbie like me :-)    for today would tmElements_t &tm1  be for example,  09,10,11&tm1   ?

1089  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 09, 2011, 01:53:40 pm
Thanks I will try that, have been all afternoon trying to get the internet access going again !

I still need to store the previous date in eprom, but I will try the upper lower bytes again, unix converted to days so it will only be 2 bytes.

It would still be easier if I could just store the dd mm yy ( which I need for the display anyway )  and find how to convert that to unix time so I could do a straight subtraction for the days elapsed.

Any change of the old dd mm yy with the remote, would automatically display the days elapsed  ...

1090  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 09, 2011, 06:23:09 am
Thanks Rob, yes  I was using unix on the abandoned sketch, divided by 86400 to work in days, but its still a an unsigned long, and I had problems simply storing these numbers in the ram of the 1307.  I was splitting into upper and lower bytes.

The new idea I want to try ( presetting the date and letting the micro work out the elapsed days ) would suit me much better.

I have looked at the adafruit librabry ( amongst many many others ) and it seems I want a backward version of

DateTime now = RTC.now();        where I can get DateTime then and give a unix value,  and back again.

I have no problem storing the individual bytes of DDMMYY and the 0-99 value for previous best.

1091  Using Arduino / Project Guidance / too many RTC libraries? on: October 09, 2011, 05:17:51 am
I am back on my simple date logging project, completely confused, I have looked at many libraries like Yet-Another DS1337 RTC library, and many of them look like I could do the simple task I require, but one uses unix , another based on year 2000, and I can't quite get it working.
I have rethought the basic idea, after failing to get the upper and lower bytes of unix days stored and read back from the 1307 RTC ram.
The new idea would work out much better than what I was trying, so I have scrapped the old sketch.
I have three LED displays,
# 1 shows the number of days since the last event ( 2 digits  0-99)
 #2  shows the previous best ( longest) number of days since the last event ( 2 digits 0-99 )
#3  shows the day, month, and year of the last event   2-2-2 digits.
The data for each is stored in the DS1307 ram in case power goes off
 I have a loop checking the date every minute, and if the day has changed, it recalculates the elapsed days,  and refreshes the ram.
I have buttons on a remote to set the displayed previous days month and year ( as well as to set the previous best display, and one to register an event  )
If an event is registered, I calculate the larger of the "elapsed" and "previous best" days which becomes " previous best",  "elapsed" is set to zero,  and the current date becomes the previous date displayed.

What I want to try, is have the "elapsed days display" calculated on the fly  ( in each loop )  from the difference between the current date and the previous date, with each press of the set date buttons - i.e. each loop.

I will need to store the previous date in the ram, ( which is where I had all the trouble using unix divided into days as a longint  split into highByte and Low byte )  so if I can just store it as 3 integers :-  "prevday"  "prevmonth"  "prevyear"

I  need to be able to subtract current "day"  "month"  "year"  from the RTC readDate ( or whichever library I use ) from the  "prevday"  "prevmonth"  "prevyear" .

Can anyone point me to a library ( or simple  instructions in Time.h ) or an example ,whereby I can convert any given YYMMDD to unix (or eclipse? or whatever) and back again after doing the subtraction?
1092  Using Arduino / Programming Questions / Re: How does the Time library adjust when millis() rolls over? on: October 08, 2011, 11:11:55 pm
Nick,  will that also work for the Y2038 problem ?   ( which I only read about yesterday - it will only effect my projects if I get to be 90 :-) )
1093  Using Arduino / Project Guidance / Re: serial to eeprom - too much information :-) on: October 02, 2011, 03:56:20 am
OK,  thanks for the tip Lefty

heres the results of reading the chip full of data, a byte at a time:-

E24C1024 Library Benchmark Sketch

--------------------------------
Write By Byte Test:

Writing data:...........................DONE
Total Time (seconds): 722
Write operations per second: 181
--------------------------------
Read By Byte Test:
Reading data:...........................DONE

Total Test Time (secs): 83
Read operations per second: 1579
Total errors: 0
--------------------------------

I have got all day for the writing, but not seconds for reading !

Back to the drawing board !   The SD card setup that had been giving me trouble seems OK now, so I think I will persevere with that !
1094  Using Arduino / Project Guidance / Re: serial to eeprom - too much information :-) on: October 02, 2011, 02:49:13 am
Thanks Lefty
I tried writing a basic sketch, reading byte by byte.
As I can't have the serial monitor to check the progress, I was going to try flashing the led while data is coming in.
I have the last address writing to the micros eeprom so that I can see where to start the next track...
I can move the start address to 44 or more to leave room for the size??

But as you say, I probably cant read fast enough to feed the DAC,  I will run a read test again and see how long it takes

Heres the crude sketch I was working on :-

Code:
  #include <WProgram.h>
  #include <Wire.h>
  #include <E24C1024.h>
  #include <EEPROM.h>
 
  int inByte = 0;         // incoming serial byte
  const int ledPin =  13;      // the number of the LED pin
  int ledState = LOW;             // ledState used to set the LED
  unsigned long time;
  unsigned long finishTime;
  unsigned long errors = 0;
  unsigned long address = 0;
  byte upperbyte;   //  address is long needs to be saved in eeprom
  byte lowerbyte;   //  -"-
 
  #define MIN_ADDRESS 0  //  change to start address of each track
  #define MAX_ADDRESS 131072 // 1 device
  void setup()
  {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  Serial.println();
  Serial.println("E24C1024 first try");
  Serial.println();
  address = MIN_ADDRESS;
}
void loop()
{
  time = millis();
  errors = 0;
  if (Serial.available() > 0) {
    // get incoming byte:
  inByte = Serial.read();

  EEPROM1024.write(address, inByte);
  address ++;
  if (!(address % 50))
  {   // toggle led ?
      if (ledState == LOW){
      ledState = HIGH;
  }
  else {
        ledState = LOW;
        digitalWrite(ledPin, ledState);
      }
    }  //  end of toggle led
    if (Serial.available() <= 0) {  //  no more data coming in
      int upperbyte = highByte(address);  // to save last address                         
      int lowerbyte = lowByte(address);
      EEPROM.write(0, upperbyte) ;
      EEPROM.write(1, lowerbyte) ;
      //   finishTime = millis() - time;
    } //  end of if no more data coming in   
  } //  end of if serial available
}
1095  Using Arduino / Project Guidance / Re: serial to eeprom - too much information :-) on: October 01, 2011, 11:55:14 pm
But will I be able to read all those x bytes starting  from address y, and feed them straight to the DAC ?
Pages: 1 ... 71 72 [73] 74 75 ... 100