Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created December 15, 2023 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenschr/dc00562bd362294e3faa5fc923077282 to your computer and use it in GitHub Desktop.
Save jenschr/dc00562bd362294e3faa5fc923077282 to your computer and use it in GitHub Desktop.
/*********************************************************
Minimal example for LTR329ALS sensor for LectureFeather
*********************************************************/
#include "Adafruit_LTR329_LTR303.h"
#include <Adafruit_DotStar.h>
Adafruit_LTR329 ltr = Adafruit_LTR329();
// There is only one pixel on the board
#define NUMPIXELS 1
// Use these pin definitions for the LectureFeather ESP32-S3
#define DATAPIN 33
#define CLOCKPIN 21
// This is the instance of the Dotstar class that is controlling the RGB LED
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BGR);
void setup() {
Serial.begin(115200);
strip.begin(); // Initialize LED pins for output
strip.setBrightness(20); // Avoid blinding yourself
strip.setPixelColor(0, 10, 0, 0); // green only
strip.show(); // Turn all LEDs off ASAP
if ( ! ltr.begin() ) {
Serial.println("Couldn't find LTR sensor!");
while (1) delay(10);
}
// Setup LTR sensor (see advanced demo in library for all options!)
Serial.println("Found LTR sensor!");
ltr.setGain(LTR3XX_GAIN_4);
ltr.setIntegrationTime(LTR3XX_INTEGTIME_50);
ltr.setMeasurementRate(LTR3XX_MEASRATE_50);
}
void loop() {
uint16_t visible_plus_ir, infrared;
if (ltr.newDataAvailable()) {
bool valid = ltr.readBothChannels(visible_plus_ir, infrared);
if (valid) {
Serial.print("CH0 Visible + IR: ");
Serial.print(visible_plus_ir);
Serial.print("\tCH1 Infrared: ");
Serial.println(infrared);
}
}
// if you don't do much in a loop, always take a small break
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment