Show Posts
Pages: 1 ... 20 21 [22] 23 24 ... 285
316  Using Arduino / Programming Questions / Re: GPS & nrf24l01+ issues on: July 05, 2014, 02:08:29 am
Auto Format has told you that you have too many right braces, the } character. Each { needs a corresponding } but they must be in the correct place such as the start and end of a function or a code block to be executed when a condition is true, for example.  In the IDE put the cursor to the right of any bracket or brace and the IDE will indicate its corresponding partner, if it exists.

As to
Code:
while(true);
What are you trying to do ?  Will the statement ever be false and allow the program to continue ?
317  Using Arduino / Programming Questions / Re: GPS & nrf24l01+ issues on: July 04, 2014, 04:10:15 pm
Try Auto Formatting your code in the IDE.  You should get a clue as to what is wrong.

Where does the loop() function end in your program ?

Also, is this
Code:
    while(true);
useful ?
318  Using Arduino / Programming Questions / Re: Sketch Optimization and Feasibility On An ATtiny on: July 04, 2014, 12:25:51 pm
Quote
UKHeliBob, would it be better to change
Code:
boolean doorSwitch[3];
to
Code:
int doorSwitch[3];
to make it more clear that I'm actually checking for HIGH/LOW rather than true/false?
Code:
const byte doorSwitch[3];
would be better.  const because the values will never change and byte because it takes less space.
319  Using Arduino / Programming Questions / Re: Arduino Autonomous GPS Navigation on: July 04, 2014, 10:38:34 am
Are you sure that the GPS is getting a lock ?
320  Using Arduino / Programming Questions / Re: Just can't quite get the code right on: July 04, 2014, 04:43:44 am
Quote
I just need to figure a better delay instead of using delay()
All Together Now "BlinkWithoutDelay"
321  Using Arduino / Programming Questions / Re: Sketch Optimization and Feasibility On An ATtiny on: July 04, 2014, 01:29:46 am
Quote
I didn't fully understand what you were saying about booleans. Do you mean to be careful with checking a boolean for its intended value? As in, make sure to only check if true/false booleans are true or false, not HIGH or LOW?
Checking that booleans are true/false is what I meant.  Currently you have
Code:
boolean doorSwitch[3];
Code:
 if (doorSwitch[0] == HIGH || doorSwitch[1] == HIGH)
This works but is not as clear as it might be.
322  Using Arduino / Programming Questions / Re: elapsedMillis help on: July 03, 2014, 10:30:07 am
Code:
if( digitalRead(switchPin)==HIGH)while(digitalRead(switchPin)==LOW);
You check to see whether the switch pin is HIGH and if it is, enter a loop that is only executed if it is LOW.  Have I read that right ?

Code:
if( digitalRead(switchPin)==HIGH)
{
while(digitalRead(switchPin)==LOW);
}
323  Using Arduino / Programming Questions / Re: Breaking down a programme. on: July 03, 2014, 10:15:40 am
Quote
I have noticed that when a function calls another function , the calling function has to be located after the called one for the compiler to find the reference.
Not if you use the Arduino IDE, because it creates the function prototypes behind the scenes and puts them near the start of the program for you.
324  Using Arduino / Programming Questions / Re: How are INPUT, OUTPUT, and INPUT_PULLUP defined? on: July 03, 2014, 10:12:27 am
Use the Arduino to tell you the answer.
Code:
void setup()
{
  Serial.begin(115200);
  Serial.print("INPUT : ");
  Serial.println(INPUT);
  Serial.print("OUTPUT : ");
  Serial.println(OUTPUT);
  Serial.print("INPUT_PULLUP : ");
  Serial.println(INPUT_PULLUP);
}

void loop()
{
}
325  Using Arduino / Programming Questions / Re: Sketch Optimization and Feasibility On An ATtiny on: July 03, 2014, 10:07:34 am
Be careful with your use of boolean variables and checking their value.  Whilst it is possible to create a boolean variable whose value is normally expressed as true or false and actually check whether its value is HIGH/LOW or 1/0 it is not so obvious what is going on when you read the code.  There is also a possible problem when using boolean varaibles in that HIGH/LOW and 0/1 are either/or values whereas that is not the case for true/false.   0 is false and any other value is true.

Another thought.  How are the switches wired ?  Do they have any resistors attached to ensure a consistent voltage when not activated ?  Whilst it is admirable that you have debounced the switches is it really necessary in this application ?
326  Using Arduino / Programming Questions / Re: How to handle lots of sensors data? on: July 03, 2014, 01:56:42 am
You have not said what type of sensors you are using but here are some ideas using digital sensors
Code:
if (digitalRead(sensorPin1) == HIGH)
{
  //do stuff if the input is HIGH
}

if (digitalRead(sensorPin1) == HIGH && digitalRead(sensorPin2) == HIGH) //etc
{
  //do stuff if both are HIGH
}


if (digitalRead(sensorPin1) == HIGH || digitalRead(sensorPin2) == HIGH) //etc
{
  //do stuff if either is HIGH
}

Then you mention serial input.  You can monitor serial input by parsing the incoming data and using the value(s) derived to decide on actions to be taken.  If more than one set of serial data is to be received and parsed then it will need to include an identifier for each set of data or be in a fixed format, such as comma separated, so that it can be parsed correctly.
327  Using Arduino / Programming Questions / Re: I need 3 digital inputs to control 2 outputs on: July 02, 2014, 01:55:39 pm
There may be other problems but I looked no further than
Code:
if ((buttonState1 == 1) && (buttonState2 == 1));
Remove the semi-colon or the if will not be acted upon.
328  Using Arduino / Programming Questions / Re: Keeping all libraries in the Arduino sketch directory on: July 02, 2014, 11:15:57 am
I suspect that it will not work but it will be easy for you to check.
329  Using Arduino / Programming Questions / Re: 2 Digital Pins & 4 States = 4 Messages on LCD. Nearly done but need some advise? on: July 02, 2014, 02:49:35 am
Code:
int systemState = (digitalRead(button1) * 2) + digitalRead(button2);
systemState will have a value of 0, 1 , 2 or 3 depending on which combination of buttons are pressed.  Use that in switch/case to display the relevant message but don't forget to clear the screen if the value changes so that the previous message is removed.
330  Using Arduino / Programming Questions / Re: Stepper Motor button direction control. on: July 02, 2014, 02:25:18 am
You are confusing a for loop which causes something to happen for a fixed number of times, with the English usage of "do this for a length of time".

One way to introduce a wait for a time period is to use the delay() function
Code:
delay(1000);
will wait for 1000 milliseconds.  This is all very well, but nothing else can happen during the delay().  That's OK if that is what you want to do but often there is a need for something to happen for a period of time, but for inputs to be read during that period.

To do that you note the start time of the period and then check frequently to see if the period has elapsed.  If not, go and do something else.  The loop() function provides a very convenient mechanism to do the frequent checking.

This principle is often referred to BlinkWithoutDelay because of the example of that name in the IDE.
Pages: 1 ... 20 21 [22] 23 24 ... 285