Show Posts
Pages: [1] 2 3 ... 122
1  Using Arduino / Programming Questions / Re: Logical error in astar on: Today at 12:01:00 am
You may have to print a char as a number explicitly, otherwise it may try and print it as an ascii value.

This sketch should illustrate the problem:
void setup() {
  Serial.begin( 9600 );
  Serial.println( 'a' );
  Serial.println( 'a', DEC );

void loop() {}

Quote from: OUTPUT
2  Using Arduino / Programming Questions / Re: ARRAYS on: April 24, 2014, 09:54:09 pm
Dynamically declaring arrays like you are doing really isn't a good idea.

Why not? Unless persistent data is needed, its a perfectly valid way of allocating an array to the stack.


You loop variables are backwards and could possibly be writing out of bounds.

 const int x=createroomRight();
  const int y=createroomStraight();
  int array[x][y];

  for (int i = 0; i < y; i++) {
    int u = 0;
    for (int p = 0; p < x; p++) {
      array[i][p] = 0;


The array is declared [x][y], however you address it like [y][x]
3  Using Arduino / Programming Questions / Re: program execution is not as intended on: April 24, 2014, 07:47:32 am
if ( checksum == data_checksum )
             Serial.println(" OK");
             delay (10000);

The close() is being called here, when the CRC values match.
Why not remove the call to close if you do not want it to occur there.

If you think that the Arduino is firing off random functions, try again. loop() is called from a loop, so it will repeat, and repeat...
4  Using Arduino / Programming Questions / Re: converting char into integer on: April 23, 2014, 09:26:25 pm
A char cannot contain a floating point value.

You can use a float to do what you ( may ) want.
float f = 23.5f;
int i = f;

However the decimal portion is dropped and i = 23, not 23.50, or 23.00

Maybe you have a string ( of chars )?
int i = atoi( "23"  );
float f = atof( "23.50" );
5  Using Arduino / Displays / Re: Strange bug with myGLCD.drawBitmap when called 6 times on: April 23, 2014, 08:17:38 pm
As I understand, avr/pgmspace.h is a macro.
It contains macros, among other things. avr/pgmspace.h
Just create a library called farpgmspace and include it where you need it.
6  Using Arduino / Programming Questions / Re: A programming question on: April 23, 2014, 06:33:52 am
In a switch  statement you will only be able to compare single characters or integer/float numbers.
You cannot use a string as a case value unless you want to compare the strings pointer ( C++ subtleties ).

A different method must be used to compare two strings as each character must be compared individually using a loop or helper function like strcmp().

And no, do not use:
case "a":

case 'a':

Or drop the switch and compare "auto" in a loop. Or use a switch on the result of strcmp().
7  Using Arduino / Programming Questions / Re: Difference between sending '123' and "123" over Serial. on: April 22, 2014, 10:23:30 pm
Got it. Thanks guys - I wasn't aware of this difference. It makes sense now - for example doing Serial.print('123',DEC) gives 12851. Therefore with "123"  I am sending only 5 bytes (including "\r\n"), while '123' is in fact 7 bytes.

Sending the data should be relatively close in timing, as its only two more characters. The algorithm to convert the integer 12851 into a printable string "12851"  would be responsible for the bulk of the overhead.
8  Using Arduino / Programming Questions / Re: Serial buffer or faster processing? on: April 22, 2014, 09:47:38 am
Thanks for the info, It seems like an interesting project. I have a small library I've been working on which can possibly provide a solution. I'll have a crack and see what I can come up with.
9  Using Arduino / Programming Questions / Re: Serial buffer or faster processing? on: April 22, 2014, 08:32:01 am
This is true only after the last string.
I really wanted to know if ':' is the last character sent, seems it is.

I can see you have two commands that are not of equal length, however

Is the led command always 7 characters ( including ':' suffix ) ?
Is the 7 seg command always 9 characters ( including ':' suffix ) ?

Need specific details not just a hint. Or at least a link to documentation.
10  Using Arduino / Programming Questions / Re: Serial buffer or faster processing? on: April 22, 2014, 07:20:23 am
Please post more information on the codes being sent.

Why have ABCD when you use X to select a device?
Does the stream end in an ':' or does that character only separate values?
Are all the codes the same length?
11  Using Arduino / Programming Questions / Re: Difference between sending '123' and "123" over Serial. on: April 22, 2014, 01:26:34 am
Yes but the OP is saying it is the other way round as regards speed

It should increase, like I said, its an int. The print library does a conversion like itoa which is far more involved than printing 3 chars in a string "123"
12  Using Arduino / Programming Questions / Re: Difference between sending '123' and "123" over Serial. on: April 22, 2014, 12:45:23 am
Obviously from your title, you're not aware of the difference between single and double quotes and how the serial monitor interacts with them. Double quotes means it's a string and single quotes means it's a char. So "123" sends out individual chars, ('1' , '2' , '3'), and '123' sends out a single char, which is why it is much faster.

Almost there, '123' is a multi byte character constant. Also its an int.
On arduino the int is 2 bytes, so the longest multibyte char can be two characters wide. '123' is truncated from 32 bits to 16.

Consider a list of values ( on 8 bit AVR )

'a'         == 0x61
'aa'       == 0x6161
'aaa'     == 0x6161
'aaaa'   == 0x6161
'aaaaa' == 0x6161
13  Using Arduino / Programming Questions / Re: 1.0.5-r2 Verify Hangs With This Sketch Only on: April 21, 2014, 08:09:18 am
You need to fix up the first comment and add a comment a few lines down.

//* Example Software Sketch
   DHT11 Humidity and Temperature Sensor test
   Credits: Rob Tillaart */
//   Added 1.8" tft color display code
/*-----( Import needed libraries )-----*/

I then get 'error: 'Adafruit_ST7735' does not name a type' because I do not have the libraries.
14  Using Arduino / Programming Questions / Re: if else or switch case? on: April 21, 2014, 06:47:03 am
I got inspired by the way this is progressing and have started a library to filter input and detect strings in the stream.

Below is a sketch with my attempt at understanding your problem, using my library.

This string: asdrEdasdGr%eEn_345(903458 c_7rA4YYY 890fdg8 df9 g0m blUe 90a":{}sd8u 90a-p5U5r8p6l3eRaNdOm

Produces this result:
Got COLOUR change: red
Got COLOUR change: green
Got MODE change: cray
Got COLOUR change: blue
Got COLOUR change: purple
Got MODE change: random

There are many options that can be implemented, so see what you think.

The sketch is below and the library is linked at the bottom.
#include <FilteredInput.h>

char colRed[] PROGMEM = "red";
char colGreen[] PROGMEM = "green";
char colBlue[] PROGMEM = "blue";
char colPurple[] PROGMEM = "purple";
char colPink[] PROGMEM = "pink";
char colOrange[] PROGMEM = "orange";
char modCray[] PROGMEM = "cray";
char modProgram[] PROGMEM = "program";
char modRandom[] PROGMEM = "random";
char *cCodes[] PROGMEM = { colRed, colGreen, colBlue, colPurple, colPink, colOrange, modCray, modProgram, modRandom, 0x00 };

FilterStream< 7 > filter( Serial, cCodes, run );

void run( char idx ){
   switch( idx ){
     case 0:  case 1: case 2:
     case 3:  case 4: case 5:
       Serial.print(  F("Got COLOUR change: ") );
     case 6: case 7: case 8:
       Serial.print(  F("Got MODE change: ") );
  Serial.println( ( __FlashStringHelper* ) pgm_read_word( &cCodes[ idx ] ) );

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

void loop() {
  static unsigned long time = millis();

  if( )
    time = millis();
  else if( millis() > ( time + 100 ) )

The library is located on github

If people are interested, I'll add some more features and write up some instructions.
15  Using Arduino / Programming Questions / Re: Is there a null Stream object for arduino to print to? on: April 21, 2014, 01:18:00 am
Here is a null stream object.

struct NullStream : public Stream{
  NullStream( void ) { return; }
  int available( void ) { return 0; }
  void flush( void ) { return; }
  int peek( void ) { return -1; }
  int read( void ){ return -1 };
  size_t write( uint8_t u_Data ){ return u_Data, 0x01; }

You can overload 'size_t write(const uint8_t *buffer, size_t size)' for a speed increase too.
Pages: [1] 2 3 ... 122