picofuse-objc

Instance Methods | Class Methods | List of all members
NXLight Class Reference

An LED, or a chain of NeoPixels, which is turned on and off, dimmed, colored, or blinked. More...

#import <Application/Application.h>

Inheritance diagram for NXLight:
Inheritance graph
[legend]
Collaboration diagram for NXLight:
Collaboration graph
[legend]

Instance Methods

(size_t) - count
 Returns the number of LEDs, which is more than 1 for a chain of NeoPixels.
 
(void) - setBoolValue:
 Turns it on or off, or every LED of a chain, and stops a blink.
 
(void) - setBoolValue:atIndex:
 Turns an LED of a chain on or off, and stops a blink.
 
(void) - setBrightness:
 Dims it, or every LED of a chain, and stops a blink. More...
 
(void) - setBrightness:atIndex:
 Dims an LED of a chain, and stops a blink.
 
(void) - setColor:
 Colors it, or every LED of a chain, and stops a blink. More...
 
(void) - setColor:atIndex:
 Colors an LED of a chain, and stops a blink.
 
(BOOL) - blinkWithInterval:repeats:
 Blinks it, starting off, and turning on and off every interval. More...
 
(BOOL) - blinkWithInterval:repeats:atIndex:
 Blinks an LED of a chain, in its color, at full brightness. More...
 
(void) - clear
 Turns it off, or every LED of a chain, and stops a blink.
 
- Instance Methods inherited from NXObject
(void) - dealloc
 Frees the instance. More...
 
(NXZone *) - zone
 Returns the zone in which the instance was allocated. More...
 
(id) - retain
 Increases the retain count of the receiver. More...
 
(void) - release
 Decreases the retain count of the receiver. More...
 
(id) - autorelease
 Releases the receiver later, when the current autorelease pool of the thread is drained. More...
 
(id) - copy
 Returns a copy which can't be changed by anything else, which the caller owns and has to release. More...
 
(uintptr_t) - hash
 Returns a number for the object, which is the same for objects which are equal by isEqual:. More...
 
(NXString *) - description
 Returns a string which describes the instance, for logging. More...
 
- Instance Methods inherited from Object
(id) - init
 Initialize the instance, after allocation. More...
 
(Class) - class
 Returns the class of the instance. More...
 
(Class) - superclass
 Returns the superclass of the instance. More...
 
(BOOL) - isEqual:
 Compares the receiver to another object for equality. More...
 
(BOOL) - isKindOfClass:
 Returns a Boolean value that indicates whether the receiver is an instance of a given class. More...
 
(BOOL) - conformsTo:
 Checks if the receiver's class conforms to a protocol. More...
 
- Instance Methods inherited from <ObjectProtocol>
(BOOL) - respondsToSelector:
 Checks if the receiver responds to a selector. More...
 

Class Methods

(NXLight *) + default
 Returns the board's own LED. More...
 
(NXLight *) + binaryWithPin:
 Returns an LED on a pin of bank 0, which is on or off. More...
 
(NXLight *) + pwmWithPin:
 Returns an LED on a pin of bank 0 driven by PWM, which can be dimmed. More...
 
(NXLight *) + rgbWithRedPin:greenPin:bluePin:inverted:
 Returns an RGB LED on three pins of bank 0 driven by PWM, which can be colored and dimmed. More...
 
(NXLight *) + neopixelWithPin:count:
 Returns a chain of NeoPixels, or WS2812s, whose data is on a pin of bank 0. More...
 
(NXLight *) + deviceWithName:
 Returns a Linux LED device, by its name in /sys/class/leds, such as "ACT". More...
 
- Class Methods inherited from NXObject
(id) + alloc
 Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More...
 
(id) + allocWithZone:
 Allocates a new instance in a specific zone. More...
 
(id) + new
 Allocates and initializes a new instance, as [[cls alloc] init] does. More...
 
(NXString *) + description
 Returns the name of the class.
 
- Class Methods inherited from Object
(void) + initialize
 Performs one-time initialization for the class. More...
 
(Class) + class
 Returns the class object. More...
 
(Class) + superclass
 Returns the superclass of the class. More...
 
(const char *) + name
 Returns the name of the class. More...
 
(BOOL) + conformsTo:
 Checks if the class conforms to a protocol. More...
 

Additional Inherited Members

- Protected Attributes inherited from Object
Class isa
 A pointer to the object's class structure. More...
 

Detailed Description

An LED, or a chain of NeoPixels, which is turned on and off, dimmed, colored, or blinked.

It's an LED of picofuse's hardware, which can be a pin which is on or off, a pin driven by PWM, which can be dimmed, an RGB LED on three pins driven by PWM, which can be colored, a chain of NeoPixels, which can each be colored, the LED of a Pico W's Wi-Fi chip, or a Linux LED device. A device can have lights of its own too, such as -[PimoroniDisplayPack light].

NXLight *light = [NXLight default];
[light setBoolValue:YES];
[light blinkWithInterval:250 * NXMillisecond repeats:YES];

Only an RGB LED and a chain of NeoPixels have colors: any other light takes a color as a brightness, from how bright the color looks, times its opacity. Only PWM, RGB and NeoPixels can be dimmed: any other light is on at any brightness but zero. An RGB LED or a NeoPixel turned on is white, and dimming one keeps its color.

A light blinks while an application which NXApplicationMain started runs, as its run loop polls picofuse's hardware, which turns it on and off. Only one blink is running for a light at a time, even for a chain of NeoPixels, and setting it, or clearing it, stops it.

Lights need picofuse's hardware to have started, which NXApplicationMain does before it makes the delegate, or hw_init() does. It's the light's from when it's made until it's deallocated, and its pins are released then.

Definition at line 40 of file NXLight.h.

Method Documentation

◆ binaryWithPin:()

+ (NXLight *) binaryWithPin: (uint8_t)  pin

Returns an LED on a pin of bank 0, which is on or off.

Returns
The light, which is off, or nil if the pin can't be an output.

◆ blinkWithInterval:repeats:()

- (BOOL) blinkWithInterval: (NXDuration)  interval
repeats: (BOOL)  repeats 

Blinks it, starting off, and turning on and off every interval.

Parameters
intervalHow long it's on, and off, for, rounded up to a millisecond.
repeatsYES to blink until it's set or cleared, or NO to turn on once, after the interval, and stay on.
Returns
YES if it blinks, or NO if the interval isn't more than zero, or it can't.

◆ blinkWithInterval:repeats:atIndex:()

- (BOOL) blinkWithInterval: (NXDuration)  interval
repeats: (BOOL)  repeats
atIndex: (size_t)  index 

Blinks an LED of a chain, in its color, at full brightness.

Only one LED of a chain blinks at a time.

◆ default()

+ (NXLight *) default

Returns the board's own LED.

Returns
The light, or nil if there's none. A Pico's is a pin, a Pico W's is its Wi-Fi chip's and a Presto's is a chain of NeoPixels. On Linux it's the device "ACT", as a Raspberry Pi names its activity LED, or else "led0", which need root, or a udev rule which gives the gpio group their files: see picofuse's README, "LEDs on Linux". A Mac has none.

◆ deviceWithName:()

+ (NXLight *) deviceWithName: (NXString *)  name

Returns a Linux LED device, by its name in /sys/class/leds, such as "ACT".

Returns
The light, or nil if there's no such device, it can't be controlled, which needs root or picofuse's udev rule, or it isn't Linux. Its trigger is set back as it was when it's deallocated.

◆ neopixelWithPin:count:()

+ (NXLight *) neopixelWithPin: (uint8_t)  pin
count: (uint8_t)  count 

Returns a chain of NeoPixels, or WS2812s, whose data is on a pin of bank 0.

Parameters
pinThe pin.
countThe number of NeoPixels in the chain, from 1.
Returns
The light, which is off, or nil if there are none, or the pin can't drive them, such as on a Mac or Linux.

◆ pwmWithPin:()

+ (NXLight *) pwmWithPin: (uint8_t)  pin

Returns an LED on a pin of bank 0 driven by PWM, which can be dimmed.

Returns
The light, which is off, or nil if the pin can't be driven by PWM.

◆ rgbWithRedPin:greenPin:bluePin:inverted:()

+ (NXLight *) rgbWithRedPin: (uint8_t)  red
greenPin: (uint8_t)  green
bluePin: (uint8_t)  blue
inverted: (BOOL)  inverted 

Returns an RGB LED on three pins of bank 0 driven by PWM, which can be colored and dimmed.

Parameters
redThe red LED's pin.
greenThe green LED's pin.
blueThe blue LED's pin.
invertedNO if a pin's LED is lit by a high output, as where they share a cathode, or YES if it's lit by a low one, as where they share an anode.
Returns
The light, which is off, or nil if a pin can't be driven by PWM, or two are the same.

◆ setBrightness:()

- (void) setBrightness: (float)  brightness

Dims it, or every LED of a chain, and stops a blink.

Parameters
brightnessFrom 0, which is off, to 1, which is full, clamped.

◆ setColor:()

- (void) setColor: (NXColor *)  color

Colors it, or every LED of a chain, and stops a blink.

Parameters
colorThe color, where nil is off.

The documentation for this class was generated from the following file: