Skip to content

Commit

Permalink
Merge pull request #1 from arduino-libraries/white-led-rename
Browse files Browse the repository at this point in the history
Replace occurrences of white LED with orange LED
  • Loading branch information
sebromero authored Jun 12, 2024
2 parents e557a63 + 139fdcc commit 861ab62
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 91 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 🤖 Nicla Sense Env Arduino Library

[![Arduino Lint](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/arduino-lint.yml) [![Compile Examples](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/compile-examples.yml) [![Spell Check](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/spell-check.yml)
[![Arduino Lint](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/arduino-lint.yml)
[![Compile Examples](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/compile-examples.yml)
[![Spell Check](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/spell-check.yml)
[![API Documentation](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/render-documentation.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv/actions/workflows/render-documentation.yml)

This library contains an API to read data from the Nicla Sense Env board and control its behaviour. The board host three different sensors which can be read simultaneously: **ZMOD4410** (Indoor Air Quality), **ZMOD4510** (Outdoor Air Quality), **HS4001** (Temperature & Humidity).

Expand All @@ -9,7 +12,7 @@ This library contains an API to read data from the Nicla Sense Env board and con
This library supports the complete API exposed by the Nicla Sense Env sensor board over I2C.

- 🌈 RGB LED control
- ⚪️ White LED control
- 🟠 Orange LED control
- 💤 Board control (sleep, reset, factory reset)
- 🔧 Board configuration (e.g. changing the I2C address)
- 🏠 Indoor Air Quality Sensor control
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ void setup(){
// ...
auto rgbLED = device.rgbLED();
// ...
auto whiteLED = device.whiteLED();
auto orangeLED = device.orangeLED();
// ...
}
}
```
Once the desired object is obtained you can call functions on these objects such as `temperatureSensor.getTemperature()`. A complete list of these functions can be found in the [API documentation](./api.md).
Once the desired object is obtained you can call functions on these objects such as `temperatureSensor.temperature()`. A complete list of these functions can be found in the [API documentation](./api.md).

## 🧑‍💻 API
The API documentation can be found [here](./api.md).
Expand All @@ -43,4 +43,4 @@ The following scripts are examples of how to use the Nicla Sense Env board with
- [RGBLED.ino](../examples/RGBLED/RGBLED.ino): Demonstrates how to control the board's RGB LED.
- [TemperatureHumidity.ino](../examples/TemperatureHumidity/TemperatureHumidity.ino): Demonstrates how to read the temperature and humidity data from the board's sensors.
- [UARTRead.ino](../examples/UARTRead/UARTRead.ino): Shows how to read data from the UART port on the board when not connecting to it over I2C.
- [WhiteLED.ino](../examples/WhiteLED/WhiteLED.ino): Demonstrates how to control the board's white LED.
- [OrangeLED.ino](../examples/OrangeLED/OrangeLED.ino): Demonstrates how to control the board's orange LED.
20 changes: 10 additions & 10 deletions examples/WhiteLED/WhiteLED.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* This example shows how to control the white LED on the Nicla Sense Env board.
* This example shows how to control the orange LED on the Nicla Sense Env board.
*
* Initial author: Sebastian Romero ([email protected])
*/

#include "NiclaSenseEnv.h"

void pulseLED(WhiteLED& led) {
void pulseLED(OrangeLED& led) {
// Fade in
for (uint8_t i = 0; i < 64; ++i) {
led.setBrightness(i);
Expand All @@ -29,17 +29,17 @@ void setup() {
NiclaSenseEnv device;

if (device.begin()) {
auto whiteLED = device.whiteLED();
auto orangeLED = device.orangeLED();

Serial.print("🔢 White LED error status enabled: ");
Serial.println(whiteLED.errorStatusEnabled());
Serial.print("💡 White LED brightness: ");
Serial.println(whiteLED.brightness());
Serial.print("🔢 Orange LED error status enabled: ");
Serial.println(orangeLED.errorStatusEnabled());
Serial.print("💡 Orange LED brightness: ");
Serial.println(orangeLED.brightness());

pulseLED(whiteLED);
pulseLED(orangeLED);

// Enable sensor error indication on white LED (LED should turn off if sensors are okay)
whiteLED.setErrorStatusEnabled(true);
// Enable sensor error indication on orange LED (LED should turn off if sensors are okay)
orangeLED.setErrorStatusEnabled(true);
} else {
Serial.println("🤷 Device could not be found. Please double-check the wiring.");
}
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version=1.0.0
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Read sensor data from the Nicla Sense Env board and control the board behaviour.
paragraph=This library comes with the following features to interact with the Nicla Sense Env board: RGB LED control, White LED control, Board control (sleep, reset, factory reset), Board configuration (e.g. changing the I2C address or enabling UART CSV output), Indoor Air Quality Sensor control, Outdoor Air Quality Sensor control, Temperature/Humidity Sensor Control, UART CSV output
paragraph=This library comes with the following features to interact with the Nicla Sense Env board: RGB LED control, Orange LED control, Board control (sleep, reset, factory reset), Board configuration (e.g. changing the I2C address or enabling UART CSV output), Indoor Air Quality Sensor control, Outdoor Air Quality Sensor control, Temperature/Humidity Sensor Control, UART CSV output
category=Device Control
url=https://github.com/arduino-libraries/Arduino_NiclaSenseEnv
architectures=samd,mbed_portenta,renesas_portenta,renesas_uno,mbed_nicla,esp32,mbed_nano
Expand Down
14 changes: 7 additions & 7 deletions src/NiclaSenseEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ RGBLED& NiclaSenseEnv::rgbLED() {
return *rgbLed;
}

WhiteLED& NiclaSenseEnv::whiteLED() {
if (!whiteLed) {
whiteLed = new WhiteLED(this->bus, this->i2cDeviceAddress);
OrangeLED& NiclaSenseEnv::orangeLED() {
if (!orangeLed) {
orangeLed = new OrangeLED(this->bus, this->i2cDeviceAddress);
}
return *whiteLed;
return *orangeLed;
}

void NiclaSenseEnv::end() {
Expand All @@ -67,9 +67,9 @@ void NiclaSenseEnv::end() {
delete rgbLed;
rgbLed = nullptr;
}
if (whiteLed) {
delete whiteLed;
whiteLed = nullptr;
if (orangeLed) {
delete orangeLed;
orangeLed = nullptr;
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/NiclaSenseEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "IndoorAirQualitySensor.h"
#include "OutdoorAirQualitySensor.h"
#include "RGBLED.h"
#include "WhiteLED.h"
#include "OrangeLED.h"

/**
* @brief The NiclaSenseEnv class represents a NiclaSenseEnv device.
Expand Down Expand Up @@ -69,11 +69,11 @@ class NiclaSenseEnv : public I2CDevice {
RGBLED& rgbLED();

/**
* @brief Returns a reference to the WhiteLED object to interact with the white LED.
* @brief Returns a reference to the OrangeLED object to interact with the orange LED.
*
* @return WhiteLED& Reference to the WhiteLED object.
* @return OrangeLED& Reference to the OrangeLED object.
*/
WhiteLED& whiteLED();
OrangeLED& orangeLED();

/**
* @brief Ends the operation of the NiclaSenseEnv class.
Expand All @@ -97,8 +97,8 @@ class NiclaSenseEnv : public I2CDevice {
* - Indoor air quality sensor mode
* - Outdoor air quality sensor mode
* - Temperature sensor enabled
* - White LED brightness
* - White LED error status enabled
* - Orange LED brightness
* - Orange LED error status enabled
* - RGB LED brightness
* - RGB LED color
*
Expand Down Expand Up @@ -250,7 +250,7 @@ class NiclaSenseEnv : public I2CDevice {
IndoorAirQualitySensor* indoorAirQualitySensorInstance = nullptr;
OutdoorAirQualitySensor* outdoorAirQualitySensorInstance = nullptr;
RGBLED* rgbLed = nullptr;
WhiteLED* whiteLed = nullptr;
OrangeLED* orangeLed = nullptr;
};

#endif
18 changes: 9 additions & 9 deletions src/WhiteLED.cpp → src/OrangeLED.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "WhiteLED.h"
#include "OrangeLED.h"

WhiteLED::WhiteLED(TwoWire& bus, uint8_t deviceAddress) : I2CDevice(bus, deviceAddress) {}
OrangeLED::OrangeLED(TwoWire& bus, uint8_t deviceAddress) : I2CDevice(bus, deviceAddress) {}

WhiteLED::WhiteLED(uint8_t deviceAddress) : I2CDevice(deviceAddress) {}
OrangeLED::OrangeLED(uint8_t deviceAddress) : I2CDevice(deviceAddress) {}

uint8_t WhiteLED::brightness() {
// Read bits 0 - 5 from white_led register
uint8_t OrangeLED::brightness() {
// Read bits 0 - 5 from orange_led register
uint8_t data = readFromRegister<uint8_t>(WHITE_LED_REGISTER_INFO);
return data & 63;
}

void WhiteLED::setBrightness(uint8_t brightness) {
void OrangeLED::setBrightness(uint8_t brightness) {
if (brightness > 63) {
return; // Invalid brightness value
}
Expand All @@ -20,13 +20,13 @@ void WhiteLED::setBrightness(uint8_t brightness) {
writeToRegister<uint8_t>(WHITE_LED_REGISTER_INFO, (currentRegisterData & ~63) | brightness);
}

bool WhiteLED::errorStatusEnabled() {
// Read bit 7 from white_led register
bool OrangeLED::errorStatusEnabled() {
// Read bit 7 from orange_led register
uint8_t data = readFromRegister<uint8_t>(WHITE_LED_REGISTER_INFO);
return data & (1 << 7);
}

void WhiteLED::setErrorStatusEnabled(bool enabled) {
void OrangeLED::setErrorStatusEnabled(bool enabled) {
uint8_t currentRegisterData = readFromRegister<uint8_t>(WHITE_LED_REGISTER_INFO);
// Set bit 7 to 1 if enabled or 0 if disabled while keeping the other bits unchanged
writeToRegister<uint8_t>(WHITE_LED_REGISTER_INFO, (currentRegisterData & ~(1 << 7)) | (enabled << 7));
Expand Down
52 changes: 52 additions & 0 deletions src/OrangeLED.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "I2CDevice.h"

/**
* @brief Represents the orange on-board LED controlled via I2C.
*
* The OrangeLED class provides methods to control the brightness and error status of the orange LED.
* It inherits from the I2CDevice class.
*/
class OrangeLED : public I2CDevice {
public:

/**
* @brief Constructs a OrangeLED object.
*
* @param bus The I2C bus to use (default is Wire).
* @param deviceAddress The I2C device address (default is 0x21).
*/
OrangeLED(TwoWire& bus = Wire, uint8_t deviceAddress = DEFAULT_DEVICE_ADDRESS);

/**
* @brief Constructs a OrangeLED object with the specified device address.
*
* @param deviceAddress The I2C address of the OrangeLED device.
*/
OrangeLED(uint8_t deviceAddress);

/**
* Gets the brightness of the orange LED.
* @return The brightness of the orange LED. Range is 0 to 63.
*/
uint8_t brightness();

/**
* Sets the brightness of the orange LED.
* Call storeSettingsInFlash() on NiclaSenseEnv instance after changing the orange LED brightness to make the change persistent.
* @param brightness : The brightness of the orange LED. Range is 0 to 63.
*/
void setBrightness(uint8_t brightness = 63);

/**
* Determines whether the orange LED is used to indicate an error status of one of the sensors.
* @return True if the orange LED is used for error status, false otherwise.
*/
bool errorStatusEnabled();

/**
* Enables or disables the orange LED to indicate an error status of one of the sensors.
* Call storeSettingsInFlash() on NiclaSenseEnv instance after enabling/disabling the orange LED error status to make the change persistent.
* @param enabled : Whether to enable or disable the orange LED error status.
*/
void setErrorStatusEnabled(bool enabled);
};
52 changes: 0 additions & 52 deletions src/WhiteLED.h

This file was deleted.

0 comments on commit 861ab62

Please sign in to comment.