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

How to avoid 'static'


  • Please log in to reply
No replies to this topic

#1 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 28 September 2014 - 03:43 PM

I'm lazy, I hate typing more than I have to. As a result, I have adapted a method that avoids having to add 'static' to every function and variable, and follows the Arduino model a little closer. I insert the following code in just about every project I start.

 

I hope this prevents some carpel tunnel syndrome for someone;

namespace Junk2
{
    public class Program
    {
        bool instanceDone = false;
        DateTime lastTick;
        EncodedMotor M0;

        public static void Main()
        {
            var p = new Program();
            p.Setup();
            while (!p.instanceDone)
                p.Loop();
        }

        void Setup()
        {
            // do initialize things here

            // pwm, phA, phB, reversed
            M0 = new EncodedMotor(PWMChannels.PWM_PIN_D5, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D10, true);
 
            lastTick = DateTime.Now;
        }

        void Loop()
        {
            DateTime thisTick = DateTime.Now;
            TimeSpan dt = thisTick - lastTick;

            //.... more stuff

            Thread.Sleep(1000 / 20); // update N times per sec
            lastTick = thisTick;
        }
    }
}






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.