Show Posts
Pages: [1] 2 3 ... 150
1  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...

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:
colorWipe(::strip.Color(255, 255, 255), 50); // White
2  Using Arduino / Programming Questions / Re: Problems with strings and &chars on: September 18, 2014, 07:51:23 pm
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'.

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.
void gtcha (char &stra[]) //this does not work. The error "sketch_sep18b:5: error:
//declaration of 'stra' as array of references"

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:

void gtcha (char (&stra)[100]){

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

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

3  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:

If you only have one library which only uses the core, you may need to include HardwareSerial.h or just Arduino.h.
4  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:
T mean(T(*x)[N]){

But then you have to dereference it to access the array.
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.
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* ) )

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

Nice, didn't think of that either.

#define SECONDSINDAY 86400L
6  Using Arduino / Programming Questions / Re: Code error on: September 16, 2014, 02:00:10 am
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:

7  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.

8  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:
9  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.

Wrap it in a check:

#ifdef __AVR__
  #include <util/delay.h>

You may also have to define _delay_ms and _delay_us as the Due versions if they aren't named the same.
10  Using Arduino / Programming Questions / Re: question about 2 different water tank code! on: September 14, 2014, 06:33:45 am
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.
11  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 ).
12  Using Arduino / Programming Questions / Re: Messing about PROGMEM and F() on: September 13, 2014, 07:24:54 am
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.
13  Using Arduino / Programming Questions / Re: error: multiple definition of `func1()' on: September 12, 2014, 04:18:59 am
Place the include inside a namespace, and call that version.

Code: (sketch.ino)
namespace Foo{
  #include "test.cpp"

void setup() {
  Serial.begin( 9600 );

void loop() {}

Code: (test.cpp)
#include <Arduino.h>
void func(){ Serial.print( "HI" ); }

Or use ifdef guards to prevent showing the definitions when not included.
14  Using Arduino / Programming Questions / Re: Selective Random Pins..not 1-10, but only 1,4,7,9 anyone know how to limit that on: September 12, 2014, 02:57:53 am
I have updated my example to actually control the pins.

It shows how to do it without using delay().

#define PIN_ON_TIME  1000
#define PIN_OFF_TIME 1000

struct PinFlash{
  PinFlash( const char pin ) : start( millis() ), pin( pin ) { digitalWrite( pin, HIGH ); }
  ~PinFlash() {
    while( millis() - start < PIN_ON_TIME );
    digitalWrite( pin, LOW );
  const char pin;
  const unsigned long start;

void setup() {
  for( char i = 1 ; i < 20 ; ++i ){
    switch( i ){ case 5 ... 15: continue; }
    pinMode( i, OUTPUT );
  Serial.begin( 115200 );

void loop() {
  static unsigned long lastRun = 0;
  if( millis() - lastRun < PIN_OFF_TIME ) return;
  switch( char pin = random( 1, 20 ) ){
    case 1 ... 4:
    case 16 ... 19: {
        PinFlash p( pin );
        Serial.print( "Flashing LED: " );
        Serial.println( pin, 10 );
      lastRun = millis();
15  Using Arduino / Programming Questions / Re: Writing to the wrong elements of an array on: September 12, 2014, 02:21:32 am
If you stick a Serial.print(mtxRow); before each write to the array, you will see that mtxRow does increase to 8, but is reset to 0 before it is called again.

Not talking about that variable  smiley-wink

buffer[mtxRow][mtxWidth+ col] = 1;


const byte mtxWidth = 8;
Pages: [1] 2 3 ... 150