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

Select LED by integer using a generic c# method

c#

  • Please log in to reply
3 replies to this topic

#1 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 12 January 2013 - 07:36 AM

I have some variables like

  public static IGPOPort LED1; // Third 595 Chip control LEDS   public static IGPOPort LED2;   public static IGPOPort LED3;   public static IGPOPort LED4;   public static IGPOPort LED5;   public static IGPOPort LED6;   public static IGPOPort LED7;   public static IGPOPort LED8;

 

I want to create a method like the follwing..

 

SwitchLED(int LEDNo,bool On)

{

  (LED + LEDNo).Write(On); //i know this doesn't work but hopping this will explain what i am trying to achieve

}

 

Any other suggestion or variation on solution would be great?


tony


#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 12 January 2013 - 08:04 AM

Hello.

Keep the LEDs definition as you have written above. Just define an array of IGPOPort, then you'll be able to do what you want:

 

 

 

static IGPOPort[] _ports = new []{  LED1,  LED2,  LED3,  // etc};SwitchLED(int LEDNo,bool On){    _ports[LEDno].Write(On); //i know this doesn't work but hopping this will explain what i am trying to achieve}

 

 

Cheers

Biggest fault of Netduino? It runs by electricity.

#3 Nevyn

Nevyn

    Advanced Member

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

Posted 12 January 2013 - 09:10 AM

I want to create a method like the follwing..


SwitchLED(int LEDNo,bool On)
{
  (LED + LEDNo).Write(On); //i know this doesn't work but hopping this will explain what i am trying to achieve
}

 

Any other suggestion or variation on solution would be great?

 

You could always try overloading the [] operator.  You can find an example of this in this post.

 

Regards,

Mark

 

Edit: fixed some formatting.


Edited by Nevyn, 12 January 2013 - 09:12 AM.

To be or not to be = 0xFF

 

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

Follow @nevynuk on Twitter


#4 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 12 January 2013 - 12:32 PM

Mark..could you suggest how i would do this..not sure how i would use your approach.


tony






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.