Skip to content

Commit 63241a8

Browse files
authored
Create potentiometer-neopixels.ino
last file
1 parent 6e2b9a6 commit 63241a8

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Read analog potentiometer on Circuit Playground Express or other board with changes
2+
// Mike Barela for Adafruit Industries 9/2018 based on
3+
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
4+
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
5+
6+
#include <Adafruit_NeoPixel.h>
7+
#ifdef __AVR__
8+
#include <avr/power.h>
9+
#endif
10+
11+
// Which pin on the microcontroller board is connected to the NeoPixels?
12+
#define PIN 8 // For Circuit Playground Express
13+
14+
// How many NeoPixels are attached to the board?
15+
#define NUMPIXELS 10
16+
17+
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
18+
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
19+
// example for more information on possible values.
20+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
21+
22+
int delayval = 500; // delay for half a second
23+
24+
void setup() {
25+
Serial.begin(9600);
26+
pixels.begin(); // This initializes the NeoPixel library.
27+
}
28+
29+
void loop() {
30+
int i; // loop variable
31+
int value; // analog read of potentiometer
32+
int display_value; // number of NeoPixels to display out of NUMPIXELS
33+
34+
// Read PIN value and scale from 0 to NUMPIXELS -1
35+
value = analogRead(A1);
36+
Serial.print(value);
37+
Serial.print(", ");
38+
display_value = int(value * NUMPIXELS / 1023);
39+
Serial.println(display_value);
40+
41+
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one
42+
43+
for(i=0; i<display_value; i++){
44+
45+
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
46+
pixels.setPixelColor(i, 0, 050, 0); // Moderately bright green color
47+
}
48+
for(i=display_value; i<NUMPIXELS; i++) {
49+
pixels.setPixelColor(i, 0, 0, 0); // turn off all pixels after value displayed
50+
}
51+
52+
pixels.show(); // This sends the updated pixel color to the hardware.
53+
54+
delay(delayval); // Delay for a period of time (in milliseconds).
55+
}

0 commit comments

Comments
 (0)