Arduino_NeoSlider_Dual.ino
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 }