Show Posts
Pages: [1] 2 3 ... 142
1  Community / Website and Forum / Re: How do I Start a Poll? on: July 22, 2014, 01:54:56 am
I remember polls being disabled. Is this a permission only moderators have?

I had a look and I cant see any poll button.
2  Community / Website and Forum / Re: Code is not getting burn in Arduino Uno on: July 22, 2014, 01:52:10 am
Its been a common question, search the forum for the string "Avrdude: skt500_getsync(): not in sync" and you'll probably find a few things.

To start off with, do you have anything plugged into pins 0 and 1, if so disconnect those or use different pins. If you need a second serial interface, you can search for examples using the SoftwareSerial over different pins.
3  Using Arduino / Programming Questions / Re: stopping a sketch once completed on: July 21, 2014, 07:43:04 am
There are a few different methods for stopping a sketch explained here: http://arduino.land/FAQ/content/7/47/en/how-to-stop-an-arduino-sketch.html
4  Using Arduino / Programming Questions / Re: #define, int or const int on: July 20, 2014, 10:52:46 pm
I guess nobody else uses enumerators? How odd. I just luvemup!

I do, was just doing a post:

GoForSmoke is correct, an enum is a great way to define constants, which are still symbols, not copy 'n' paste jobs.
C++11 will allow enums to become one of the better choices, as the enum values are no longer in the global scope, which can allow more creative control.

Whats more is they can have their size controlled, there is no behind the scenes conversions of integer literals. ( notice the : uint8_t )

Currently an enum  can take the form:
Code:
enum SystemPins{
  buttonPin = 2,
  lcdPin0,
  lcdPin1,
  lcdPin2,
  lcdPin3,
  ledWarningPin,
};

You could separate the like pins into different enums, however the point is they are all global names.

When the IDE 1.5.8 is released we can do this:
Code:

enum{ ledWarningPin = 2 }; //Normal enum

enum class HID : uint8_t { //Strongly typed enum
  button0 = 3,
  button1 = 4
};  

enum class LCD : uint8_t {
  data0 = 5,
  data1 = 6,
  data2 = 7,
  data3 = 8,    
}
5  Products / Arduino Yún / Re: IDE 1.5.7 missing SPI library on: July 20, 2014, 10:20:57 pm
Time to post your sketch.
6  Using Arduino / Programming Questions / Re: #define, int or const int on: July 20, 2014, 10:03:22 pm
@Pyro,

I learned it is possible  (prefer the C++11 over the C++98)

the constant   5.0/1024   versus   5/1024   can be incorporated same way I guess

The C++98 version can be incorporated into a typedef:

Code:
typedef Select< USE_FLOAT, float, int >::Result analog_t;

analog_t x = analogRead(A0)* 5/1024;

void foo( analog_t &in ){
  return;
}

You could then use the typedef to sort out the constants you mentioned:
Code:
analog_t result = analog_t( 5.0f ) / analog_t( 1024.0f );

//Or for the example above:
analog_t x = analogRead(A0)* analog_t( 5.0f ) / analog_t( 1024.0f );

This has the advantage of removing all floating point arithmetic when analog_t is int.

In C++11 you can also create the typedef using decltype. ( in C++98 mode GCC allows an extension named typeof, which is equivalent to C++11's decltype )
7  Using Arduino / Programming Questions / Re: A C vs C++ trivia question about integer constants on: July 20, 2014, 09:30:45 pm
In the case of the shift operators, I don't think it matters whether the number of bits being shifted is specified as long or 16-bit int - what matters is the type of the number being shifted.

Pete

Yup, you're onto it.

<< & >> are evaluated left to right, so integral promotion rules won't promote a smaller left hand side to a larger right hand value. Primarily because the left hand side denotes the size of the result.

Here is something from the standard:
Quote
5.8 Shift operators [expr.shift]
1 The shift operators << and >> group left-to-right.
shift-expression:
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
The operands shall be of integral or unscoped enumeration type and integral promotions are performed.
The type of the result is that of the promoted left operand. The behavior is undefined if the right operand
is
negative, or greater than or equal to the length in bits of the promoted left operand.
2 The value of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are zero-filled. If E1 has an unsigned
type, the value of the result is E1 × 2
E2, reduced modulo one more than the maximum value representable
in the result type. Otherwise, if E1 has a signed type and non-negative value, and E1 × 2
E2 is representable
in the result type, then that is the resulting value; otherwise, the behavior is undefined.
3 The value of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed
type and a non-negative value, the value of the result is the integral part of the quotient

The promoted left operand refers to a left hand value that would be promoted if it was smaller than int, like a char.
8  Using Arduino / Programming Questions / Re: error: expected unqualified-id before '.' token on: July 20, 2014, 09:19:03 pm
No, I just like to leave it in.

extern only needs to be located where it can be seen by multiple source files. However seeing it in someone else's code instantly tells me that changing the variable declaration in the file scope (.cpp) will break something elsewhere, or simply not compile.
9  Using Arduino / Programming Questions / Re: error: expected unqualified-id before '.' token on: July 20, 2014, 09:00:56 pm
include the file "avr/pgmspace.h" into your code.

Also, only the array definition needs PROGMEM, the declaration does not. As you already specify PROGMEM, prog_xxx isn't needed either. Just use unsigned char or uint8_t.

Also, to keep your code usable with the IDE 1.5.7 and above, add const.
Code:
//Header
extern const unsigned char bitmaps[];

//cpp file
extern const unsigned char bitmaps[] PROGMEM = { /** values **/ };
10  Products / Arduino Yún / Re: IDE 1.5.7 missing SPI library on: July 19, 2014, 08:15:05 pm
Each core has its own version, its not in the root libraries folder.

arduino-1.5.7\hardware\arduino\avr\libraries\SPI
arduino-1.5.7\hardware\arduino\sam\libraries\SPI
11  Using Arduino / Programming Questions / Re: Use Pointer or Reference to Serial or SoftwareSerial in Library on: July 19, 2014, 07:45:31 pm
Prefix the function with the class name like you have on the other functions.

Also instead of using a pointer/reference to the HardwareSerial object, You can use the Stream object. Or if you only send data, the Print object ( Serial inherits both. )

An example of inheriting print: http://forum.arduino.cc/index.php?topic=200975.msg1481633#msg1481633
In the above example, Print can be replaced with Stream.


12  Using Arduino / Programming Questions / Re: #define, int or const int on: July 19, 2014, 07:30:39 pm
there is an important function of  #define  not mentioned yet

#define   can be used for conditional compilation e.g.

you can't use a const <type> for this smiley-wink

Maybe not your second example. But the first one is easy:

Using C++11:
Code:
const bool USE_FLOAT = true;

decltype( USE_FLOAT ? float() : int() ) x = analogRead(A0)* 5/1024;

Using C++98
Code:
const bool USE_FLOAT = true;

template< bool V, typename _T, typename _F > struct Select{ typedef _F Result; };
template< typename _T, typename _F > struct Select< true, _T, _F >{ typedef _T Result; };

Select< USE_FLOAT, float, int >::Result x = analogRead(A0)* 5/1024;
13  Using Arduino / Programming Questions / Re: #define, int or const int on: July 19, 2014, 07:41:18 am
And a quick check of an old draft says:

Quote
16.3 Macro replacement [cpp.replace]
1 Two replacement lists are identical if and only if the preprocessing tokens in both have the same number,
ordering, spelling, and white-space separation, where all white-space separations are considered identical.
...
14  Using Arduino / Programming Questions / Re: #define, int or const int on: July 19, 2014, 07:31:58 am
I tried it using 1.5.6 which uses the C++98 standard:

Quote
sketch_jul19a.ino:9: error: invalid suffix "_DEF" on integer constant


And in 1.5.7 with C++11 enabled:
Quote
sketch_jul19b.ino: In function 'void setup()':
sketch_jul19b.ino:9:28: error: unable to find numeric literal operator 'operator"" _DEF'

What setup did you use to get a valid output? I've never heard of the overlapping errors you describe.
15  Using Arduino / Programming Questions / Re: string overwriting on: July 18, 2014, 05:49:30 pm
I had to edit my post above, a slight error:

I added a cast to char on Serial.read(), as it returns an int. What would happen is the received char 'a' would be added to the String as the integer "97". The cast makes the String library add it as a single character.

This and the many allocations are reasons to use a DIY method. Where as  arr[i] = Serial.read(); would work without a cast.

Pages: [1] 2 3 ... 142