Show Posts
Pages: 1 2 [3] 4 5 ... 152
31  Using Arduino / Programming Questions / Re: Converting code to Arduino Sketch on: September 20, 2014, 02:48:35 am
If you change PC3 to PINC3 and PC4 to DDC4 to match the names in the datasheet, it compiles without further changes.

In 1.5.7, it compiles with no changes to the code. Are you saying the names are wrong (values), or not defined?

Maybe it was added to AVR in a later release ( 1.0.5/1.5.6 and below ).
32  Using Arduino / Programming Questions / Re: Converting code to Arduino Sketch on: September 20, 2014, 02:08:49 am
Just remove the three includes at the top.

If you want to use setup() and loop(), just add them, move the contents of int main into setup and then delete the int main function. However the internal init() function may mess with your setup.

You can see how int main is used by the Arduino code here:
http://arduino.land/FAQ/content/2/2/en/can-i-use-int-main-with-arduino.html
33  Development / Other Software Development / Re: Some new core functions on: September 20, 2014, 12:31:56 am
Quote
1)  tmp can (and with 16 bit ints, often will) overflow, leading to nonsense result.
There will always be some kind of overflow, even if you make the array an unsigned 64 bit type and set all the elements to the maximum 64 bit value (1.8446744e+19).
No, its a bug, you need to use a large enough type for the sum so it doesn't overflow,
so if the array elements are int16, the sum should be int32, etc etc.  I'm not sure
templates can do what's needed.

Its one of the many problems they can solve. The post I made on page 2 shows how it can be done with a slight mod http://forum.arduino.cc/index.php?topic=265085.msg1873064#msg1873064

Quote
3) Divide by zero if N = 0
When will this happen? Does myArray[0] even get compiled, regardless of type?

Its a special case that should be handled in a defined manner - perhaps add error
flag or define the function to return 0.  Typical lowly processors return 0xFFFF for
divide by zero without trapping, their bigger cousins trap to a handler.

You can declare a zero sized array ( only valid inside a class for objects of unknown length ), however you cannot pass a zero sized array to an array declaration... The function is already safe!

Quote
I just did it for consistency with the other functions.
Ah, yes, thought that might be the reason.

I explain this above, its required, otherwise all you have is a pointer.

Quote
This sort of feature creep is why standard C++ libraries end up being too bloated for use on microcontrollers...

Just like functional code, the compiler will not compile unused features of a class. The standard C++ libraries are heavily dependent on dynamic memory usage, however most STL classes can use a custom allocator allowing you to remove the dynamic overhead with a static or short lived local storage space.

Quote
Ok but what if someone (for whatever reason) wants to find the mean of values that are Absurdly big, like type long long . What do I do then, make tmp long double? Should I cut them off

Yes.

Quote
I suppose I can use a struct and automatically set tmp to the next type, so if the user enters int, the compiler will make tmp long or float.

Yup, good thinking, however this still can have trouble when the largest type is reached. Rather than allowing faulty code for the large type, you could use the EnableIf construct to disable the definition if a long long for example is used. Read up on SFINAE. This is available using the newer compiler on 1.5.7 ( not necessarily C++11, just newer than the 1.0.5 compiler ). There are also ways of doing this without SFINAE either.
34  Using Arduino / Programming Questions / Re: NOOB ALERT: Leveraging function argument for class instantiation? on: September 18, 2014, 08:03:36 pm
Your global variable 'strip' is hidden by the function parameter 'strip', the closest scope wins...

Code:
Adafruit_NeoPixel strip[2]

//...

void theCycle(int strip){

If you want to keep the variable name the same, you must access the global version explicitly:
Quote
colorWipe(::strip.Color(255, 255, 255), 50); // White
35  Using Arduino / Programming Questions / Re: Problems with strings and &chars on: September 18, 2014, 07:51:23 pm
Quote
string str3 = "trtty ";  //This gives always an error "sketch_sep18b:5:

As pointed out the type name is wrong. C/C++ is case sensitive and names must match exactly: 'String'.

Quote
I tried to pass a string or character array by value or reference, and I am getting errors where I think I should not get.
Code:
void gtcha (char &stra[]) //this does not work. The error "sketch_sep18b:5: error:
//declaration of 'stra' as array of references"
{
Serial.print(stra);   
}

You must use brackets to show the variable is a reference to an array, not an array of references. If you do, you must provide the length between the square brackets:

Code:
void gtcha (char (&stra)[100]){
  Serial.print(stra);   
}

If the function needs to be used by multiple ( and different sized ) arrays, you can use a template to fill in the size:
Code:
template< unsigned N >
  void gtcha (char (&stra)[ N ]){
    Serial.print(stra);   
}

And if you have arrays with different data types, the template can handle that too:
Code:
template< typename T, unsigned N >
  void gtcha ( T (&stra)[ N ]){
    Serial.print(stra);   
}


36  Using Arduino / Programming Questions / Re: Passing parameters in constructors. on: September 18, 2014, 06:46:14 am
Any libraries that your libraries use, must also be included. Check out the third bullet point: http://arduino.land/FAQ/content/1/3/en/what-does-the-ide-change-in-my-sketch.html

If you only have one library which only uses the core, you may need to include HardwareSerial.h or just Arduino.h.
37  Development / Other Software Development / Re: Some new core functions on: September 18, 2014, 05:27:21 am
and why is x is passed by reference, or is that a templates thing?

It is not a template feature, its required because an array cannot be passed by value, its the same as trying to assign one array to another.

You can also pass the array by pointer:
Code:
T mean(T(*x)[N]){

But then you have to dereference it to access the array.
Code:
tmp += (*x)[i];

If you use the array declaration without a reference or pointer, it is not actually an array at all, but a  pointer to the first element.
Code:
T mean(T x[N]){

You can see this in action as sizeof will work correctly with the reference or dereferenced pointer, however the prototype for x above will always return 2 ( sizeof( T* ) )

38  Using Arduino / Programming Questions / Re: I HATE C!!!! - DaysBetween on: September 17, 2014, 04:41:44 am
Code:
int remDays = dT/SECONDSINDAY;
Divide by 86400, or divide by 20864?

Nice, didn't think of that either.

Quote
#define SECONDSINDAY 86400L
39  Using Arduino / Programming Questions / Re: Code error on: September 16, 2014, 02:00:10 am
Quote
error : 'class button has no member named 'holdhander'

It is holdHandler in your code.

What library do you use, it doesn't seem like this one: http://playground.arduino.cc/Code/Button

40  Community / Bar Sport / Re: Strings or woodwinds? on: September 15, 2014, 10:24:38 pm
It seems people here are saying 'string' to emphasize the fact they aren't using the Arduino class 'String', however a character array ( with a null terminator ) in the C/C++ world is called a C-style string, and commonly known simply as a cstring.

41  Using Arduino / Programming Questions / Re: SDFAT return file creation date, time, ect...not print! on: September 15, 2014, 02:26:27 am
d.creationDate is most probably a timestamp of some sort.

The function x.printFatDate likely parses the timestamp into a readable format.

Open up the code and have a look.

EDIT: maybe this'll help: http://stackoverflow.com/a/15763512
42  Products / Arduino Due / Re: An error accurred when build the program with Arduino DUE R3! on: September 15, 2014, 01:58:57 am
the file is an AVR only file, and not part of the Arduino core so not portable.

http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

Wrap it in a check:

Code:
#ifdef __AVR__
  #include <util/delay.h>
#endif

You may also have to define _delay_ms and _delay_us as the Due versions if they aren't named the same.
43  Using Arduino / Programming Questions / Re: question about 2 different water tank code! on: September 14, 2014, 06:33:45 am
Quote
if i can add other code for the other tank like this

You can! However you still need to work out how to let the Arduino know which set of values to use. It needs some way of knowing if its looking at a half full 2 meter tank or an empty tank that is only 1 meter high.

...Or just modify and upload the program for whatever tank size you need.

If the tank is empty when you setup the device, you can have it calibrate to the distance of the first reading(s) then it can simply scale the values between empty and full to obtain percentages or volume.
44  Using Arduino / Programming Questions / Re: question about 2 different water tank code! on: September 14, 2014, 05:11:27 am
If you cannot change the code for each tank, then maybe you could add a 'calibrate' button to switch between 100 and 200 cm distances, an LED can be used as an indicator. Or even simpler, just a set of exposed pins you can bridge with a shunt/jumper for what ever mode you need. ( I gather that 1M is 1 meter high, not 1 Mega liter in capacity ).
45  Using Arduino / Programming Questions / Re: Messing about PROGMEM and F() on: September 13, 2014, 07:24:54 am
Quote
I don't have the lenght of the string when using F()

If speed isn't an issue, you could always use strlen_P to get the length.
Pages: 1 2 [3] 4 5 ... 152