Skip to content

Commit 2a77813

Browse files
authored
Merge pull request #1947 from kattni/neoslider
Adding NeoSlider example code
2 parents 0db1ba2 + da4c523 commit 2a77813

5 files changed

Lines changed: 209 additions & 0 deletions

File tree

Adafruit_NeoSlider/Arduino_NeoSlider/.uno.test.only

Whitespace-only changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
// SPDX-License-Identifier: MIT
3+
/*
4+
* This example shows how read the potentiometer on the I2C QT Slide Potentiometer
5+
* and make the NeoPixels change too!
6+
*/
7+
8+
#include "Adafruit_seesaw.h"
9+
#include <seesaw_neopixel.h>
10+
11+
#define DEFAULT_I2C_ADDR 0x30
12+
#define ANALOGIN 18
13+
#define NEOPIXELOUT 14
14+
15+
Adafruit_seesaw seesaw;
16+
seesaw_NeoPixel pixels = seesaw_NeoPixel(4, NEOPIXELOUT, NEO_GRB + NEO_KHZ800);
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
21+
//while (!Serial) delay(10); // wait until serial port is opened
22+
23+
Serial.println(F("Adafruit PID 5295 I2C QT Slide Potentiometer test!"));
24+
25+
if (!seesaw.begin(DEFAULT_I2C_ADDR)) {
26+
Serial.println(F("seesaw not found!"));
27+
while(1) delay(10);
28+
}
29+
30+
uint16_t pid;
31+
uint8_t year, mon, day;
32+
33+
seesaw.getProdDatecode(&pid, &year, &mon, &day);
34+
Serial.print("seesaw found PID: ");
35+
Serial.print(pid);
36+
Serial.print(" datecode: ");
37+
Serial.print(2000+year); Serial.print("/");
38+
Serial.print(mon); Serial.print("/");
39+
Serial.println(day);
40+
41+
if (pid != 5295) {
42+
Serial.println(F("Wrong seesaw PID"));
43+
while (1) delay(10);
44+
}
45+
46+
if (!pixels.begin(DEFAULT_I2C_ADDR)){
47+
Serial.println("seesaw pixels not found!");
48+
while(1) delay(10);
49+
}
50+
51+
Serial.println(F("seesaw started OK!"));
52+
53+
pixels.setBrightness(255); // half bright
54+
pixels.show(); // Initialize all pixels to 'off'
55+
}
56+
57+
58+
59+
void loop() {
60+
// read the potentiometer
61+
uint16_t slide_val = seesaw.analogRead(ANALOGIN);
62+
Serial.println(slide_val);
63+
64+
for (uint8_t i=0; i< pixels.numPixels(); i++) {
65+
pixels.setPixelColor(i, Wheel(slide_val / 4));
66+
}
67+
pixels.show();
68+
69+
delay(50);
70+
}
71+
72+
73+
74+
// Input a value 0 to 255 to get a color value.
75+
// The colours are a transition r - g - b - back to r.
76+
uint32_t Wheel(byte WheelPos) {
77+
WheelPos = 255 - WheelPos;
78+
if(WheelPos < 85) {
79+
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
80+
}
81+
if(WheelPos < 170) {
82+
WheelPos -= 85;
83+
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
84+
}
85+
WheelPos -= 170;
86+
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
87+
}

Adafruit_NeoSlider/Arduino_NeoSlider_Dual/.uno.test.only

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
// SPDX-License-Identifier: MIT
3+
/*
4+
* This example shows how read the potentiometer on the I2C QT Slide Potentiometer
5+
* and make the NeoPixels change too!
6+
*/
7+
8+
#include "Adafruit_seesaw.h"
9+
#include <seesaw_neopixel.h>
10+
11+
#define DEFAULT_I2C_ADDR 0x30
12+
#define ANALOGIN 18
13+
#define NEOPIXELOUT 14
14+
15+
Adafruit_seesaw seesaw1;
16+
Adafruit_seesaw seesaw2;
17+
seesaw_NeoPixel pixels1 = seesaw_NeoPixel(4, NEOPIXELOUT, NEO_GRB + NEO_KHZ800);
18+
seesaw_NeoPixel pixels2 = seesaw_NeoPixel(4, NEOPIXELOUT, NEO_GRB + NEO_KHZ800);
19+
20+
void setup() {
21+
Serial.begin(115200);
22+
23+
//while (!Serial) delay(10); // wait until serial port is opened
24+
25+
Serial.println(F("Adafruit PID 5295 I2C QT Slide Potentiometer test!"));
26+
27+
if (!seesaw1.begin(DEFAULT_I2C_ADDR) || !seesaw2.begin(DEFAULT_I2C_ADDR+1)) {
28+
Serial.println(F("seesaws not found!"));
29+
while(1) delay(10);
30+
}
31+
32+
uint16_t pid;
33+
uint8_t year, mon, day;
34+
35+
seesaw1.getProdDatecode(&pid, &year, &mon, &day);
36+
Serial.print("seesaw found PID: ");
37+
Serial.print(pid);
38+
Serial.print(" datecode: ");
39+
Serial.print(2000+year); Serial.print("/");
40+
Serial.print(mon); Serial.print("/");
41+
Serial.println(day);
42+
43+
if (pid != 5295) {
44+
Serial.println(F("Wrong seesaw PID"));
45+
while (1) delay(10);
46+
}
47+
48+
if (!pixels1.begin(DEFAULT_I2C_ADDR) || !pixels2.begin(DEFAULT_I2C_ADDR+1)){
49+
Serial.println("seesaw pixels not found!");
50+
while(1) delay(10);
51+
}
52+
53+
Serial.println(F("seesaw started OK!"));
54+
55+
pixels1.setBrightness(255); // half bright
56+
pixels2.setBrightness(255); // half bright
57+
pixels1.show(); // Initialize all pixels to 'off'
58+
pixels2.show(); // Initialize all pixels to 'off'
59+
}
60+
61+
62+
63+
void loop() {
64+
// read the potentiometer
65+
uint16_t slide1_val = seesaw1.analogRead(ANALOGIN);
66+
uint16_t slide2_val = seesaw2.analogRead(ANALOGIN);
67+
Serial.print(slide1_val);
68+
Serial.print(", ");
69+
Serial.println(slide2_val);
70+
71+
for (uint8_t i=0; i< pixels1.numPixels(); i++) {
72+
pixels1.setPixelColor(i, Wheel(slide1_val / 4));
73+
pixels2.setPixelColor(i, Wheel(slide2_val / 4));
74+
}
75+
pixels1.show();
76+
pixels2.show();
77+
78+
delay(50);
79+
}
80+
81+
82+
83+
// Input a value 0 to 255 to get a color value.
84+
// The colours are a transition r - g - b - back to r.
85+
uint32_t Wheel(byte WheelPos) {
86+
WheelPos = 255 - WheelPos;
87+
if(WheelPos < 85) {
88+
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
89+
}
90+
if(WheelPos < 170) {
91+
WheelPos -= 85;
92+
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
93+
}
94+
WheelPos -= 170;
95+
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
96+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
NeoSlider NeoPixel Rainbow Demo
5+
"""
6+
import board
7+
from rainbowio import colorwheel
8+
from adafruit_seesaw.seesaw import Seesaw
9+
from adafruit_seesaw.analoginput import AnalogInput
10+
from adafruit_seesaw import neopixel
11+
12+
# NeoSlider Setup
13+
neoslider = Seesaw(board.I2C(), 0x31)
14+
potentiometer = AnalogInput(neoslider, 18)
15+
pixels = neopixel.NeoPixel(neoslider, 14, 4)
16+
17+
18+
def potentiometer_to_color(value):
19+
"""Scale the potentiometer values (0-1023) to the colorwheel values (0-255)."""
20+
return value / 1023 * 255
21+
22+
23+
while True:
24+
print(potentiometer.value)
25+
# Fill the pixels a color based on the position of the potentiometer.
26+
pixels.fill(colorwheel(potentiometer_to_color(potentiometer.value)))

0 commit comments

Comments
 (0)