I will be maintaining my libraries here:
http://bit.ly/pATDBi

I am the lead developer for libraries 
that ship with the Wiring distribution. 
As per version 1.0 -
Wiring will support Arduino boards.
You are welcome to check it out!
http://wiring.org.co/download/
LED Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com


Navigation


Current version

1.2 2009-05-07: Added blink()


History

1.2 2009-05-07: Added blink()
1.1 2009-04-07: Altered API
1.0 2008-10-23: Initial Release


Description

LED is a library for the Arduino.

It is created to help Hardware Abstraction, and readability of code. It hides the pinMode, and digitalRead calls for the user.

LED library is part of the Hardware Abstraction libraries.


Download, install and import

Download here: Attach:LED.zip

NOTE: Updated version for Arduino1.0x can be found here: http://arduino-info.wikispaces.com/HAL-LibrariesUpdates 2/13 terry@yourduino.com

Put the LED folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->LED".
Once the library is imported, an "#include <LED.h>" line will appear at the top of your Sketch.


Creation

LED(byte ledPin)

LED led = LED(13);

Initializes an LED object at a digital pin 13.


Functions

bool getState()

Returns the current state of the LED. true == on()

void on()

Set led on, calls digitalWrite(pin,HIGH) and sets state=true

void off()

Set led on, calls digitalWrite(pin,LOW) and sets state=false

void toggle()

Toggle state and call on() or off()

void blink(unsigned int time, byte times)

Will halt program execution for time milliseconds. And over that period of time blink the LED times times.

void setValue(byte val)

Assumes a PWM pin, and trigger a analogWrite()

void fadeIn(unsigned int time)

Assumes a PWM pin and fades in. Speed is determined using time. Time is measured in milliseconds.

void fadeOut(unsigned int time)

Assumes a PWM pin and fades out. Speed is determined using time. Time is measured in milliseconds.


Example

  1. /*
  2. ||
  3. || @file Blink.pde
  4. || @version 1.1
  5. || @author Alexander Brevig
  6. || @contact alexanderbrevig@gmail.com
  7. ||
  8. || @description
  9. || | Display the intuitive way of blinking an LED when using this Hardware Abstraction Library
  10. || #
  11. ||
  12. || @license
  13. || | Copyright (c) 2009 Alexander Brevig. All rights reserved.
  14. || | This code is subject to AlphaLicence.txt
  15. || | alphabeta.alexanderbrevig.com/AlphaLicense.txt
  16. || #
  17. ||
  18. */
  19.  
  20. #include <LED.h>
  21.  
  22. //create a LED object at digital pin 13
  23. LED led = LED(13);
  24.  
  25. void setup(){/*no setup required*/}
  26.  
  27. void loop(){
  28.   led.blink(2000);//on a second, off a second
  29. }


FAQ

How can I use multiple LEDs?

LED is a class. Therefore to LED multiple digital pins, you must create an instance for each of them. In the example above, a LED instance (called led) for pin 13 is created with the following line:

LED led = LED(13);

To LED an additional pin (pin 4 for example), you could create the following instance called led2:

LED led2 = LED(4);

And now it's just to call the functions you need on the LED you are interested in:

//update LEDs
  led.on();
  led2.toggle();

You can also create an array of instances for a class. Lets do this for pins 8-12:

//create array of LED instances
LED led[5] = {LED(8), LED(9), LED(10), LED(11), LED(12)}; 

And now a for loop can be used to iterate through the array:

 // turn each instance in the array on in setup()
for(int i=0; i<5; i++) { 
  led[i].on();
}

// toggle each instance in the array in loop()
for(int i=0; i<5; i++) {
  led[i].toggle();
  delay(200);
}


Information about this page

Part of AlphaBeta Libraries.
Last Modified: February 07, 2013, at 10:37 PM
By: terryking228

Share