Show Posts
Pages: 1 ... 90 91 [92] 93 94 ... 231
1366  Using Arduino / Programming Questions / Re: How do I set different outputs along a Senors values like a to b, c to d, etc on: June 09, 2013, 02:11:41 pm
i'm trying to turn a relay on and off with different light intensities, currently it turns on above 650.  i would like to be able to change to time the relay is on based on the light intensity range, ie 650-750 and so on.

Then a you want a switch ranges as such:

Code:
switch (someInput)
{
  case 1 ... 5: // 1 to 5
    output = someValue1;
    break;
  case 6 ... 10: // 6 to 10
    output = someValue2;
    break;
  case 1 ... 15: // 11 to 55
    output = someValue3;
    break;
  default:
    output = someValue4;
    break;
}
1367  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 02:04:02 pm
Code:
else
  int value
  for(value = 0 ; value <= 1; value+=5)
  {
    digitalWrite(M1, LOW);  
    digitalWrite(M2, LOW);    
    analogWrite(E1, 1);
    analogWrite(E2, 1);   //PLL Speed Control
    delay(30);
  }  

Watch your curly braces. The indentation here suggests you want all of this code to be inside the else clause, but no curly braces means the only the first statement is:

Code:
if (someCondition)
{
  // code runs when someCondition is true
}
else
// first line of code runs when someCondition is false
// anything after that runs no matter the result of someCondition

Even if you only want a single statement to run, its good practice to ALWAYS surround code with curly braces for if/elseif /else so that you don't run into issues like you are having:

Code:
if (someCondition)
{
  // code runs when someCondition is true
}
else
{
  // code runs when someCondition is false
}
// code runs no matter the result of someCondition

You should also use the Auto-format tool (Ctl+T or Tools > Auto Format) to make sure you have proper indentation that won't cause confusion down the road. There is also the added benefit of telling your when you have an uneven number of right and left curly braces. Every opening left curly brace should have a closing right curly brace. Every closing right curly brace should have an opening left curly brace.

Lastly, don't just post "So" and a bunch of code, post something of value like "I tried this: <CODE> and now I'm getting this error message <ERROR MESSAGE>". Code goes in CODE tags, not QUOTE tags.
1368  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 01:51:07 pm
Quote
You can't turn an if statement into a function, you can only nest it within the function.

the statement is = if (position == 3)


So that needs to be within a function:

Code:
void someFunction()
{
   if (position == 3)
   {
     // code
   }
}
1369  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 01:42:41 pm
Because i don't understand how you nest a statement into a code!


What do you mean by "nest a statement into a code"? What do you consider "a statement"? What do you consider "a code"?
1370  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 01:36:55 pm
but if i turn
Code:
if (position == 3)
in to
Code:
int if (position == 3)

it stills shows the error of expected unqualified-id before if

That's because you are trying to turn the code into a function. You can't turn an if statement into a function, you can only nest it within the function. Why are you trying to turn that code into a function?
1371  Using Arduino / Programming Questions / Re: Return? how does this work? on: June 09, 2013, 01:34:26 pm
will this also call the function or do i have to do that before?

Code:
if(currentTime - ethernetMaintainTimeLapsed > 60000) {
    Ethernet.maintain();
    ethernetMaintainInterval = currentTime;
  }

That will call the function, but you return value will be discarded.
1372  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 01:29:12 pm
You can't have a function nested within another function:

Code:
void someFunction()
{
  // some code here
  int someNestedFunction()
  {
    // code
    return someInt;
  }
}

Functions need to be separate:

Code:
void someFunction()
{
  // some code here
}

int someNonNestedFunction()
{
  // code
  return someInt;
}

Quote
Can you give me an example of how i am supposed to do it because i don't have much time left!

That sounds suspiciously like "please do the rest of my assignment for me"
1373  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 01:19:41 pm
sorry I am a newbie. So how do you put it in a function (i'm dutch and 12 years so sorry for my english)

Assuming you don't have to return a value:

Code:
void someFunctionName()
{
  // code goes here
}

Assuming you do have to return a value (int in this example:

Code:
int someFunctionName()
{
  // code goes here
  return someInt;
}
1374  Using Arduino / Programming Questions / Re: How do I set different outputs along a Senors values like a to b, c to d, etc on: June 09, 2013, 01:18:13 pm
I'm assuming you have to use map function but not sure how to set this up.

Only if there exists an equation that can take the unmapped value and make it into a mapped value. If you had a subset like this:

1 -> -4
2 -> 8
3 -> 1000
4 -> -2345
5 -> 1

then the map function won't work. In cases like this, you would need an if/else if or an array.

You would be better off posting more information, like the code you have currently and a better description (including examples) of what you want to do.
1375  Using Arduino / Programming Questions / Re: expected unqualified-id before 'if' on: June 09, 2013, 01:13:37 pm
it still doesn't work

error: expected unqualified-id before 'if'


Post the updated code, so we know you did it right.

how do you make the if statement in a function?

You don't, you put it into a function.
1376  Using Arduino / Project Guidance / Re: Serial Error Reason ? on: June 09, 2013, 12:56:49 pm
if that's the case, then nothing happens either ways ( according to plan ) .

Yes, but you are assuming something does happen when you try to process the data you received here:

Code:
getSerial();
trueval = serialData * 100 ;
getSerial();
trueval = trueval + serialData * 10 ;
getSerial();
trueval = trueval + serialData ;

The improper way to do it would be to make getSerial blocking until data has been received. The proper way to do it, is to not act on data until some kind of terminating byte is sent.

Also, are you returning serialData when it is a global variable?
1377  Using Arduino / Project Guidance / Re: Push-Button LED help on: June 08, 2013, 11:25:24 pm
Post your code.

Post a description of how things are connected.
1378  Using Arduino / Programming Questions / Re: Two characters(char) from serial monitor in the one field of the matrix-Problem! on: June 08, 2013, 11:18:19 pm
Read one character. Convert it from ASCII to binary. Store it in a variable. Shift the contents of the variable to the left by 8. Read the second character. Convert it to binary and add it to the variable:

Code:
char h = 'F';
char l = 'F';

int r = hexASCIItoBinary(h);
r <<= 8;
r+= hexASCIItoBinary(l);
1379  Using Arduino / Programming Questions / Re: HOW DO YOU USE BUTTON TO SWITCH BETWEEN 4 SEQUENCES on: June 08, 2013, 11:11:27 pm
Take a look at the BlinkWithoutDelay for writing non-blocking blinking code.

Take a look at the StateChangeDetection example for handling button toggling.

Create a state machine in which the state is changed based on the momentary switch being pressed/released. The state will determine which LEDs blink.

Don't try to get everything working at once, get a small part working. Study it to the point where you understand it. Then, add another feature. Rinse and repeat.
1380  Using Arduino / Programming Questions / Re: Stringreplace() function on: June 08, 2013, 10:11:04 am
With zoomkat code I can add serial data to a string. So what I have to do to parse floats from created string?

Ask zoomkat. S/he is the only regular around here that recommends using Strings.
Pages: 1 ... 90 91 [92] 93 94 ... 231