Show Posts
Pages: 1 2 [3] 4 5 ... 68
31  Using Arduino / Programming Questions / Re: Unicode characters in Arduino on: July 27, 2014, 10:23:12 pm
Open C:\Users\<your user>\AppData\Roaming\ArduinoXX\preferences.txt (where XX is your Arduino IDE version).

Change preproc.substitute_unicode from true to false.

This solved a problem for me with the Arduino not being able to correctly read characters such as é à etc from the Serial monitor.. maybe it will work for you too smiley-wink
32  Using Arduino / Programming Questions / Re: Question about grammar for the boolean function on: July 27, 2014, 10:15:04 pm
Hello and welcome smiley

fabs( f ) return the absolute value of float f: it will always return the positive value of the float. For example with f = 0.1 it will return 0.1, and with f = -0.1 it will also return 0.1.

Using this function remove the need to manually do 2 comparisons.

So instead of writing:
Code:
if ( ( f < 0 && f >= -DELTA ) || ( f > 0 && f <= DELTA ) )

You can just write:
Code:
if ( fabs( f ) <= DELTA )

And max( a, b ) will return either a or b, depending which one is greater.

33  Using Arduino / Programming Questions / Re: LED Binary Converter on: July 26, 2014, 12:24:36 am
Yes, and then he want to split each '0' and '1' of this binary string, to set the state of his LEDs:

"100" -> 100 -> "1100100" -> '1','1','0','0','1','0','0' -> 1,1,0,0,1,0,0


My code produce the same result,  but with much less work:

"100" -> 100 -> 1,1,0,0,1,0,0
34  Using Arduino / Programming Questions / Re: LED Binary Converter on: July 25, 2014, 11:52:28 pm
Why do you complicate so much... Is there a reason you want to convert from string to int, then from int to string, to then split this string into bits?

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

  char numStr[] = "100";
  uint8_t num = atoi( numStr );
 
  for ( int8_t i = 7; i >= 0; i-- )
  {
    Serial.println( (bool)(num & (1 << i)) );
  }
}
35  Using Arduino / Programming Questions / Re: LED Binary Converter on: July 25, 2014, 11:33:48 pm
luisilva, itoa with base 2 will do the same thing.
36  Using Arduino / Programming Questions / Re: Set bits in a variable as output ports for serial connections on: July 25, 2014, 11:27:26 pm
Here is a nice post about what you want to do: http://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c-c
37  Using Arduino / Programming Questions / Re: LED Binary Converter on: July 25, 2014, 11:21:03 pm
Can you wire all LEDs onto the same port? So that you could simplify a lot by just setting the port value to the received number...

http://www.arduino.cc/en/Reference/PortManipulation
38  Using Arduino / Programming Questions / Re: LED Binary Converter on: July 25, 2014, 10:59:47 pm
From what I understand you enter a string such as "11001101" and you want to break it into 8 bits, one bit for each LEDs. Here is how I would do it: http://codepad.org/xaiL6pyf
39  Using Arduino / Programming Questions / Re: Looping LED patterns and using a button to break the loop on: July 22, 2014, 08:07:12 pm
You have been asked to post some code, and you have been told that your question is too vague... You didn't post code or explained what you want to do, so no one can help you... smiley
40  Using Arduino / Programming Questions / Re: Help to simplify code - CapacitiveSensor on: July 22, 2014, 09:26:32 am
But don't forget he is obviously a beginner, also, using malloc in loop() is really a bad idea.
41  Using Arduino / Programming Questions / Re: Help to simplify code - CapacitiveSensor on: July 22, 2014, 09:05:44 am
Why so complex? smiley-eek

Code:
#include <CapacitiveSensor.h>

const uint8_t NUM_SENSORS = 3;

CapacitiveSensor cs[NUM_SENSORS] =
{
  CapacitiveSensor(2,3),
  CapacitiveSensor(2,4),
  CapacitiveSensor(2,5)
};

int TSW[NUM_SENSORS];
long SW[NUM_SENSORS];

void setup()                    
{
   cs[0].set_CS_AutocaL_Millis(0xFFFFFFFF);    
   Serial.begin(9600);
}

void loop()                    
{
  for ( uint8_t i = 0; i < NUM_SENSORS; i++ )
  {
    SW[i] =  cs[i].capacitiveSensor(30);

    if (SW[i] > 500)
    {
      TSW[i] ++;
      //Serial.println(TSW[i]);
      if (TSW[i] == 5)
      {
        Serial.print("SW ");
        Serial.print( i );
        Serial.println( " on");
      }
    }
    else TSW[i] = 0;
  }
}

Next step would be to use a struct...
42  Using Arduino / Programming Questions / Re: Help to simplify code - CapacitiveSensor on: July 22, 2014, 08:29:19 am
Hello,

A for loop is what you need smiley
43  Using Arduino / Programming Questions / Re: How can I send and recive multiple values over serial? on: July 22, 2014, 08:10:37 am
Hello and welcome,

Here is an example how I would do it:
Code:
void loop()
{
  if ( Serial.available() > 0 )
  {
    static char input[64];
    static uint8_t i;
    char c = Serial.read();

    if ( c != '\r' && i < 64-1)
      input[i++] = c;

    else
    {
      input[i] = '\0';
      i = 0;
      
      char c;
      uint8_t v;
      
      if ( sscanf(input, "%c%hhu", &c, &v) == 2 )
      {
        switch( tolower(c) )
        {
          case 'r':
          {
            Serial.print("Setting PWM on Red to: ");
            Serial.println( v );
            analogWrite( ledR, v );
            break;
          }
          case 'g':
          {
            Serial.print("Setting PWM on Green to: ");
            Serial.println( v );
            analogWrite( ledG, v );
            break;
          }
          case 'b':
          {
            Serial.print("Setting PWM on Blue to: ");
            Serial.println( v );
            analogWrite( ledB, v );
            break;
          }
        }
      }
    }
  }
}

If you want a more robust code, read this: http://www.gammon.com.au/serial (especially, the reply #1)
44  Using Arduino / Programming Questions / Re: Millis()? on: July 21, 2014, 11:05:20 pm
Also, be careful with wrap around.

If "lastTime" is an unsigned long, that will not be a problem at all smiley-wink

http://playground.arduino.cc/Code/TimingRollover
45  Community / Exhibition / Gallery / Re: Programming DS3231 Alarms and Interupts on: July 21, 2014, 10:49:34 pm
Thank you, I have a DS3231 too, while I don't need alarms or interrupts yet, it might be helpful in the future smiley-wink

Since you didn't include the library that you used in those sketches, here is a link to it (I suppose it's this one, right?): http://forum.arduino.cc/index.php/topic,57642.0.html
Pages: 1 2 [3] 4 5 ... 68