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

Sub routines with LED flash

sub routine subroutine

  • Please log in to reply
1 reply to this topic

#1 vader7071

vader7071

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationDothan, AL

Posted 04 October 2016 - 01:15 AM

Here is the issue I have,  I am using a Netduino 1 to control (4) LEDs.

 

I need each LED to flash at a different rate.

 

Below is the code I have created so far.

 

Here is my issue.  The brth() Thread.sleep(x) seems to be controlling everything.  I need to run each of these subs independently so if I adjust brth() it won't affect tLed(), mLed(), or bLed(), or where none of the others affect each other.

The bottom line question. What did I do wrong?

 

Thank you in advance for your help.

Oh, forgot to mention the bad news.  I need this working in 2 days.  Yeah.  I just had this idea.  I'm an idiot.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
 
namespace VaderChestBox
{
  public class Program
  {
    // Variables
 
    //Digital Inputs
 
    //Digital Outputs
    static OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D1, true);
    static OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D2, false);
    static OutputPort led3 = new OutputPort(Pins.GPIO_PIN_D3, true);
    static OutputPort breath = new OutputPort(Pins.GPIO_PIN_D4, false);
 
    //Analog Inputs
 
    //Analog Outputs
 
    public static void Main()
    {
      // write your code here
 
      while (true)
      {
        tLed();
        mLed();
        bLed();
        brth();
      }
    }
 
    public static void tLed()
    {
      // flash Top LED (LED1).  1.5 second cycle 50% duty.
      led1.Write(!led1.Read());
      Thread.Sleep(750);
    }
 
    public static void mLed()
    {
      // flash Middle LED (LED2).  3.7 second cycle 50% duty.
      led2.Write(!led2.Read());
      Thread.Sleep(1850);
    }
 
    public static void bLed()
    {
      // flash Bottom LED (LED3).  2.35 second cycle 50% duty.
      led3.Write(!led3.Read());
      Thread.Sleep(1175);
    }
 
    public static void brth()
    {
      // Trigger Breath Module.  5.1 second cycle 2% duty.
      breath.Write(true);
      Thread.Sleep(100);
      breath.Write(false);
      Thread.Sleep(5000);
    }
  }
}


#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 04 October 2016 - 07:12 AM

Thought about using NETMF timers ?

 

http://blog.mark-ste...1/netmf-timers/

 

Alternatively, PWM ?

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter





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.