Show Posts
Pages: 1 2 [3] 4 5 ... 68
31  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.
32  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
33  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
34  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
35  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
36  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.
37  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...
38  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
39  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)
40  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
41  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
42  Using Arduino / Programming Questions / Re: My EEPROM data kept resetting =( on: July 21, 2014, 10:33:31 pm
@ Guix,  Which pin on an Arduino is PIC?

smiley Sorry but that's the first picture that I found, showing difference between active low and active high.
43  Using Arduino / Programming Questions / Re: My EEPROM data kept resetting =( on: July 21, 2014, 10:25:15 pm
I may be wrong, but it appears to me that your button wiring is incorrect, it should be like this (in your case, active low):
44  Using Arduino / Programming Questions / Re: Looping LED patterns and using a button to break the loop on: July 21, 2014, 09:49:20 pm
Your arduino isn't multithreaded, so you must avoid blocking code (such as while() and delay()).
45  Using Arduino / Programming Questions / Re: Looping LED patterns and using a button to break the loop on: July 21, 2014, 09:36:09 pm
Hello,

Post your code. I suspect that you are using delays for your sequences. Right?
Pages: 1 2 [3] 4 5 ... 68