Show Posts
Pages: 1 ... 23 24 [25] 26 27 ... 285
361  Using Arduino / Programming Questions / Re: Growing numbers to the left on: June 28, 2014, 10:27:31 am
The thread title sounds like you are trying to right justify the number when printed.  If so then printing 3 spaces after each number will not work.

Peter's suggestion will though.  The snprintf() function formats a char array containing the number, then you can print the formatted buffer just like any other char.  Try Peter's example, play with the number being printed and see what it does.
362  Using Arduino / Programming Questions / Re: ls20031 GPS chip cant receive NMEA messages continously on: June 28, 2014, 10:22:19 am
You were a bit quick with the bump, don't you think ?
Can you please be as quick posting your code so that we can see what you are doing ?
363  Using Arduino / Programming Questions / Re: Controling servos with buttons on: June 28, 2014, 10:08:25 am
Quote
How about now?
Closer, but still no cigar.
You have no bounds checking on the value of pos.  Its value should stay between 0 and 180.

Also, compare
Code:
  if (digitalRead(buttonleft) == HIGH);
and
Code:
  if (digitalRead(buttonright) == HIGH)
Spot the difference.

Have you got any pulldown resistors on the button pins to stop their voltage floating and providing spurious inputs ?

As written, holding down a button will rapidly cause the servo to move one way or the other (once the code is fixed, of course).  Is that what you want or should the servo only move a little each time a button becomes pressed and not move any further until it is pressed again ?
364  Using Arduino / Programming Questions / Re: Controling servos with buttons on: June 28, 2014, 02:35:40 am
Quote
Whats wrong with it?
Code:
 else (digitalRead(buttonleft) == HIGH);
What is that supposed to do ?  It is not testing the state of buttonleft which is presumably what you want it to do.
Code:
   myservo.write(5);
    myservo.write(-5);
These 2 lines are presumably supposed to move the servo in increments of 5 either way.  However, msyservo.write() takes an absolute position as its argument and not an increment from where the servo currently is.  You need to read the buttons and if pressed update a position variable and use that as the argument to myservo.write() making sure that the value stays in bounds which -5 is not by the way.
365  Using Arduino / Programming Questions / Re: Using Unsigned Chars in Arduino on: June 28, 2014, 02:24:23 am
Quote
as Strings cannot contain unsigned chars.
Do you mean Strings or do you mean strings ?
366  Using Arduino / Programming Questions / Re: push buttons to change frequency on: June 28, 2014, 01:40:46 am
I suggest that you post the code that you have that uses the pot. 
Presumably moving the pot causes a variable to change.  If so then using buttons to change the variable should be easy.
367  Using Arduino / Programming Questions / Re: How to make Loop only run a certain number of times on: June 27, 2014, 12:24:01 pm
If by "loop" you mean "the" loop, as in void loop() {} then you can't afaik- its job is to loop for ever.

But you could put a for in setup().

EDIT.... like steinie44 said  smiley
Or count the required number of times through the loop() function then enter a while loop with an exit condition that will always be true.
368  Using Arduino / Project Guidance / Re: Help starting my sketch on: June 27, 2014, 07:57:55 am
Could you give me an example of what that would look like?
Here is some pseudo code to give you a start
Code:
start of loop()
  //code to detect light and soil moisture

  if watering is needed
    //commands to start watering
    startedWatering = millis();
  end of if
 
  if millis() - startedWatering >= waterinfPeriod
    //commands to stop watering
  end of if

end of loop()
369  Using Arduino / Programming Questions / Re: Declare functions and classes in sketch on: June 27, 2014, 04:55:53 am
Quote
Because compiler reads from top to down all classes and functions needs to be placed in an order for the compiler to work.
If you trying to call a function before it's declared you get a scope error.
That is not true of functions when using the Arduino IDE.  Consider this
Code:
void setup()
{
  Serial.begin(115200);
  funcB();
}

void loop()
{
}

void funcB()
{
  Serial.println("In funcB");
  funcA();
}

void funcA()
{
  Serial.println("In funcA");
}
In the code as presented funcA() is called before it is defined, but it works.  Behind the scenes the function prototypes are added to the program as part of the process of checking or uploading the code.
370  Using Arduino / Project Guidance / Re: Help starting my sketch on: June 27, 2014, 04:41:02 am
I would start the loop() function with a check of the light level rather than the moisture and do nothing if it is not dark.  Then if it is dark do the moisture check, start watering if it is dry and stop watering when it is wet enough.  That way you do not have to check the light level elsewhere the program.

To improve readability of the code I would give the pins meaningful names either by using #define or by using const int named variables.  If at some point you want to incorporate other inputs, perhaps a manual override to stop watering or a temperature sensor perhaps, then you would be wise to avoid using the delay() function because it blocks program operation.  Instead use the principle shown by the BlinkWithoutDelay example in the IDE to note the start time of a state and check periodically if the required elapsed time has passed.
371  Using Arduino / Project Guidance / Re: Help starting my sketch on: June 27, 2014, 02:23:31 am
The most useful thing that you can do is to post your code, including the if statements that you are having trouble with and explain what is going wrong.
372  Using Arduino / Programming Questions / Re: The easiest way to do a "single-game" console? on: June 26, 2014, 03:35:41 pm
Have you done any research on the functions in the library ?
http://arduino.cc/en/Reference/TFTLibrary
http://arduino.cc/en/Reference/TFTLoadImage seems to be what you want.
373  Using Arduino / Programming Questions / Re: How use a function? on: June 26, 2014, 08:07:15 am
Quote
I tried move the  function "remoteIP"  to the class "UIPClient" but  the function returns an IP wrong .
Have you any code that you want to share with us ?
374  Using Arduino / Programming Questions / Re: Hello guys I need some helping hand... on: June 26, 2014, 06:55:45 am
Quote
Sir Hellibob... can you show me how it is done? i dont really have an idea how to do that
Have you looked at and do you understand the BlinkWithoutDelay example in the IDE ?  If not then do it now.

You will need to restructure your program so that you keep calling the popo() function. When it is first called send the carriage return and save the first start time from millis().  Next time it is called check whether the required interval has passed and if so send the first AT command string and save the new start time.  Next time it is called check whether the required interval has passed and if so send the second AT command string and save the new start time.  Carry on the same way until all the data has been sent.  If you update a byte variable in popo() as each command is sent you can keep track of what state the system is in, how long to wait and what to do next.  You will have created a State Machine.

I see, however, that there are suggestions in this thread that you may not need to wait as long between sending, if at all.  What is it that you want to do whilst the data is being sent ?
375  Using Arduino / Programming Questions / Re: Hello guys I need some helping hand... on: June 26, 2014, 01:17:48 am
Quote
is it possible to remove the delay in sending message and change it into millis?
Yes.

Does there actually have to be a delay between the commands and data in the popo() function and if there does do they need to be as long as one second ?
Pages: 1 ... 23 24 [25] 26 27 ... 285