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

Wearable Keypad


  • Please log in to reply
9 replies to this topic

#1 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 October 2011 - 08:38 PM

Sparkfun has designed a Wearable Keypad: http://www.sparkfun.com/products/10411

Posted Image

I thought it would be nice to use this as input device for a specific project so I got one and wrote a library.

Code sample:
WearableKeypad Keypad = new WearableKeypad(Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D6);
while (true)
{
    switch (Keypad.Read())
    {
        case 1: Debug.Print("Up"); break;
        case 2: Debug.Print("Right"); break;
        case 3: Debug.Print("Down"); break;
        case 4: Debug.Print("Left"); break;
        case 5: Debug.Print("Logo"); break;
    }
    Thread.Sleep(100);
}

Or in VB.NET:
Dim Keypad As WearableKeypad = New WearableKeypad(Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D6)

Do
    Select Case Keypad.Read()
        Case 1 : Debug.Print("Up")
        Case 2 : Debug.Print("Right")
        Case 3 : Debug.Print("Down")
        Case 4 : Debug.Print("Left")
        Case 5 : Debug.Print("Logo")
    End Select

    Thread.Sleep(100)
Loop

Source code at: http://netmftoolbox.codeplex.com/
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 27 October 2011 - 03:51 AM

The auto-repeat feature would be perfect for this gadget. Just merge the sources! Cheers
Biggest fault of Netduino? It runs by electricity.

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 08:16 AM

The auto-repeat feature would be perfect for this gadget. Just merge the sources!
Cheers

Good suggestion!

I'm also considering to make the Read() return an enumerated value, for example:
public enum Buttons
{
    None = 0,
    Up = 1,
    Right = 2,
    Down = 3,
    Left = 4,
    Logo = 5
}
A bit more code, but I think it would make it easier to use.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 27 October 2011 - 09:03 AM

I'm also considering to make the Read() return an enumerated value

I wouldn't do it, because the enum is not extensible. E.g. if tomorrow you'll create the 8-ways joystick (which may be compatible), the user must change his/her code.
Cheers
Biggest fault of Netduino? It runs by electricity.

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 09:11 AM

I wouldn't do it, because the enum is not extensible. E.g. if tomorrow you'll create the 8-ways joystick (which may be compatible), the user must change his/her code.

To be honest, I hope regular joysticks use better logics. Reading a value of this keypad is not according to an existing standard I had the feeling.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 27 October 2011 - 09:38 AM

To be honest, I hope regular joysticks use better logics. Reading a value of this keypad is not according to an existing standard I had the feeling.

Great!
A good reason to wear the driver as it was a better joystick!
Biggest fault of Netduino? It runs by electricity.

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 09:45 AM

Great!
A good reason to wear the driver as it was a better joystick!

I mean, look at the datasheet. It doesn't use a common method to read the device as far as I know. I'm not speaking about the software but the hardware :)
If I would have designed the hardware, and wanted to read 5 buttons over 3 pins, I would use a binary mode (0 to 7 = 000 to 111). That way, a reading could be done much faster.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 27 October 2011 - 09:52 AM

I mean, look at the datasheet. It doesn't use a common method to read the device as far as I know. I'm not speaking about the software but the hardware :)
If I would have designed the hardware, and wanted to read 5 buttons over 3 pins, I would use a binary mode (0 to 7 = 000 to 111). That way, a reading could be done much faster.

Okay, but that's about the hardware, and should keep a question between this specific joystick and the related driver.

Now consider an user who's writing a game, requiring a joystick.
Other users may purchase several kind of joysticks: joypad, a set of raw buttons, analog, even a mouse. The game should require a generic IGameAdapter interface, then *any* of the proprietary driver should implement that interface.
Along this way, you may choose any game adapter you want without touching the base game. BTW, it would a nonsense task, indeed.
Cheers
Biggest fault of Netduino? It runs by electricity.

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 09:55 AM

Along this way, you may choose any game adapter you want without touching the base game. BTW, it would a nonsense task, indeed.
Cheers

Ah you mean a joystick interface. I read you ;)

Too bad this acts more as a keyboard then as a joystick; with a joystick for example it's possible to press both up and left at the same time. This uses only a single button at the same time.

But I'll stay with the numbers, it's more generic compared to my other keypad-class. Perhaps I should interface it as a keypad, which could really use your AutoRepeatInputPort code :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 xprment626

xprment626

    New Member

  • Members
  • Pip
  • 6 posts

Posted 27 October 2011 - 08:06 PM

I was also going to suggest using an Enum when I first saw this post, but originally decided against commenting. But since you mention it :-)


[Flags]
public enum Buttons
{
    None = 0,
    Up = 1,
    Right = 2,
    Down = 4,
    Left = 8,
    Select = 16
}


This would provide support for a 8 key joystick or pressing multiple keys ... or simulating 8 key joystick by pressing multiple keys. This may lack some extensibility, but given the benefit I would be inclined to be ok with that. You could make it more extensible (using generics perhaps similar to EventArgs<T>) but I think the overhead is unnecessary at this time. Alternatively, you can just provide constants for WearableKeypad which has the added benefit of readability with a smaller increase than the enum.

Just my $0.02




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.