Show Posts
Pages: 1 [2] 3 4 ... 67
16  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 08:47:59 am
Code:
      if (buttonState == HIGH) {
The key insight is that this test needs to test buttonState _and_ time since last button press before deciding the button press is GO.

-br
17  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 07:19:15 am
Think a little more about what needs to be locked out.  Not the whole servo loop, just the button check, right?


-br
18  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 07:01:38 am
I am sorry to inform you that you are a little further from your objective than you may have thought.  This happens often in this game.  You'll be finished faster if you lose the denial and get on with the work.

It is not possible to run the servo while inside your new hypothetical button lockout if the lockout is implemented as a delay.  Delay blocks everything else.  This is why it is necessary to use a method that keeps track of time.

You don't want a delay.  You want a lockout.  Think of it in those terms and you might get somewhere.


-br
19  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 06:45:56 am
The Blink Without Delay example contains an example of this sort of timing logic.

Good luck with your project.

-br
20  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 06:37:17 am
You don't need a delay.  You need to make note of the time when the button is pressed by saving millis() in an unsigned long variable. Then when the button is pushed again, you need to check the difference between the current time and the saved time and see if enough time has passed to allow the button push to proceed.

-br
21  Using Arduino / Programming Questions / Re: Pulsing LED with varying speed keeps jumping brightness? on: May 10, 2013, 06:29:21 pm
Direct Digital Synthesis (DDS) via lookup table is an approach for generating sinusoidal output worth looking at.  It's much faster than floating point arithmetic because it's based on table lookups.

Here is a good example, and you don't even need the low-pass filter for your LED application:

http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/


-br
22  Using Arduino / Programming Questions / Re: Countdown timer on: May 10, 2013, 11:30:28 am
To decrement timer it is sufficient to say:
Code:
    --timer;

-br
23  Using Arduino / Programming Questions / Re: scrolling thru variables with "for...loop" to apply array on: May 10, 2013, 11:20:57 am
Your syntax is creative but not C.  Something like this might work better:
Code:
int pins[] = {2, 3, a2};
void loop(){
      for(int i = 0; i < 6; i++){
        pinMode(pins[i], arrayX[i]);
      }
      
      for(int i = 0; i < 6; i++){
        digitalWrite(pins[i], arrayY[i]);
      }
}

Edit: of course, you want six elements in pins[]…
24  Using Arduino / Sensors / Re: Trying to use digital input 0 & 1 as button inputs - unsucsesfully on: May 10, 2013, 11:08:48 am
Confirm you're not calling Serial.begin()?

Post your code and we might be able to offer better answers.

-br
25  Using Arduino / Interfacing w/ Software on the Computer / Re: Communication both read and write at the same time on: May 10, 2013, 09:57:25 am
Look into the VirtualWire library.

-br
26  Using Arduino / Programming Questions / Re: Simple concatenation (to trigegr a random fonction) on: May 10, 2013, 09:50:52 am
What you are trying to accomplish is usually done in C with an array of function pointers, one entry for each of the functions.  You can select a random index into the array and call the function through the pointer.

Read up on "function pointer table in C" and you'll get the idea.

With that many functions, it will be worth your while to learn how to put the table of function pointers into PROGMEM, as well.

Good luck with your project,

-br
27  Using Arduino / Programming Questions / Re: How to make global variables accessible to libraries/classes? on: May 10, 2013, 08:52:01 am
Quote
I mean I used Serial.print in the main loop, in the class functions, and in the constructor…

It's my understanding that your constructor can't do much because the Arduino hardware isn't initialized yet.  Printing is a no-no, millis() isn't initialized, and so on.  Perhaps someone more familiar with the issue can jump in with more if I've got this wrong.

You could use a .begin() method, like Serial does, to work around this.

-br
28  Using Arduino / Interfacing w/ Software on the Computer / Re: Wondering how to interface Arduino with Java on: May 10, 2013, 07:03:44 am
http://playground.arduino.cc/Interfacing/Java

-br
29  Using Arduino / Programming Questions / Re: How to make global variables accessible to libraries/classes? on: May 10, 2013, 06:57:45 am
Code:
since the Arduino IDE doesn't allow me to define classes in the sketch
Now I am puzzled.  What gave you this idea?  The IDE doesn't enforce syntax, and the compiler is a C++ compiler.

It would help to understand the current organization of the code a little better.  Where are the globals declared in your big pile of code?  And where are they defined?

Can you post the code, piecemeal if needed, in code tags, please?

-br


30  Using Arduino / Programming Questions / Re: Variable scope and RAM on: May 09, 2013, 08:16:22 pm
Yes, because C locals live on the stack.

Once the procedure defining a local variable returns, the location on the stack reserved for that local is released with the rest of the stack frame to become free stack space (or more properly free space between the stack and the malloc heap).

-br
Pages: 1 [2] 3 4 ... 67