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

You say you have the problem since you added the RTC... And then you say if you remove the code for the button, it works... So I'm a bit confused.

If the problem is your button code: How is your button wired? Are you sure you wired it so it reads LOW when pressed ?

Also, still about that button, you should debounce it properly: http://arduino.cc/en/Tutorial/Debounce

Or, as you are using many big delays, you should look into using interrupts to catch every button presses, because actually your code won't catch button presses while the code is delayed... Or yet better, get rid of those delays and use non blocking code instead smiley
44  Using Arduino / General Electronics / Re: eeprom- help on: July 21, 2014, 07:41:10 pm
No idea, I think that with an 16Mhz Arduino, speeds would be very similar, but I can be wrong.  smiley-kitty
45  Using Arduino / General Electronics / Re: eeprom- help on: July 21, 2014, 04:10:43 pm
If you are talking about Chip Select, then yes, in the datasheet they call it CE (Chip Enable).

And this isn't an EEPROM, this is Flash memory. Main difference is: with the EEPROM you can erase one byte, but with the Flash, you can't erase just one byte, you have to erase a whole sector (in the case of this chip, the smallest sector size is 4KB).

If you absolutely want an EEPROM, I doubt you will find one with a size greater than 1MB (but I can be wrong).
Pages: 1 2 [3] 4 5 ... 68