Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

3x4 Matrix Keypad bounce problem


  • Please log in to reply
8 replies to this topic

#1 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 25 May 2013 - 06:19 PM

I'm using this keypad: http://www.adafruit.com/product/419

with the Toolbox.NETMF.Hardware.MatrixKeyPad driver and I'm getting a lot of bounce. It appears that the "time" parameter of the event handler is not working correctly. For example, in the code below, ButtonLastPushed is initially 0 and the first time the button is pushed "time" is zero also. Has anyone else run into this problem and found a fix?

/// Triggered when a key is pressedstatic void kb_OnKeyDown(uint KeyCode, uint Unused, DateTime time) {   if (ButtonLastPushed.AddMilliseconds(intBounceWait) > time) return; // prevent bounce   ButtonLastPushed = time;   Debug.Print("Key pressed: " + KeyLookup((int)KeyCode).ToString()); }


#2 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 25 May 2013 - 08:31 PM

I'd expect time to be zero when the board starts up since there's no RTC on board, or is there? After startup, clock should start ticking of course. Would that explain the phenomena you're seeing? EDIT: What is the initial value of the ButtonLastPushed variable? I guess it should be DateTime.MinValue.

#3 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 25 May 2013 - 08:53 PM

To start with I'm using the N+2. Sorry about posting in the wrong forum if this has anything to do with it.

 

The value of the "time" parameter is always 00:00:00 as if there were no clock at all on board. I don't expect the board to have the current time, just the time relative to startup. I can work around my problem with the code below, but I expected the Toolbox.NETMF.Hardware.MatrixKeyPad code to work and was wondering if anyone else had seen this problem.

static void kb_OnKeyDown(uint KeyCode, uint Unused, DateTime time){   KeyDown(KeyLookup((int)KeyCode), DateTime.Now);}// Process the keypad inputstatic void KeyDown(int KeyVal, DateTime dtTime)  {  if (ButtonLastPushed.AddMilliseconds(intBounceWait) > dtTime) return; // prevent bounce  ButtonLastPushed = dtTime;...


#4 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 25 May 2013 - 09:45 PM

I'll have to retract that last post. It does not work either. Looks like there is something wrong with the clock...



#5 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 25 May 2013 - 09:52 PM

Ok, that is truly strange. What if you just assign a variable DateTime.Now, does that produce anything other than zero? If not, could be hardware problems but one should think more stuff would also not work then so I assume you get a decent value and that would leave a firmware upgrade or you've teied that already perhaps? I don't know the differences, if any, between the N2 and NP2 with respect to such an issue, I'd suspect there's none.

#6 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 25 May 2013 - 10:16 PM

This is weird. The clock works. Debug printing .Now shows the clock incrementing. Maybe it is the keypad.



#7 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 26 May 2013 - 06:30 AM

I really doubt it's the keypad, I think you should try setting a few breakpoints in select places of the Toolbox.NETMF.Hardware.MatrixKeyPad driver code and find out where that zero originates from. There could be a bug in there or perhaps something resulting from incorrect wiring.

#8 kiodisplays

kiodisplays

    New Member

  • Members
  • Pip
  • 1 posts

Posted 07 June 2013 - 03:43 PM

It looks like the problem is in the MatrixKeyPad.cs file. I changed the following to make the time work correctly:

 

Line: 131

 

    From:    this.OnKeyDown(this._LastKeyPress, 0, [color=#0000ff;]new DateTime())[/color];

 

    To:        this.OnKeyDown(this._LastKeyPress, 0, [color=#0000ff;]DateTime.Now[/color]);

 

and

 

 

Line: 137

 

    From:    this.OnKeyUp(this._LastKeyPress, 0, [color=#0000ff;]new DateTime()[/color]);

 

    To:        this.OnKeyUp(this._LastKeyPress, 0, [color=#0000ff;]DateTime.Now[/color]);

 

That fixed my problem.

 

Cheers,

 

-Karl

 



#9 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 11 June 2013 - 01:20 PM

Thanks for the input Karl. I'll give your suggestion a try.

-Capel






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.