Show Posts
Pages: 1 [2] 3 4 ... 58
16  Using Arduino / Programming Questions / Re: How to combine Strings and other Variable Types on: September 07, 2014, 10:21:29 pm
A lot of people here will tell you to forget about the String class...it adds a lot of bloat to your programs. Instead, you character arrays and terminate them with the null character ('\0'). For example, run the program below and enter a floating point number via the Serial monitor to get an idea about using char arrays as strings. (Note there is a difference between String and string.) The code below converts the value to a float, but also just uses it as a string via the string copy (strcpy()) and string concatenate (strcat()) functions.

Code:
void setup() {

  Serial.begin(115200);
}

void loop() {
  char buff[25];
  char message[30];
  int charsRead;
  float val;
  
  if (Serial.available() > 0) {
    charsRead = Serial.readBytesUntil('\n', buff, 24);   // Get every thing up to the Enter key
    buff[charsRead] = '\0';                              // Make it a string
    val = atof(buff);                                    // Convert to a float
    Serial.print("The number entered was: ");
    Serial.println(val);                                 // Show as a numeric
    strcpy(message, "The number is ");                   // Copy some text
    strcat(message, buff);                               // Add the contents entered by user
    Serial.println("Or, you can print it as a string:");
    Serial.println(message);
  }
}
17  Using Arduino / Programming Questions / Re: Problems with Serial.begin on: September 07, 2014, 12:08:10 pm
I just compiled with 1.5.7 and there were no error messages.

Code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(4800, SERIAL_8E1);
}

void loop() {
  // put your main code here, to run repeatedly:

}
18  Using Arduino / Programming Questions / Re: Aother newb question on: September 07, 2014, 12:01:10 pm
You may have to wait a few weeks, but Arduino Projects for Amateur Radio (see Amazon.com) has exactly what you are looking for. The actual circuit varies according to the type of rotator you have, too. Most have 0-360 degree rotation, but the Yaesu has 0 - 450.

Jack, W8TEE
19  Using Arduino / Programming Questions / Re: Help changing time on RTC1307 with buttons on: September 07, 2014, 09:19:35 am
An RTC based on the 1307 should not be 55 seconds off over the course of a day.  I've only noticed a few seconds over several months with my RTC module. I'd investigate this first, as something is basically wrong. Doing an hour-by-hour adjustment just shouldn't be necessary.
20  Using Arduino / Programming Questions / Re: Help from someone more advanced than myself on: September 06, 2014, 09:14:03 pm
This in pretty ugly, but you might experiment with it to see how it functions:

Code:

int input1;
int input2;

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

void loop() {
  char buff[10];
  int digitsEntered;

  if (Serial.available() > 0) {
    digitsEntered = Serial.readBytesUntil('\n', buff, 9);
    buff[digitsEntered] = '\0';
    if (input1 == 0) {
      input1 = atoi(buff);
      Serial.print("input1 = ");
      Serial.println(input1);
    } else if (input2 == 0) {
      input2 = atoi(buff);
      Serial.print("input2 = ");
      Serial.println(input2);
    }
    if (input1 != 0 && input2 != 0) {
      Serial.print("input1 / input2 = ");
      Serial.println(input1 / input2);
    }
  }
}
21  Using Arduino / Programming Questions / Re: Range narrowing function on: September 06, 2014, 02:05:25 pm
Why are these comments here? They appear wrong

Code:
Flow1Value = 30*Flow1Count/169; //60*1000/2000=24
Flow2Value = 30*Flow2Count/169; //60*1000/2500=24
Flow3Value = 30*Flow3Count/169; //60*1000/2500=24
22  Using Arduino / Programming Questions / Re: Question about error " was not declared in this scope" on: September 06, 2014, 02:00:12 pm
You need to post all of your code so we can paste it into our IDE and run it.
23  Using Arduino / Programming Questions / Re: Somebody can explain to me the meaning of this part of code on: September 06, 2014, 10:06:22 am
It a function definition:

Code:
void colore(void *ptr) {       // Pass in a typeless pointer
  RGB *c;                      // Define a Red Green Blue type of pointer
  c = (RGB *)ptr;              // Cast the void pointer memory address to be an RGB pointer, assign to c

  analogWrite(GREEN, 255-c->green);   // 255 minus (*c).green, which subtracts the green element from 255
  analogWrite(BLUE, 255-c->blue);
  analogWrite(RED, 255-c->red);
}

I doubt that most programmers would write it this way.
24  Using Arduino / Project Guidance / Re: Can't receive data more than 64byte on: September 04, 2014, 11:25:04 pm
Does this give you any ideas? While running the Serial monitor, type in 80 characters (or so) and click Send.

Code:
void setup() {
  Serial.begin(115200);
}

void loop() {
  int bytesRead;
  char buff[101];
 
  if (Serial.available() > 0) {
    bytesRead = Serial.readBytesUntil('\n', buff, 100);
    buff[bytesRead] = '\0';
    Serial.print("bytesRead = ");
    Serial.println(bytesRead);
    Serial.print("buff = ");
    Serial.println(buff);
  }
}
25  Using Arduino / Project Guidance / Re: Can't receive data more than 64byte on: September 04, 2014, 11:09:58 pm
I'm guessing:

Look at the HardwareSerial.h header file found in your IDE directory:

   hardware\arduino\avr\cores\arduino

and you will see that the transmit and receive buffers are set to 64 bytes.
26  Using Arduino / Programming Questions / Re: Sketch compiles on PC but not on Raspberry Pi on: September 04, 2014, 01:09:18 pm
Yes. Go to the Raspberry Pi site and ask them.
27  Using Arduino / Programming Questions / Re: TFT ILI9341 on: September 04, 2014, 10:39:50 am
What board are you using?
28  Using Arduino / Programming Questions / Re: Help in the code sytax on: September 03, 2014, 01:44:37 pm
First, statements like:

Code:
if (val == 1 && val == 2)

don't make sense, because val is either 1 or 2, not both. My guess is that you want to use a logical OR condition, such as:

Code:
if (val == 1 || val == 2)

Also, most compilers implement what is called "short circuiting", although I don't know if the Gnu compiler does this. My guess is that it does. Short circuiting is simply a completion of the branch on the first condition that fulfills the branch. For example,

Code:
if (val == 1 || val == 2 || num == 10 || num == 13)

With short circuiting, if val equals 1, the rest of the expression is not even evaluated and the if statement block is executed. Therefore, in complex expressions, it sometimes makes sense to put the most likely outcome first in the expression list.
29  Using Arduino / Programming Questions / Re: working with Array (basic code but very strange) on: September 03, 2014, 12:22:27 pm
Quote
Isn't all this a bit pointless in the small Arduino environment?

As the programmer you decide what size the array will be so why is there a need to use sizeof().
If you need to use the size of the array in a FOR loop, for example just use
Code:
const byte arrayLen = 6;
int myArray[arrayLen];

I disagree strongly. The sizeof operator offers numerous advantages. Using the Array_Size() macro is typeless, so if I want to march through a for loop using an int array, I can use the macro. If I want to traverse a different array of type float, I can use the same macro because it is typeless. Your way requires defining a const for each array used in the program if they have different element counts. Also, if I change the size of the array, I need to remember to edit the length constant, too. The macro obviates such changes. Finally, the macro allows you to get away from "magic numbers" (e.g., 6) in the code.
30  Using Arduino / Programming Questions / Re: 'Beginning C for Arduino by Jack Purdum' book errors? Modified Blink program on: September 02, 2014, 10:11:48 pm
Stick with it and make sure you work the exercises. When you get finished with it, all of this will look like duck's soup.
Pages: 1 [2] 3 4 ... 58