Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: Using CC3000 with millis - not working on: September 11, 2014, 07:03:17 pm
Also, after lastSampleTime is initialised, it is never updated.  I would expect that, each time 5 minutes is up, you would reset lastSampleTime to the current value of millis().

Strictly speaking that method will cause a slight drift to the timing which will accumulate over time. The "drift-free" method is to add your interval (fiveMinutes) to the value of lastSampleTime when your event is triggered (ie. inside the if clause).

2  Community / Exhibition / Gallery / Re: Ways to update the RTC DS3231 from NTP server on: December 19, 2013, 06:38:48 pm
where the time zone for my area is -6 since i am in central America.

And yet you forget your fairly close Venezuelan neighbours and fail to include non-integer timezones (UTC -4:30).

I often encounter this problem, as I live in Central Australia (UTC+9:30).

K5CZ's code has the same deficiency, his is probably easier to fix with:

after line 130 add a new line with:
#define TIME_ZONE_HALF 0  /*, 1 or -1*/
then modify line 559 to:
result = secsSince1900 - 2208988800UL + TIME_ZONE_INT * SECS_PER_HOUR + TIME_ZONE_HALF * SECS_PER_HOUR / 2;
3  Using Arduino / Programming Questions / Re: unsigned Long Bug? I think so. on: September 03, 2013, 12:01:35 am
You are using integer constants in hexadecimal form.

From "The C Programming Language" (K&R), second edition, Section A2.5.1, "Integer Constants":

... The type of an integer constant depends on its form, value and suffix...

... If it is unsuffixed octal or hexadecimal, it has the first possible of these types: int, unsigned int, long int, unsigned long int...

Note the use of "first possible", this means that without the "L" suffix to force it into a long type, it will be assigned to an int (16 bits on Arduino) if its value is within the range of ints (which it is in this case). Leading zeros are not the mechanism by which long integer constants are created, you need to explicitly suffix them.
4  Using Arduino / Programming Questions / Re: indexed or enumerated structure on: July 18, 2013, 06:36:42 pm
Not sure if I'm misinterpreting the problem, but have you considered overloading the subscript operator [] in the struct?

As a struct is just a class with default public methods and member variables, you get all these semantics for free.
5  Using Arduino / Programming Questions / Re: Using millis for time delay for (push ON/OFF button) on: June 06, 2013, 09:56:44 pm
yea crimony, but the millis button will overflow back to 0 after 50 days, that time the "timep-time" would go negative and the condition without abs "(timep-time) <= timedelay" would be satisfied for 50 more days smiley-razz

thats why i included the abs function, or is it not necessary or am i overlooking something?

Your code uses time in seconds, so you can't use the standard transparent technique for managing millis() rollover, which would be something like this (not tested, likely to contain some errors):

unsigned long timedelay;
unsigned long time;
unsigned long timep;
bool ac_on = false;

void loop()
  val = digitalRead(sensor);                                //pir sensor
  potval = analogRead(pot);                                //pot value for time delay
  timedelay = 1000 * map(potval, 0, 1023, 20, 600); // delay in milliseconds

  if(val == 1)                                                     // if pir sensor triggered
    digitalWrite(led, HIGH);
    if (!ac_on)                                              // only toggle the AC if it's not on yet.
      ac_on = true;
    time = millis();
  timep = millis();
  if( ac_on && timep - time > timedelay)                   // time delay exceeded
    digitalWrite(led, LOW);
    ac_on = false;

This code assumes the AC starts *OFF*. If it's not, then the logic will be reversed. You really should have a mechanism for detecting whether the AC is on or off, it would make your solution much more robust.
6  Using Arduino / Programming Questions / Re: Using millis for time delay for (push ON/OFF button) on: June 06, 2013, 08:52:06 pm
the ac remote has just a single command for ON and OFF

So *you* need to keep track of whether it is on or off, and only switch it if it's different to what you want it to be.

Also you shouldn't need the abs() calls as the type of your "timep" and "time" variables will be "unsigned long" already.
7  Using Arduino / Programming Questions / Re: exit() seems premature on: May 19, 2013, 06:54:41 pm
I wholeheartedly endorse this thread.

johnkauffman: <posts code that calls exit()>
PeterH: "Don't ever use exit(), the correct way to halt is to call an infinite loop"
econjack: "What does exit() do anyway?"
pYro_65, WizenedEE: "calls an infinite loop"

Comedy gold fellas.
8  Using Arduino / Programming Questions / Re: Pointer Problems on: May 15, 2013, 07:28:49 pm
You are declaring rootMenu, oneMenu and twoMenu in the setup() function, these are being allocated on the stack, and reclaimed when you exit setup. You're keeping the pointer to rootMenu as it is declared global, then when you call Serial.println() it is using the memory previously used by the variables rootMenu, oneMenu and twoMenu, and overwriting the data there.

Declare your variables rootMenu, oneMenu and twoMenu at the global scope.
9  Using Arduino / Programming Questions / Re: Udp.beginPacket() time delay problem on: January 07, 2013, 12:52:33 am
You haven't really clarified what you mean by the delay "when there's nothing on the other end". If the remote device is powered down then I suspect the problem is related to ARP.

Although at layer 3 (IP) you send to an IP address, at layer 2 (ethernet) your packet needs to have the MAC address of the destination in it in order to be sent. With your destination device on the local subnet, your source device will try to get the receiver's MAC address through ARP resolution. If it's not there, the ARP will fail and the packet won't be sent. The ARP request is likely to have a timeout associated with it that may be the cause of the delay.
10  Using Arduino / Programming Questions / Re: Maintain Hover At Given Height on: November 09, 2012, 06:24:32 pm
You need one of these:

Bit expensive though. Also may be too large for your application.
11  Using Arduino / Programming Questions / Re: splitting hexadecimal byte on: October 13, 2011, 06:10:42 pm
DataByte[0] = 0xB5

How do i separate the byte into two parts,

You do this:-

DataParts[0] = DataByte[0] >> 4
DataParts[1] = DataByte[0] & 0xf

Won't that do sign extension on DataParts[0] of the type of DataByte[] is char? (ie. result in DataParts[0] == 0xF5)
12  Using Arduino / Programming Questions / Re: Using a class instance as a class global. How? on: August 10, 2011, 11:16:31 pm
I expect undefined behaviour if the constructor for NewSoftSerial is called in the global variable initialization stage.

Where were you planning to put the declaration for Thermal then?

My expectations are unrealistic, as it turns out. Global scope is the right thing to do.

On closer inspection of the NewSoftSerial Library, it appears they must have ensured that they are immunized from the kind of initialisation issues covered here.

13  Using Arduino / Programming Questions / Re: Using a class instance as a class global. How? on: August 10, 2011, 07:44:15 pm

Yes, that gets rid of pointers, but I can't get it to compile:

My bad, I didn't test at all, and my C++ is very rusty.

The point was supposed to be that you need to use an initialization list if there is no default constructor for a member variable (in this case class NewSoftSerial).

That works, although I caution you that this is using a static constructor. Although it worked this time, static constructors can sometimes give weird results because of the order the constructors are called during program initialization.

I expect undefined behaviour if the constructor for NewSoftSerial is called in the global variable initialization stage.
14  Using Arduino / Programming Questions / Re: Using a class instance as a class global. How? on: August 10, 2011, 06:51:43 pm
Or use a reference member and an initialization list:

#ifndef Thermal_h
#define Thermal_h

#include <NewSoftSerial.h>
#include <WProgram.h>
#include <WConstants.h>

class Thermal{

    Thermal(int RX_Pin, int TX_Pin);

int _RX_Pin;
  int _TX_Pin;
NewSoftSerial& _printer;


#include <NewSoftSerial.h>

#include <WProgram.h>
#include <WConstants.h>
#include "Thermal.h"

Thermal::Thermal(int RX_Pin, int TX_Pin):
_printer(RX_Pin, TX_Pin), _RX_Pin(RX_Pin), _TX_Pin(TX_Pin) {}
15  Using Arduino / Programming Questions / Re: Need to call an uninstantiated method from object method on: August 09, 2011, 12:48:25 am
Page 5 of this has an example of the sort of thing you need to do (make a wrapper). You will need a static entry point, but that function can bounce to the handler specified for the individual object.
Pages: [1] 2 3 ... 7