Skip to content

Commit 69ff3b8

Browse files
committed
sparkle motion examples
1 parent c9f2d95 commit 69ff3b8

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

Sparkle_Motion_Examples/Arduino_I2S_SparkleMotion/.feather_esp32_v2.test.only

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: 2025 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Arduino.h>
6+
#include "ESP_I2S.h"
7+
8+
// I2S pin definitions for Sparklemotion
9+
const uint8_t I2S_SCK = 26; // BCLK
10+
const uint8_t I2S_WS = 33; // LRCLK
11+
const uint8_t I2S_DIN = 25; // DATA_IN
12+
13+
// Create I2S instance
14+
I2SClass i2s;
15+
16+
void setup() {
17+
// Fast serial for plotting
18+
Serial.begin(500000);
19+
20+
// Initialize I2S
21+
i2s.setPins(I2S_SCK, I2S_WS, -1, I2S_DIN);
22+
if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO, I2S_STD_SLOT_LEFT)) {
23+
Serial.println("Failed to initialize I2S bus!");
24+
return;
25+
}
26+
27+
Serial.println("I2S Mic Plotter Ready");
28+
}
29+
30+
void loop() {
31+
static uint32_t lastPlot = 0;
32+
33+
// Get a sample
34+
int32_t sample = i2s.read();
35+
36+
// Only plot every 1ms (1000 samples/sec is plenty for visualization)
37+
if (millis() - lastPlot >= 1) {
38+
if (sample >= 0) { // Valid sample
39+
// Plot both raw and absolute values
40+
Serial.printf("%d,%d\n", (int16_t)sample, abs((int16_t)sample));
41+
}
42+
lastPlot = millis();
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_NeoPixel.h>
6+
7+
#define BLOCK_1 21
8+
#define BLOCK_2 22
9+
#define NUM_PIXELS 8
10+
11+
Adafruit_NeoPixel STRIP_1(NUM_PIXELS, BLOCK_1, NEO_GRB + NEO_KHZ800);
12+
Adafruit_NeoPixel STRIP_2(NUM_PIXELS, BLOCK_2, NEO_GRB + NEO_KHZ800);
13+
14+
void setup() {
15+
STRIP_1.begin();
16+
STRIP_2.begin();
17+
STRIP_1.setBrightness(25);
18+
STRIP_2.setBrightness(50);
19+
}
20+
21+
uint16_t pixelHue_1 = 0;
22+
uint16_t pixelHue_2 = 256;
23+
24+
void loop() {
25+
pixelHue_1 += 256;
26+
for(int i=0; i<STRIP_1.numPixels(); i++) {
27+
int hue_1 = pixelHue_1 + (i * 65536L / STRIP_1.numPixels());
28+
STRIP_1.setPixelColor(i, STRIP_1.gamma32(STRIP_1.ColorHSV(hue_1)));
29+
}
30+
STRIP_1.show();
31+
32+
pixelHue_2 -= 256;
33+
for(int i=STRIP_2.numPixels(); i>-1; i--) {
34+
int hue_2 = pixelHue_2 + (i * 65536L / STRIP_2.numPixels());
35+
STRIP_2.setPixelColor(i, STRIP_2.gamma32(STRIP_2.ColorHSV(hue_2)));
36+
}
37+
STRIP_2.show();
38+
39+
delay(10);
40+
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Example illustrating two different LED Animations running on
6+
Neopixels connected to 2 of the main outputs of the Sparkle Motion
7+
"""
8+
import board
9+
import neopixel
10+
11+
from adafruit_led_animation.animation.comet import Comet
12+
from adafruit_led_animation.animation.rainbow import Rainbow
13+
from adafruit_led_animation.color import GREEN
14+
15+
strip1_pixel_pin = board.D21
16+
strip2_pixel_pin = board.D22
17+
18+
pixel_count = 8
19+
20+
strip1_pixels = neopixel.NeoPixel(
21+
strip1_pixel_pin, pixel_count, brightness=0.1, auto_write=False
22+
)
23+
strip2_pixels = neopixel.NeoPixel(
24+
strip2_pixel_pin, pixel_count, brightness=0.1, auto_write=False
25+
)
26+
27+
comet = Comet(strip1_pixels, speed=0.05, color=GREEN, tail_length=3, bounce=True)
28+
rainbow = Rainbow(strip2_pixels, speed=0.05, period=3)
29+
30+
while True:
31+
comet.animate()
32+
rainbow.animate()

0 commit comments

Comments
 (0)