Show Posts
Pages: 1 [2] 3 4 ... 416
16  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: March 05, 2014, 09:42:43 am
I'm having trouble with rewriting my alarms. I'm switching on 12 lamps with separate timers ...


One thing you can try  is to replace the Alarm.write with a call to Alarm.free with the ID you want to change and then call Alarm.create with the new time.  Alarm.write sets the alarm time and activates the alarm but it does not update the scheduler.

Otherwise, there is a lot going on there and It’s difficult to see exactly what is happening with the alarms. Can you create a simple test sketch that just handles the alarm rescheduling and see if that works as expected.
17  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 16, 2014, 08:13:10 am
Note that I updated to posted code  to  so the minute tests for greater than or equal to the day start minute.
18  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 16, 2014, 07:48:43 am
here is another approach to determining if its day or night:

Code:
time_t startOfDay;
time_t startOfNight;

void setup()
{
  startOfDay = timeToSeconds(6,30,0); // Hour,Min,Secs for start of day
  startOfNight = timeToSeconds(18,30,0); // Hour,Min,Secs for start of Night
}

boolean isDaytimeNow()
{
    time_t t = timeToSeconds(hour(), minute(), second());
    return (t >= startOfDay && t < startOfNight);     
}

time_t timeToSeconds(time_t H, time_t M, time_t S)
{
 return (H * SECS_PER_HOUR) + (M * SECS_PER_MIN) + S;
}
19  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 16, 2014, 07:18:22 am
Good point!

try something like this:
Code:
boolean isDaytimeNow()
{
  // in this example, day starts at 6:30AM and ends at  6:30 PM
  int startDayHour = 6; // 6 am
  int startDayMinute = 30;
  int endDayHour = 18; // 6PM
  int endDayMinute = 30;

  int thisHour = hour();
  int thisMinute = minute();

  boolean result = false;

  // the following determines if the current hour and minute times are within
  // the day start and end times
  if( thisHour >= startDayHour) {
    if( thisHour == startDayHour){
      result = thisMinute >=  startDayMinute;
    }
    else{
      if( (thisHour < endDayHour) || (thisHour == endDayHour && thisMinute < endDayMinute) ){
        result = true;
      }
    }                
  }
  return result;
}

like my previous post, this is untested but hopefully will get you going in the right direction

Edit: changed  test for minutes from:
    thisMinute >  startDayMinute
 to
     thisMinute >=  startDayMinute;  // test for greater than or equal to
20  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 16, 2014, 04:38:39 am
Hello spyking,

If you want to know if the current time is day or night, you could do something like the following function. In this example, day starts at 6AM and ends at 6PM:
Code:
//returns true if it is day time now
boolean isDaytimeNow()
{
  // in this example, day starts at 6AM and ends at  6 PM
  int startDayHour = 6; // 6 am
  int endDayHour = 18; // 6PM
 
  int thisHour = hour();
 
  // the following determines if the current hour is within the day start and end times
  return thisHour >= startDayHour && thisHour < endDayHour; 
}
Calling that function will return true if its day and false if its night
Here is the code extended to support to start and end times of any hour and minute:
Code:
//returns true if it is day time now
boolean isDaytimeNow()
{
  // in this example, day starts at 6:30AM and ends at  6:30 PM
  int startDayHour = 6; // 6 am
  int startDayMinute = 30;
  int endDayHour = 18; // 6PM
  int endDayMinute = 30;
 
  int thisHour = hour();
  int thisMinute = minute();
 
  // the following determines if the current hour and minute times are within
  // the day start and end times
  return thisHour >= startDayHour &&
         thisMinute >= startDayMinute &&
         thisHour < endDayHour &&
         thisMinute < endDayMinute; 
}

I guess that what you are looking to do is to set the daytime flag at at startup and then toggle this off and on using the alarms, perhaps something like this:
Code:
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include <TimeAlarms.h>

boolean daytime;

// Alarm times
tmElements_t dtm,ntm;

void setup()
{
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  //Day
  dtm.Hour = 6;
  dtm.Minute = 30;
  dtm.Second = 0;

  // Night
  ntm.Hour = 18;
  ntm.Minute = 30;
  ntm.Second = 0;

  // Set up Alarms
  Alarm.alarmRepeat(dtm.Hour,dtm.Minute,dtm.Second, Day);
  Alarm.alarmRepeat(ntm.Hour,ntm.Minute,ntm.Second, Night);
}

void loop()
{
}

void Day()
{
  Serial.println("Day");
  daytime = true;
}

void Night()
{
  Serial.println("Night");
  daytime = false;
}

//returns true if it is day time now
boolean isDaytimeNow()

  int thisHour = hour();
  int thisMinute = minute();
 
  // the following determines if the current hour and minute times are within
  // the day start and end times
  return thisHour >=  dtm.Hour &&
         thisMinute >= dtm.Minute &&
         thisHour < ntm.Hour &&
         thisMinute < ntm.Minute; 
}
21  Using Arduino / Programming Questions / Re: Servo Timer2 Library Problems? on: January 28, 2014, 06:11:10 am
http://forum.arduino.cc/index.php/topic,21975.0.html
The original post you posted the library is where I got it. I had some errors and found a forum post the OP had the same errors and he posted the code containing the fixed errors and I haven't received an error(when compiling) since I used that code.


If the code you are using is from another post,  let me have a link to that code. I would like to have a look at the exact same code you are running.

22  Using Arduino / Programming Questions / Re: Servo Library error causing robot to imitate a dog chasing it's tail. on: January 22, 2014, 03:34:03 am
the degreesToUS function should be:
Code:
int degreesToUS(int degrees)
{
  return (map(degrees, 0,180, MIN_PULSE, MAX_PULSE));
}

although ServoTimer2 will not be as accurate as the Srvo library, I did a quick test using a logic analyzer and measured the output timing of ServoTimer2 to be within 1 % of the servo library. This will degrade if other interrupts are occurring frequently (as may be the case with VirtualWire), but I am surprised the test sketch posted does not work for you.

Can you post a link to the location where you downloaded the version of ServoTimer2 that you are using.


p.s. - the title of this tread may cause unnecessary concern for people using the Servo library, you may want to rephrase the problem statement as we don't yet know what is the cause of the behavior you are seeing, but its nothing to do with the Servo library and my not be due to an error in ServoTimer2.
Michael
23  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: October 29, 2013, 10:57:20 am
Hi ladinek,

I would be happy to add this feature to the library after it is well tested with the various chips compatible  with DS1307 that the library currently works with.
I suggest you create a new thread for your DS1307 enhancements when you are ready to post some code, and add a link to that thread here.

Michael Margolis
24  Using Arduino / Project Guidance / DS1302 RTC problems on: October 10, 2013, 04:59:38 am
so it seems that the ds1302 and ds1307 are both fault ridden , is there any other rtc that is reliable ?

I tested a bunch of DS1307 chips for many weeks back when the time library was created and never saw a fault.  If you haven’t already,  try one on well-made breakout board before ruling out this chip.

---
Mod – It looks like this RTC discussion is hardware related rather than anything directly to do with the time library. I think the posters issues would be apparent using any test harness for the RTC chips. If there is further discussion on RTC chips, it may be better to put this back in its own thread and add a link here to that, to keep this thread  focused on the Time library .
   
Michael Margolis
25  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 05, 2013, 02:42:06 am
Keith, don't beat yourself up. I can see why it seemed logical to include the TimeAlarm library within the Time folder. Unfortunately, Arduino does not currently handle library installation or inter-library dependencies very well, which  is why I chose to have TimeAlarms as a separate library. Perhaps when Arduino support a simple mechanism for installing libraries, problems such as yours will go away.

Michael
26  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 03, 2013, 05:13:09 pm
It looks like the libraries are not being found.
Make sure you have installed DS1307RTC in the Arduino libraries folder.

The Time.zip file is structured so you can copy the three folders (Time, TimeAlarms, and DS130RTC) into the Arduino Libraries folder.
27  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 01, 2013, 12:53:52 pm
Well, well. Look who's back. Been a while. Life treating you well, I hope.

Hi Paul, its good to be back.
I have been busy with all kinds of interesting projects. Still am, but will try to hang out here as much as possible.

Michael
28  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 01, 2013, 11:24:34 am
Keith, there is code for connecting to a DS1307 RTC provided with the Time library download, its called TimeRTC. Why not use that?

Michael
29  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: January 29, 2013, 05:29:52 pm
Alarms for the same time will be called in the order the were scheduled.

The scheduler calls the alarm handler in the Alarm.delay function so this should be called regularly in the sketch. There is a readme file in the download with some more details.
When there are more than one alarm ready to be triggered, the first scheduled alarm is serviced on the next call to Alarm.delay, the next scheduled alarm is serviced on the next call to Alarm.delay and so on.
The accuracy of the servicing depends on how often the Alarm.delay function is called.   

I have not used PulsePattern, but if time the code is in the interrupt handler is short, the timing accuracy should not be significantly affected. Why not give it a try. If you print the millis value in the alarm handler you should be able to see if that library is affecting the servicing of the alarms.

I hope that helps.

Have fun!
30  Development / Other Software Development / Re: Notepad++ User Defined Language for Arduino on: January 02, 2013, 11:52:55 am
I would be interested to know why the xml approach is not working as you want. The NPP user-defined language seems easier for users to install and more flexible  for those of use that want to switch between Arduino colouring and straight C++. Please do post a link if you start a new thread on this topic.
Pages: 1 [2] 3 4 ... 416