Skip to content

Commit

Permalink
Merge pull request #2926 from adafruit/arduino_vcnl4200
Browse files Browse the repository at this point in the history
arduino simpletest for the vcnl4200
  • Loading branch information
BlitzCityDIY authored Nov 18, 2024
2 parents b0c1fa1 + 76337d2 commit 815e584
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 28 deletions.
Empty file.
50 changes: 50 additions & 0 deletions Arduino_VCNL4200_simpletest/Arduino_VCNL4200_simpletest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include "Adafruit_VCNL4200.h"

Adafruit_VCNL4200 vcnl4200;

void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10); // wait for native USB
}

Serial.println("Adafruit VCNL4200 ALS simple test");

if (!vcnl4200.begin()) {
Serial.println("Could not find a valid VCNL4200 sensor, check wiring!");
while (1) {
delay(10);
}
}
Serial.println("VCNL4200 found!");

vcnl4200.setALSshutdown(false);
vcnl4200.setALSIntegrationTime(VCNL4200_ALS_IT_100MS);
vcnl4200.setALSPersistence(VCNL4200_ALS_PERS_2);

vcnl4200.setProxShutdown(false);
vcnl4200.setProxHD(false);
vcnl4200.setProxLEDCurrent(VCNL4200_LED_I_200MA);
vcnl4200.setProxIntegrationTime(VCNL4200_PS_IT_8T);
}

void loop() {
// Read the proximity sensor data
uint16_t proxData = vcnl4200.readProxData();
Serial.print("Prox Data: ");
Serial.println(proxData);
// Read the ambient light sensor (ALS) data
uint16_t alsData = vcnl4200.readALSdata();
Serial.print("ALS Data: ");
Serial.print(alsData);
// Read the raw white sensor data
uint16_t whiteData = vcnl4200.readWhiteData();
Serial.print(", White Data: ");
Serial.println(whiteData);

delay(100);
}
8 changes: 7 additions & 1 deletion GemmaM0_Band_Jacket/DiscoBandCamp/XYmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// XY(x,y) takes x and y coordinates and returns an LED index number,
// for use like this: leds[ XY(x,y) ] == CRGB::Red;

#include <FastLED.h>

// Parameters for width and height
const uint8_t kMatrixWidth = 24;
Expand All @@ -37,8 +38,10 @@ CRGB leds[ NUM_LEDS ];
// This code, plus the supporting 80-byte table is much smaller
// and much faster than trying to calculate the pixel ID with code.
#define LAST_VISIBLE_LED 119
uint8_t XY( uint8_t x, uint8_t y)
uint16_t XY(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
(void)width;
(void)height;
// any out of bounds address maps to the first hidden pixel
if( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
return (LAST_VISIBLE_LED + 1);
Expand Down Expand Up @@ -79,3 +82,6 @@ uint8_t XY( uint8_t x, uint8_t y)
uint8_t j = JacketTable[i];
return j;
}

// Instantiate an XYMap object
XYMap myXYMap = XYMap::constructWithUserFunction(kMatrixWidth, kMatrixHeight, XY);
34 changes: 17 additions & 17 deletions GemmaM0_Band_Jacket/DiscoBandCamp/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void threeSine() {
byte sinDistanceG = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 10 + x * 16)), 2);
byte sinDistanceB = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 11 + x * 16)), 2);

leds[XY(x, y)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB);
leds[XY(x, y, 0, 0)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB);
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ void plasma() {
for (int x = 0; x < kMatrixWidth; x++) {
for (int y = 0; y < kMatrixHeight; y++) {
byte color = sin8(sqrt(sq(((float)x - 7.5) * 10 + xOffset - 127) + sq(((float)y - 2) * 10 + yOffset - 127)) + offset);
leds[XY(x, y)] = CHSV(color, 255, 255);
leds[XY(x, y, 0, 0)] = CHSV(color, 255, 255);
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ void rider() {
brightness = 255 - brightness;
CRGB riderColor = CHSV(cycleHue, 255, brightness);
for (byte y = 0; y < kMatrixHeight; y++) {
leds[XY(x, y)] = riderColor;
leds[XY(x, y, 0, 0)] = riderColor;
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ void colorFill() {
for (byte x = 0; x < kMatrixWidth; x++) {
byte y = currentRow;
if (currentDirection == 2) y = kMatrixHeight - 1 - currentRow;
leds[XY(x, y)] = currentPalette[currentColor];
leds[XY(x, y, 0, 0)] = currentPalette[currentColor];
}
}

Expand All @@ -143,7 +143,7 @@ void colorFill() {
for (byte y = 0; y < kMatrixHeight; y++) {
byte x = currentRow;
if (currentDirection == 3) x = kMatrixWidth - 1 - currentRow;
leds[XY(x, y)] = currentPalette[currentColor];
leds[XY(x, y, 0, 0)] = currentPalette[currentColor];
}
}

Expand Down Expand Up @@ -174,8 +174,8 @@ void sideRain() {

scrollArray(rainDir);
byte randPixel = random8(kMatrixHeight);
for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth - 1) * rainDir, y)] = CRGB::Black;
leds[XY((kMatrixWidth - 1)*rainDir, randPixel)] = CHSV(cycleHue, 255, 255);
for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth - 1) * rainDir, y, 0, 0)] = CRGB::Black;
leds[XY((kMatrixWidth - 1)*rainDir, randPixel, 0, 0)] = CHSV(cycleHue, 255, 255);

}

Expand All @@ -194,7 +194,7 @@ void confetti() {

// scatter random colored pixels at several random coordinates
for (byte i = 0; i < 4; i++) {
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(currentPalette, random16(255), 255); //CHSV(random16(255), 255, 255);
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight), 0, 0)] = ColorFromPalette(currentPalette, random16(255), 255); //CHSV(random16(255), 255, 255);
random16_add_entropy(1);
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ void myConfetti() {

// scatter random colored pixels at several random coordinates
for (byte i = 0; i < 4; i++) {
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(MyColors_p, random16(255), 255); //CHSV(random16(255), 255, 255);
leds[XY(random16(kMatrixWidth), random16(kMatrixHeight), 0, 0)] = ColorFromPalette(MyColors_p, random16(255), 255); //CHSV(random16(255), 255, 255);
random16_add_entropy(1);
}

Expand Down Expand Up @@ -263,7 +263,7 @@ void slantBars() {

for (byte x = 0; x < kMatrixWidth; x++) {
for (byte y = 0; y < kMatrixHeight; y++) {
leds[XY(x, y)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
leds[XY(x, y, 0, 0)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
}
}

Expand All @@ -286,7 +286,7 @@ void swirly()
// blur it repeatedly. Since the blurring is 'lossy', there's
// an automatic trend toward black -- by design.
uint8_t blurAmount = beatsin8(2,10,255);
blur2d( leds, kMatrixWidth, kMatrixHeight, blurAmount);
blur2d(leds, kMatrixWidth, kMatrixHeight, blurAmount, myXYMap);

// Use two out-of-sync sine waves
uint8_t i = beatsin8( 27, kBorderWidth, kMatrixHeight-kBorderWidth);
Expand All @@ -297,12 +297,12 @@ void swirly()

// The color of each point shifts over time, each at a different speed.
uint16_t ms = millis();
leds[XY( i, j)] += CHSV( ms / 11, 200, 255);
leds[XY( j, i)] += CHSV( ms / 13, 200, 255);
leds[XY(ni,nj)] += CHSV( ms / 17, 200, 255);
leds[XY(nj,ni)] += CHSV( ms / 29, 200, 255);
leds[XY( i,nj)] += CHSV( ms / 37, 200, 255);
leds[XY(ni, j)] += CHSV( ms / 41, 200, 255);
leds[XY(i, j, 0, 0)] += CHSV( ms / 11, 200, 255);
leds[XY(j, i, 0, 0)] += CHSV( ms / 13, 200, 255);
leds[XY(ni,nj, 0, 0)] += CHSV( ms / 17, 200, 255);
leds[XY(nj,ni, 0, 0)] += CHSV( ms / 29, 200, 255);
leds[XY(i,nj, 0, 0)] += CHSV( ms / 37, 200, 255);
leds[XY(ni, j, 0, 0)] += CHSV( ms / 41, 200, 255);

FastLED.show();
}
4 changes: 2 additions & 2 deletions GemmaM0_Band_Jacket/DiscoBandCamp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void scrollArray(byte scrollDir) {
}

for (byte y = 0; y < kMatrixHeight; y++) {
leds[XY(scrollX,y)] = leds[XY(scrollX + scrollDir*2 - 1,y)];
leds[XY(scrollX,y,0,0)] = leds[XY(scrollX + scrollDir*2 - 1,y,0,0)];
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ void mapNoiseToLEDsUsingPalette()
}

CRGB color = ColorFromPalette( currentPalette, index, bri);
leds[XY(i,j)] = color;
leds[XY(i,j,0,0)] = color;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void setup() {
// Forward declarations of an array of cpt-city gradient palettes, and
// a count of how many there are. The actual color palette definitions
// are at the bottom of this file.
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
extern const TProgmemRGBGradientPaletteRef gGradientPalettes[];
extern const uint8_t gGradientPaletteCount;

// Current palette number from the 'playlist' of color palettes
Expand Down Expand Up @@ -265,7 +265,7 @@ DEFINE_GRADIENT_PALETTE( bhw3_32_gp ) {
//
// This list of color palettes acts as a "playlist"; you can
// add or delete, or re-arrange as you wish.
const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
const TProgmemRGBGradientPaletteRef gGradientPalettes[] = {
bhw3_32_gp,
bhw1_01_gp,
bhw1_07_gp,
Expand All @@ -281,7 +281,7 @@ const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {

// Count of how many cpt-city gradients are defined:
const uint8_t gGradientPaletteCount =
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPaletteRef );
void loop()
{
EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
Expand Down
2 changes: 1 addition & 1 deletion library.deps
Original file line number Diff line number Diff line change
@@ -1 +1 @@
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, Adafruit LSM303DLHC, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC, Adafruit SHARP Memory Display, Adafruit SPIFlash, BSEC Software Library, WiiChuck, Adafruit DPS310, Adafruit AHTX0, RotaryEncoder, Adafruit MCP9808 Library, LSM303, Adafruit Protomatter, Adafruit IS31FL3741 Library, Sensirion I2C SCD4x, Adafruit TestBed, Bounce2, Adafruit AHRS, Adafruit DRV2605 Library, STM32duino VL53L4CD, PicoDVI - Adafruit Fork, Adafruit MMA8451 Library, Adafruit TSC2007, GFX Library for Arduino, Adafruit PyCamera Library, Adafruit ADG72x, Adafruit BNO055, Adafruit SHT4x Library
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, Adafruit LSM303DLHC, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC, Adafruit SHARP Memory Display, Adafruit SPIFlash, BSEC Software Library, WiiChuck, Adafruit DPS310, Adafruit AHTX0, RotaryEncoder, Adafruit MCP9808 Library, LSM303, Adafruit Protomatter, Adafruit IS31FL3741 Library, Sensirion I2C SCD4x, Adafruit TestBed, Bounce2, Adafruit AHRS, Adafruit DRV2605 Library, STM32duino VL53L4CD, PicoDVI - Adafruit Fork, Adafruit MMA8451 Library, Adafruit TSC2007, GFX Library for Arduino, Adafruit PyCamera Library, Adafruit ADG72x, Adafruit BNO055, Adafruit SHT4x Library, Adafruit VCNL4200 Library
7 changes: 3 additions & 4 deletions simple_strand_palettes/simple_strand_palettes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void setup() {
// Forward declarations of an array of cpt-city gradient palettes, and
// a count of how many there are. The actual color palette definitions
// are at the bottom of this file.
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
extern const TProgmemRGBGradientPaletteRef gGradientPalettes[];
extern const uint8_t gGradientPaletteCount;

// Current palette number from the 'playlist' of color palettes
Expand Down Expand Up @@ -618,7 +618,7 @@ DEFINE_GRADIENT_PALETTE( bhw1_28_gp ) {
//
// This list of color palettes acts as a "playlist"; you can
// add or delete, or re-arrange as you wish.
const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
const TProgmemRGBGradientPaletteRef gGradientPalettes[] = {
bhw1_28_gp,
Sunset_Real_gp,
es_rivendell_15_gp,
Expand Down Expand Up @@ -657,7 +657,7 @@ const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {

// Count of how many cpt-city gradients are defined:
const uint8_t gGradientPaletteCount =
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPaletteRef );



Expand All @@ -677,4 +677,3 @@ const uint8_t gGradientPaletteCount =
FastLED.show();
FastLED.delay(20);
}

0 comments on commit 815e584

Please sign in to comment.