I will be maintaining my libraries here: https://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! https://wiring.org.co/download/
LED Library for Arduino Author: Alexander Brevig Contact: alexanderbrevig@gmail.com
1.2 2009-05-07: Added blink()
1.2 2009-05-07: Added blink()
1.1 2009-04-07: Altered API
1.0 2008-10-23: Initial Release
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 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.
LED(byte ledPin)
LED led = LED(13);
Initializes an LED object at a digital pin 13.
Returns the current state of the LED. true == on()
Set led on, calls digitalWrite(pin,HIGH) and sets state=true
Set led on, calls digitalWrite(pin,LOW) and sets state=false
Toggle state and call on() or off()
Will halt program execution for time milliseconds. And over that period of time blink the LED times times.
Assumes a PWM pin, and trigger a analogWrite()
Assumes a PWM pin and fades in. Speed is determined using time. Time is measured in milliseconds.
Assumes a PWM pin and fades out. Speed is determined using time. Time is measured in milliseconds.
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); }
Part of AlphaBeta Libraries. | |
Last Modified: | February 07, 2013, at 10:37 PM |
By: | terryking228 |