Show Posts
Pages: 1 [2] 3 4 ... 33
16  Using Arduino / Programming Questions / Re: Compilation error: 'new_8_4' was not declared in this scope on: April 21, 2014, 09:38:51 pm
No, they're not variables, they are missing functions that don't appear to be in the source code. The first compiler error message is on:


which is a missing function. It, and the others I checked, are not in the source file.
17  Using Arduino / Programming Questions / Re: Making an array element a reference to another variable on: April 21, 2014, 06:39:21 pm
I read it differently. I thought he is asking for an array of pointers to other variables. For example:

void setup() {
  //Initialize serial and wait for port to open:\
int *ptr[10];
int i;
int a, b, c;

a = 5;
b = 10;
c = 15;

ptr[0] = &a;
ptr[1] = &b;
ptr[2] = &c;
for (i = 0; i < 3; i++)
18  Using Arduino / Programming Questions / Re: if else or switch case? on: April 21, 2014, 12:05:20 am
I just checked some research that Nick did and it appears that a switch-case does not always produced a jump table:;wap2

Unless I was doing some time-sensitive code where I could see that the switch-case was a problem, I'd stick with it because, for me at least, it is easier to read.
19  Using Arduino / Programming Questions / Re: if else or switch case? on: April 20, 2014, 11:47:38 pm
@michinyon: If I had to maintain the code, I'd rather see 25 case blocks. Like CrossRoads, I, too, was under the impression that the Gnu compiler would generate a jump table for switch statements which would be more efficient. I'd check, but all I have is a tablet right now.
20  Using Arduino / Programming Questions / Re: if else or switch case? on: April 19, 2014, 08:48:44 pm
To the above I would add that there are dumb uses of both, but I've seen some RDC (Really Dumb Code) using a cascading if statement. The following was in an actual piece of production code I saw:

if (day == THEFIRST)
else if (day == THESECOND)
else if (day == THETHIRD)

// more of the same...

else if (day == THETWENTYEIGHTH) {
   if (isLeapYear())
else if (day == THETWENTYNINTH)
else if (day == THIRTHIETH)
else if (day == THIRTHYFIRST)

I kid you not. On average, there would be 14 false if tests in this nightmare. This begs for a switch. I have not looked at the Gnu compiler code, but most C compilers I've used generate a jump table for a switch, which is usually pretty efficient. Anyway, for me, most of my applications are such that memory is not an issue, so I go with code readability and I think the switch wins that metric.
21  Using Arduino / Programming Questions / Re: Need some help with my code ,please on: April 19, 2014, 01:48:58 pm
There's no need to apologize...all of us have been there. We're just trying to understand what you're trying to do and point you in the right direction.

It appears that, depending on the reading of previousPosition, the for loops adjust by the 3rd expression in the for loop, either to raise something (temperature??) or lower it:

previousPosition += 1


previousPosition -= 1

In both loops, the comparison is made to servonormal. If that's the case, why not use:

while (previousPosition != seronormal) {
   // get the data here
   if (previousPosition < servonormal)
      previousPosition++;      // same as previousPosition += 1
      previousPosition--;      // same as previousPosition -= 1

I think this is what you are trying to do.
22  Using Arduino / Programming Questions / Re: Need some help with my code ,please on: April 19, 2014, 01:20:38 pm
I still think this statement:

for (previousPosition != 0; previousPosition < servocold; previousPosition += 1)

is suspect, because the expression:

previousPosition != 0

is either logic True (1), or false (0). You may think it's working as you want it to, but I serious doubt it. The only reason it works is because the logic conditions start the loop either with 0 or 1, depending on the logic state.  There is nothing in the ANSI standard for C that requires logic True to be 1 and logic False to be 0. Indeed, some early compilers used -1 for True and still others used -1 for False.  Also, as you've written the loop, it tests a "position" against "servocold", which is either strange or a poor choice of variable names. Finally, just because serendipity makes a program work doesn't mean it's properly coded. Such things come back to bite you later on.
23  Using Arduino / Programming Questions / Re: Need some help with my code ,please on: April 19, 2014, 12:53:47 pm
In several places you have:

for(previousPosition != 0; previousPosition < servocold; previousPosition += 1)  // goes from 0 degrees to 180 degrees

A for loop has 3 expressions:
   1) the starting condition of the variable that controls the loop
   2) a (relational) test that determines if another iteration through the loop is needed
   3) usually a change in the variable that controls the loop.
Your expression 1 looks suspect, since it is a relational test, not what is usually an assignment statement. Given your comment, it probably needs to look something like:

int degrees;

for(degrees = 0; degrees < servocold; degrees++)  // goes from 0 degrees to 180 degrees

This code marches through from 0 up to servocold 1 degree at a time.

Also, when you post code here, place your cursor in the IDE source code window, press Ctrl-T, which formats it for you. Then press Ctrl-A to copy all of your code. Then come to this forum, start your post, hit the pound sing (#) and copy your code between the two code tags. That makes it easier for us.
24  Using Arduino / Programming Questions / Re: the if-case is taken only one time in the while-loop, why? on: April 19, 2014, 12:37:40 pm
AWOL: does he need it? He is in an infinite while loop and I don't see a break, so it never comes out of it.
25  Using Arduino / Programming Questions / Re: How do I move a sequence through an array? on: April 19, 2014, 10:25:56 am
...example of how of use the modulo operator...

Suppose you want to find out if an integer is odd or even. The modulo operator (%) gives you the remainder after division. Then:

int wholeNumber;
int i;
int remainder;

for (i = 0; i < 30; i++) {
   wholeNumber = i / 2;
   remainder = i % 2;
   Serial.print("wholeNumber = ");   // integer division
   Serial.print(wholeNumber );        // modulo
   Serial.print("    remainder = ");
   if (remainder == 1) {
      Serial.println("Number is odd");
   } else {
      Serial.println("Number is even");

If you put this in the setup() function and run it, you will see how modulo is different than division. Because the modulo gives the remainder after division, remainder will alternate between 0 and 1, while wholeNumber increases as the loop progresses. The increase will not be "smooth", however, since integer division truncates the result.
26  Using Arduino / Programming Questions / Re: How do I move a sequence through an array? on: April 18, 2014, 11:07:11 pm
HazardsMind: Your approach puts a bandage on the wound, our approach heals the wound so you don't need the bandage.
27  Using Arduino / Programming Questions / Re: How do I move a sequence through an array? on: April 18, 2014, 09:13:01 pm
In your macro:

#define SIZE (sizeof(Array)/sizeof(Array[0])-1)

for a byte array, it evaluates to;

size = 10 / 1 - 1 = 9

Then in your for loops, you get:

for (j = 0; j < 9; j++) {

which only reads 9 elements (0-8), not 10. The macro you are using gives the number of elements in the array, not the highest index of the array. You would never read the last element...the old off-by-one problem. You should drop the -1 from the macro.
28  Using Arduino / Programming Questions / Re: getting else without previous if error on: April 18, 2014, 09:03:58 pm
Do you really want to do this:

analogRead(pressure >= 1)

as part of the if statement? I guess that, if pressure is greater than or equal to 1, the expression is logic True, which then performs an analogRead() on pin 1. I don't think that's what you really want to do. Perhaps:

if (analogRead(pressure ) >= 1  &&  pressure <= 100)
    digitalWrite(green, HIGH);
} else {
    digitalWrite(red, HIGH);

Also, before you post your code, place your cursor in the source code window and press Ctrl-T to reformat you code to a more readable format. Then copy that code between the code tags, which you can call up by clicking the pound sign (#).
29  Using Arduino / Programming Questions / Re: Sketch on Mini w/328 only runs once on: April 18, 2014, 10:32:06 am
@raschemmel: Too subtle?
30  Using Arduino / Project Guidance / Re: void loop() 1 void loop() 2 on: April 18, 2014, 08:49:19 am
You can load and run the Blink Without Delay sketch by following the Arduino IDE menu sequence

File --> Examples --> Digital --> BlinkWithoutDelay
Pages: 1 [2] 3 4 ... 33