Show Posts
Pages: 1 ... 38 39 [40]
586  Forum 2005-2010 (read only) / Frequently-Asked Questions / Show a pusbutton "bounciness"... on: July 06, 2010, 05:05:53 am
Hi,
    I have a dfrobot "joystick + 3 pushbuttons" shield, and I wanted to count the number of bounces I get when pushing each of the three buttons.

When used with the dfrobot shield I mentioned, this code show the number of bounces of the joystick button.

Change btnPin value to taste.

Code:
/*
 * Test a pushbutton "bounciness".
 *
 * Connect a pushbutton to pin 5.
 * Open serial monitor.
 * Push the button and see the transition count
 * on the serial monitor.
 * It should read 2 (press + release),
 * but because of the "bounce" problem, the number of
 * transisions can be 4, 6 or even higher.
 *
 */

int btnPin = 5;
int btn;
int prevBtn;
long cnt = 0;
long prevMillis;


void setup() {
    Serial.begin(115200);

    pinMode(btnPin, INPUT);
    btn = digitalRead(btnPin);
    prevBtn = btn;
}


void loop() {
    btn = digitalRead(btnPin);
    
    if (btn != prevBtn) {
        prevBtn = btn;
        cnt++;
        prevMillis = millis();
    }
    
    if (millis() - prevMillis > 2000) {
        prevMillis = millis();
        Serial.println(cnt);
        cnt = 0;
    }
}
587  Forum 2005-2010 (read only) / Uno Punto Zero / Detect new libraries with IDE open on: July 26, 2010, 10:33:09 am
I've noticed that if I create a new library while the Arduino IDE is running, I have to close and reopen it to make it recognize the new library, otherwise the compilation will fail with a "file not found" error message.

This is a minor inconvenience; nonetheless it would be nice if it was solved.
588  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Skins for Arduino? Why not? on: July 26, 2010, 06:33:36 am
I have no idea what it would take to implement a "skinnable" IDE. As long as it doesn't slow down the IDE nor decreases its stability, it's ok with me.

:-)
589  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Skins for Arduino? Why not? on: July 26, 2010, 04:51:10 am
-1 for IDE skins. I think it would add useless bloat to IDE code.
590  Forum 2005-2010 (read only) / Uno Punto Zero / Abstracd LiquidCrystal class on: July 23, 2010, 05:19:02 pm
I've bought three different models of LCD for the Arduino. One of them is parallel, i.e. is directly connected to the Arduino digital pins, the other two are serial, i.e. you don't manage the display pins directly, but talk to a uP (tipically a PIC16) via Serial or software serial. The protocol is usually very simple: send an ascii char and it gets displayed. Send a byte < 32 (dec) and you are altering some lcd params. Usually there's also an escape byte to pass data directly to the lcd controller.
I've found that the LiquidCrystal library can be adapted quite easily to the serial LCD even if it's been written for the parallel ones.

The libs for the serial displays can be implemented as derived classes of the LiquidCrystal lib. Still I feel it would be more logical to have a base abstract class and derive from there the current LiquidCrystal lib as well as the serial ones.
Also, libraries for some serial LCDs should be included in the base distribution.

My 2 cents.

P.S.: I'll post some code as soon as I polish it a bit...
591  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Be able to set a region in a defined piece of code on: August 15, 2010, 12:50:43 pm
Quote
I have resorted to placing multiple commands on a single line in order to shorten the overall length of the sketch.  Most code structure nazis cringe at the thought of this, I'm sure, but it has become a necessary evil to me.

I usually pay attention not only to code structure, but even to the number of blanks between a closing paren and an opening brace.
I even align comments.
Trashing code structure just to "shorten the length of the sketch" is a very, I mean VERY bad idea. You're trading a fundamental code maintenance requirement for the nuisance of scrolling through a long text file. The "necessary evil" you're talking about is learning how to split a sketch into multiple files or, better yet, learn how to write libraries (this site has a very good tutorial).

:-)
592  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Be able to set a region in a defined piece of code on: July 31, 2010, 04:38:09 pm
Quote
I personally am not sure where the line is on noobie stuff, "we" hand them a kinda pricey board that could burst into flames, show them how to mess with mains current, then turn around and say a +/- expansion box in the IDE is too confusing for them

After all you may have scored a point :-)

Well I just don't like code folding. Let alone that regions thing which is supposed to be code folding on steroids. And let's keep ms crap out of arduino!

Ah, I feel better now... /me takes a deep breath

 ;D
593  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Be able to set a region in a defined piece of code on: July 31, 2010, 01:03:31 pm
So it seems code regions are useful in very large projects. That's just why they shouldn't be included in the Arduino IDE. For small projects, they're not so useful it seems, and Arduino is not targeted towards experienced developers who need to write thousands of lines of code (which probably wouldn't fit in the uP anyway).
Let's protect the Arduino IDE from that dreadful virus called featuritis. Advanced developers can always switch to a more advanced and featurefull editor, after all.
594  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Be able to set a region in a defined piece of code on: July 30, 2010, 01:59:30 am
If a sketch code becomes so large it needs "regions" then it's probably better broken into multiple files or better yet one or more libraries.
I don't say that regions wouldn't be handy, but IMHO they'd add complexity for newcomers without bringing in real innovation.

All of this IMHO, of course :-)
595  Forum 2005-2010 (read only) / Uno Punto Zero / Re: Real Time Operating System on: July 23, 2010, 06:33:42 pm
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1175981525
Pages: 1 ... 38 39 [40]