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.

mihulich

Member Since 01 Apr 2013
Offline Last Active Apr 02 2013 05:13 PM
-----

Topics I've Started

Simple timer

01 April 2013 - 04:36 PM

Please, be kind! Here is another topic "Netduino Timers", but there is no usefull information for me. I need to measure a friquency of incoming impulses, so i decided to use timers and interrupts. I want to start a timer with first interrupt from a sensor and then stop this timer with a second interrupt. In TimerCallback I wanted to add 1 with every timer tick. But do not understand how to start and stop a timer with the same event! Help me please.. At fist i want to test it with button interrupt, but it does not work correctly( The second interrupt does not work and timer ticks constantly :mellow:

My code:

 

namespace Timer_testing_LED{    public class Program    {        private static Timer oneHerzTimer = null;        private static OutputPort LED = null;        private static InterruptPort button = null;        public static int i = 0;        public static int j = 0;        public static void Main()        {            LED = new OutputPort(Pins.ONBOARD_LED, false);            button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelHigh);            button.OnInterrupt += new NativeEventHandler(button_Interrupt_Event);            //timerEvent = new TimerCallback(TimerInterrupt);            while (j < 2)            {                if (j > 0)                {                    oneHerzTimer = new Timer(new TimerCallback((object data) =>                    {                        i++;                        LED.Write(!LED.Read());                    })                        , null, 100, 500);                    Thread.Sleep(Timeout.Infinite);                }            }        }        private static void TimerInterrupt(object state)        {            i++;            //LED.Write(!LED.Read());        }        private static void button_Interrupt_Event(uint data1, uint data2, System.DateTime time)        {            if (j > 0)            {                oneHerzTimer.Dispose();                oneHerzTimer = null;                for (int k = 0; k <= (i / 2); k++)                {                    LED.Write(true);                    Thread.Sleep(50);                    LED.Write(false);                    Thread.Sleep(350);                }            }            j = 2;        }    }}

 

 

 


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.