Skip to content

Commit 3e56c9d

Browse files
committed
Adding NeoSlider code
1 parent 0db1ba2 commit 3e56c9d

5 files changed

Lines changed: 204 additions & 0 deletions

File tree

Adafruit_NeoSlider/Arduino_NeoSlider/.uno.test.only

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

Adafruit_NeoSlider/Arduino_NeoSlider_Dual/.uno.test.only

Whitespace-only changes.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* This example shows how read the potentiometer on the I2C QT Slide Potentiometer
3+
* and make the NeoPixels change too!
4+
*/
5+
6+
#include "Adafruit_seesaw.h"
7+
#include <seesaw_neopixel.h>
8+
9+
#define DEFAULT_I2C_ADDR 0x30
10+
#define ANALOGIN 18
11+
#define NEOPIXELOUT 14
12+
13+
Adafruit_seesaw seesaw1;
14+
Adafruit_seesaw seesaw2;
15+
seesaw_NeoPixel pixels1 = seesaw_NeoPixel(4, NEOPIXELOUT, NEO_GRB + NEO_KHZ800);
16+
seesaw_NeoPixel pixels2 = 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 (!seesaw1.begin(DEFAULT_I2C_ADDR) || !seesaw2.begin(DEFAULT_I2C_ADDR+1)) {
26+
Serial.println(F("seesaws not found!"));
27+
while(1) delay(10);
28+
}
29+
30+
uint16_t pid;
31+
uint8_t year, mon, day;
32+
33+
seesaw1.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 (!pixels1.begin(DEFAULT_I2C_ADDR) || !pixels2.begin(DEFAULT_I2C_ADDR+1)){
47+
Serial.println("seesaw pixels not found!");
48+
while(1) delay(10);
49+
}
50+
51+
Serial.println(F("seesaw started OK!"));
52+
53+
pixels1.setBrightness(255); // half bright
54+
pixels2.setBrightness(255); // half bright
55+
pixels1.show(); // Initialize all pixels to 'off'
56+
pixels2.show(); // Initialize all pixels to 'off'
57+
}
58+
59+
60+
61+
void loop() {
62+
// read the potentiometer
63+
uint16_t slide1_val = seesaw1.analogRead(ANALOGIN);
64+
uint16_t slide2_val = seesaw2.analogRead(ANALOGIN);
65+
Serial.print(slide1_val);
66+
Serial.print(", ");
67+
Serial.println(slide2_val);
68+
69+
for (uint8_t i=0; i< pixels1.numPixels(); i++) {
70+
pixels1.setPixelColor(i, Wheel(slide1_val / 4));
71+
pixels2.setPixelColor(i, Wheel(slide2_val / 4));
72+
}
73+
pixels1.show();
74+
pixels2.show();
75+
76+
delay(50);
77+
}
78+
79+
80+
81+
// Input a value 0 to 255 to get a color value.
82+
// The colours are a transition r - g - b - back to r.
83+
uint32_t Wheel(byte WheelPos) {
84+
WheelPos = 255 - WheelPos;
85+
if(WheelPos < 85) {
86+
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
87+
}
88+
if(WheelPos < 170) {
89+
WheelPos -= 85;
90+
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
91+
}
92+
WheelPos -= 170;
93+
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
94+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
# Fill the pixels a color based on the position of the potentiometer.
25+
pixels.fill(colorwheel(potentiometer_to_color(potentiometer.value)))

0 commit comments

Comments
 (0)