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.

Matthias Thiele

Member Since 24 Oct 2010
Offline Last Active Jan 19 2011 06:46 PM
-----

Topics I've Started

My first Netduino project

26 October 2010 - 07:58 PM

Hi,

I am new to the Netduino and I would like to share my first projet: a class for a rotary encoder (e.g. from Alps STEC 12E8). It might be useful for a radio-volume controls or the selection of menu entries. The example adapts the blinking LED example and changes the blink time by the encoder.

All you have to do is to connect the two encoder lines and the switch with three Netduino input ports and create a "RotaryEncoder" object. Register an event handler for the switch or the rotation and you are ready.

            rot = new RotaryEncoder(Pins.GPIO_PIN_D13, Pins.GPIO_PIN_D11, Pins.GPIO_PIN_D12);
            rot.setPosition(100);
            rot.setRange(1, 1000);
            rot.setFullCycleMode();
            rot.OnMove += button_OnMove;

            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            while (true)
            {
                led.Write(true); // turn on the LED
                Thread.Sleep(i); // sleep
                led.Write(false); // turn off the LED
                Thread.Sleep(i); // sleep
            }

Of course you need an action method to do any useful work

        static void button_OnMove(uint data1, uint data2, DateTime time)
        {
            i = (int)data1;
            Debug.Print("Tick " + i + "    - Direction " + data2);
        }

The complete source code and an example is attached to this entry. I hope it will be useful for someone. I will expand it in the future with a progressive count (fast spinning will count even faster - in steps by 2, 5 or 10, slow spinning counts with the normal precision).

Bug fixes or corrections will be welcome.

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.