Show Posts
Pages: 1 ... 4 5 [6] 7 8 ... 55
76  Using Arduino / Programming Questions / Re: How to pass function / variable name? on: August 13, 2014, 09:02:29 am
Some people have problems with complex data definitions. For example, what is:

Code:
double (*(*pf)())[3][4];

You can unravel complex data definitions using the Right-Left Rule, which is detailed in The C Programming Guide or also summarized  here:

http://jdurrett.ba.ttu.edu/3345/handouts/RL-rule.html

77  Using Arduino / Programming Questions / Re: i'm trying to combine the readwrite code with the random() code NEED HELP ASAP!! on: August 12, 2014, 10:34:09 pm
First, welcome to the Forum.

As a newcomer, you should read the first two posts to this Forum, as they lay out the guidelines to be followed when posting to the Forum. The fact that you posted your entire sketch is a step in the right direction, but please use code tags from now on (i.e., the '#' button when you are posting). Also, tell us exactly what it not going correctly and what errors or error messages you are seeing.
78  Using Arduino / Programming Questions / Re: Math imprecision on: August 12, 2014, 03:00:52 pm
Or, try something like this:

Code:
#define UlongFromBinaryString(str)      PowerOfTwoFromString(str, 1)
#define UlongFromHexString(str)      PowerOfTwoFromString(str, 4)
 
unsigned long PowerOfTwoFromString(char *input, int shift)
{
    unsigned long val = 0;
    char upperLimit = 'a' + (1 << shift);
    while (*input) {
        char c = tolower(*input++);
        unsigned long digit = (c > 'a' && c < upperLimit) ? c - 'a' + 10 : c - '0';
        val = (val << shift) | digit;
    }
    return val;
 }

void setup() {
  Serial.begin(115200);
  Serial.println(UlongFromHexString("0x001FBB82"));
}

void loop() {
 
}
79  Using Arduino / Programming Questions / Re: temperature flickering. on: August 12, 2014, 02:26:40 pm
Do you really need the granularity of .5 of a degree? Don't forget that loop() is being executed pretty damn fast which could cause flickering just from the frequent updates to the display.

Two things:
     1) if you can tolerate a .75 degree swing (or whatever), maintain a lastRead[5] array for the previous readings. If the current and previous temps are less than .75 degree apart, don't bother updating the display.

     2) do your analogRead()'s at some interval you can live with. If you really need one second updates, use the millis() function to build your own delay for one second (or whatever you need). As it stands now, updates are coming so fast the fan probably couldn't keep up anyway.
80  Using Arduino / Programming Questions / Re: How to use indexOf by an byte array ? on: August 12, 2014, 10:11:42 am
You're going to have to write your own indexOf function. You can use a brute force approach that just cycles through the array, or you could use  a modified binary search since the data seem to be in sorted order.
81  Using Arduino / Programming Questions / Re: Trouble initializing i2c display on: August 12, 2014, 08:12:20 am
I haven't used the LiquidCrystal_I2C library, but the constructor call looks weird:

Code:
LiquidCrystal_I2C lcd(0x27 , 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

For most Arduino boards, pins 0, 1 are used by the Serial object and pins 2,3 are for external interrupts. In most examples I've seen for I2C use, the constructor is:

Code:
LiquidCrystal_I2C lcd(0x27 , 16, 4);  // Set the LCD I2C address

which sets the slave/master address and the column/row count. Have you tried the simpler constructor?
82  Using Arduino / Project Guidance / Re: Word lookup table on: August 11, 2014, 10:34:39 pm
I don't think you've defined the problem in a solvable form. Try restating it, using examples of what is expected.
83  Using Arduino / Programming Questions / Re: converting RTC to string on: August 11, 2014, 06:52:00 pm
I see you're using the DS1307. Keep in mind how the Time Keeper Register works. Each value is a BCD number, so if you try to display the 8 bits as a single byte, it probably won't make much sense. So if you need seconds, you read register 0 and look at the low nibble. You can find BCD routines on this Forum.

84  Using Arduino / Programming Questions / Re: Weird LCD flicker on: August 11, 2014, 06:55:09 am
Does this look a little odd to anyone else:

Code:
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);

Doesn't the Serial object use pins 0 and 1 for communication? I can see that he's not using the Serial object, but are there any uses of those pins going on behind the scenes with the IDE? It's more common to see something like:

Code:
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);


I try to avoid using pins 2 and 3 since they are often used for external interrupts. You might try rewiring the LCD and use an appropriately modified constructor.
85  Using Arduino / Programming Questions / Re: Getting a float division from integers on: August 09, 2014, 01:21:43 pm
Take a look at your options:

Code:
#include <math.h>


void setup() {

  float val = 3.5;
 
  Serial.begin(115200);
  Serial.print("floor = ");
  Serial.println(floorf(val));
  Serial.print("round = ");
  Serial.println(roundf(val));
  Serial.print("ceil = ");
  Serial.println(ceilf(val));
 
}

void loop() {

}
86  Using Arduino / Programming Questions / Re: Getting a float division from integers on: August 09, 2014, 10:16:03 am
I'm not sure how you've defined all of the variables, but I'll assume that r and oflow are floats. Then try:

Code:
float test =0;

 test = (4194304.0 / (r + (65536.0 * oflow)));

The use of the decimal point after numeric constants tells the compiler to use the float data type in the expression.
87  Using Arduino / Programming Questions / Re: How to convert HEX string to equivalent DEC integer on: August 08, 2014, 08:23:40 am
Since you're looking for the newline character, why not use:

Code:
Serial.readBytesUntil('\n', data, sizeof(data));



I would also change data from String to char data[].
88  Using Arduino / Programming Questions / Re: Need Arduino to be Faster. on: August 08, 2014, 07:22:29 am
Wrap your
Code:
Serial.print()
calls in scaffolding code. For example:

Code:
#define DEBUG      // Place at top, just after all #includes

// ...more code...

void setup() {
  #ifdef DEBUG
    Serial.begin(115200);
  #endif

  // ...more code...

  #ifdef DEBUG
    Serial.print(millis() - start);       
    Serial.print("\t");                   

    Serial.print(total1);
    Serial.print("\t");         
  // ...more Serial.print() calls...
  #endif

Now, if you comment out the #define DEBUG at the top of the file, the Serial object is no longer compiled into the program. You can get better timing and code size data without having to search/add/remove a bunch of comment characters.
89  Using Arduino / Programming Questions / Re: Atmel Studio and Syntax Highlighting on: August 07, 2014, 08:49:12 am
Perhaps this might help:

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=117624&start=0

90  Using Arduino / Programming Questions / Re: Serial port error on: August 07, 2014, 08:45:59 am
The Serial.read() method always returns a byte data type that reflects the character that was received. If you look up the ASCII code for the digit character '0', you will find it is 48.
Pages: 1 ... 4 5 [6] 7 8 ... 55