Skip to content

Commit

Permalink
Merge pull request #2957 from FoamyGuy/sparkle_motion_examples
Browse files Browse the repository at this point in the history
sparkle motion examples
  • Loading branch information
FoamyGuy authored Jan 28, 2025
2 parents c9f2d95 + 69ff3b8 commit 7a43be2
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include <Arduino.h>
#include "ESP_I2S.h"

// I2S pin definitions for Sparklemotion
const uint8_t I2S_SCK = 26; // BCLK
const uint8_t I2S_WS = 33; // LRCLK
const uint8_t I2S_DIN = 25; // DATA_IN

// Create I2S instance
I2SClass i2s;

void setup() {
// Fast serial for plotting
Serial.begin(500000);

// Initialize I2S
i2s.setPins(I2S_SCK, I2S_WS, -1, I2S_DIN);
if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO, I2S_STD_SLOT_LEFT)) {
Serial.println("Failed to initialize I2S bus!");
return;
}

Serial.println("I2S Mic Plotter Ready");
}

void loop() {
static uint32_t lastPlot = 0;

// Get a sample
int32_t sample = i2s.read();

// Only plot every 1ms (1000 samples/sec is plenty for visualization)
if (millis() - lastPlot >= 1) {
if (sample >= 0) { // Valid sample
// Plot both raw and absolute values
Serial.printf("%d,%d\n", (int16_t)sample, abs((int16_t)sample));
}
lastPlot = millis();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include <Adafruit_NeoPixel.h>

#define BLOCK_1 21
#define BLOCK_2 22
#define NUM_PIXELS 8

Adafruit_NeoPixel STRIP_1(NUM_PIXELS, BLOCK_1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel STRIP_2(NUM_PIXELS, BLOCK_2, NEO_GRB + NEO_KHZ800);

void setup() {
STRIP_1.begin();
STRIP_2.begin();
STRIP_1.setBrightness(25);
STRIP_2.setBrightness(50);
}

uint16_t pixelHue_1 = 0;
uint16_t pixelHue_2 = 256;

void loop() {
pixelHue_1 += 256;
for(int i=0; i<STRIP_1.numPixels(); i++) {
int hue_1 = pixelHue_1 + (i * 65536L / STRIP_1.numPixels());
STRIP_1.setPixelColor(i, STRIP_1.gamma32(STRIP_1.ColorHSV(hue_1)));
}
STRIP_1.show();

pixelHue_2 -= 256;
for(int i=STRIP_2.numPixels(); i>-1; i--) {
int hue_2 = pixelHue_2 + (i * 65536L / STRIP_2.numPixels());
STRIP_2.setPixelColor(i, STRIP_2.gamma32(STRIP_2.ColorHSV(hue_2)));
}
STRIP_2.show();

delay(10);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Example illustrating two different LED Animations running on
Neopixels connected to 2 of the main outputs of the Sparkle Motion
"""
import board
import neopixel

from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.color import GREEN

strip1_pixel_pin = board.D21
strip2_pixel_pin = board.D22

pixel_count = 8

strip1_pixels = neopixel.NeoPixel(
strip1_pixel_pin, pixel_count, brightness=0.1, auto_write=False
)
strip2_pixels = neopixel.NeoPixel(
strip2_pixel_pin, pixel_count, brightness=0.1, auto_write=False
)

comet = Comet(strip1_pixels, speed=0.05, color=GREEN, tail_length=3, bounce=True)
rainbow = Rainbow(strip2_pixels, speed=0.05, period=3)

while True:
comet.animate()
rainbow.animate()

0 comments on commit 7a43be2

Please sign in to comment.