Skip to content

Commit 9caf603

Browse files
authored
Merge pull request #2537 from adafruit/propmaker_examples
Adding CP and Arduino examples for Prop-Maker Feather
2 parents 6ea5c0e + 9bf9511 commit 9caf603

File tree

6 files changed

+2574
-0
lines changed

6 files changed

+2574
-0
lines changed

RP2040_Prop-Maker_Feather_Examples/Arduino_Prop-Maker_Feather_Example/.none.test.only

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// SPDX-FileCopyrightText: 2023 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_NeoPixel.h>
6+
#include <Adafruit_LIS3DH.h>
7+
#include <Adafruit_Sensor.h>
8+
#include <Servo.h>
9+
10+
Adafruit_NeoPixel strip(60, PIN_EXTERNAL_NEOPIXELS, NEO_GRB + NEO_KHZ800);
11+
12+
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
13+
14+
Servo servo_0;
15+
16+
uint8_t x = 0;
17+
18+
void setup() {
19+
// core1 setup
20+
Serial.begin(115200);
21+
22+
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
23+
Serial.println("Couldnt start LIS3DH");
24+
while (1) yield();
25+
}
26+
27+
lis.setRange(LIS3DH_RANGE_2_G);
28+
29+
pinMode(PIN_EXTERNAL_POWER, OUTPUT);
30+
digitalWrite(PIN_EXTERNAL_POWER, HIGH);
31+
32+
strip.begin();
33+
strip.show();
34+
strip.setBrightness(50);
35+
36+
pinMode(PIN_EXTERNAL_BUTTON, INPUT_PULLUP);
37+
38+
servo_0.attach(PIN_EXTERNAL_SERVO);
39+
}
40+
41+
void loop() {
42+
43+
delay(10);
44+
x++;
45+
for(int32_t i=0; i< strip.numPixels(); i++) {
46+
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + x) & 255));
47+
}
48+
strip.show();
49+
// Print X Y & Z accelerometer data
50+
if (x % 10 == 0) {
51+
// every 100ms
52+
sensors_event_t event;
53+
lis.getEvent(&event);
54+
/* Display the results (acceleration is measured in m/s^2) */
55+
Serial.print("Accel X: "); Serial.print(event.acceleration.x);
56+
Serial.print(" \tY: "); Serial.print(event.acceleration.y);
57+
Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
58+
Serial.println(" m/s^2 ");
59+
Serial.println(x);
60+
}
61+
// external button press disable external power
62+
if (! digitalRead(PIN_EXTERNAL_BUTTON)) {
63+
Serial.println("External button pressed");
64+
digitalWrite(PIN_EXTERNAL_POWER, LOW);
65+
}
66+
else {
67+
digitalWrite(PIN_EXTERNAL_POWER, HIGH);
68+
}
69+
70+
if (x < 128) {
71+
// forward
72+
servo_0.writeMicroseconds(map(x, 0, 127, 1000, 2000));
73+
} else {
74+
// and back
75+
servo_0.writeMicroseconds(map(x-128, 0, 127, 2000, 1000));
76+
}
77+
return;
78+
79+
}
80+
81+
uint32_t Wheel(byte WheelPos) {
82+
WheelPos = 255 - WheelPos;
83+
if(WheelPos < 85) {
84+
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
85+
}
86+
if(WheelPos < 170) {
87+
WheelPos -= 85;
88+
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
89+
}
90+
WheelPos -= 170;
91+
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
92+
}
93+
94+
// audio runs on core 2!
95+
96+
#include <I2S.h>
97+
98+
#include "boot.h"
99+
#include "hithere.h"
100+
101+
struct {
102+
const uint8_t *data;
103+
uint32_t len;
104+
uint32_t rate;
105+
} sound[] = {
106+
hithereAudioData, sizeof(hithereAudioData), hithereSampleRate,
107+
bootAudioData , sizeof(bootAudioData) , bootSampleRate,
108+
};
109+
#define N_SOUNDS (sizeof(sound) / sizeof(sound[0]))
110+
111+
I2S i2s(OUTPUT);
112+
113+
uint8_t sndIdx = 0;
114+
115+
116+
void setup1(void) {
117+
i2s.setBCLK(PIN_I2S_BIT_CLOCK);
118+
i2s.setDATA(PIN_I2S_DATA);
119+
i2s.setBitsPerSample(16);
120+
}
121+
122+
void loop1() {
123+
Serial.printf("Core #2 Playing audio clip #%d\n", sndIdx);
124+
play_i2s(sound[sndIdx].data, sound[sndIdx].len, sound[sndIdx].rate);
125+
delay(5000);
126+
if(++sndIdx >= N_SOUNDS) sndIdx = 0;
127+
}
128+
129+
void play_i2s(const uint8_t *data, uint32_t len, uint32_t rate) {
130+
131+
// start I2S at the sample rate with 16-bits per sample
132+
if (!i2s.begin(rate)) {
133+
Serial.println("Failed to initialize I2S!");
134+
delay(500);
135+
i2s.end();
136+
return;
137+
}
138+
139+
for(uint32_t i=0; i<len; i++) {
140+
uint16_t sample = (uint16_t)data[i] * 32;
141+
// write the same sample twice, once for left and once for the right channel
142+
i2s.write(sample);
143+
i2s.write(sample);
144+
}
145+
i2s.end();
146+
}

0 commit comments

Comments
 (0)