diff --git a/NeoPixel_GoPro_Lens_Light/NeoPixel_GoPro_Lens_Light.ino b/NeoPixel_GoPro_Lens_Light/NeoPixel_GoPro_Lens_Light.ino new file mode 100644 index 000000000..bdf7fc496 --- /dev/null +++ b/NeoPixel_GoPro_Lens_Light/NeoPixel_GoPro_Lens_Light.ino @@ -0,0 +1,38 @@ +#include +#ifdef __AVR__ + #include +#endif + +#define PIN 0 //neopixel pin + +int POT = A1; //analog pin 1 = Trinket m0 Pin 2 +int val = 0; + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) +Adafruit_NeoPixel ring = Adafruit_NeoPixel(16, PIN, NEO_RGBW + NEO_KHZ800); + +void setup() { + ring.begin(); + ring.setBrightness(255); //max brightness available for the pot + ring.show(); // Initialize all pixels to 'off' +} + +void loop() { + val = analogRead(POT); //will hold analog value sent by pot + val = map(val, 0, 1023, 0, 255); //maps analog values to digital so that it can be used by the neopixel + + uint16_t i; + + //sets all 16 pixels to on and only show level of white light defined by analog value of the pot + for (i = 0; i < ring.numPixels(); i++) { + ring.setPixelColor(i, 0, 0, 0, val); + } + ring.show(); +} \ No newline at end of file diff --git a/NeoPixel_GoPro_Lens_Light/NeoPixel_GoPro_Lens_Light.py b/NeoPixel_GoPro_Lens_Light/NeoPixel_GoPro_Lens_Light.py new file mode 100644 index 000000000..2e126a42a --- /dev/null +++ b/NeoPixel_GoPro_Lens_Light/NeoPixel_GoPro_Lens_Light.py @@ -0,0 +1,24 @@ +from analogio import AnalogIn +import board +import time +import neopixel + +pot = AnalogIn(board.A1) # what pin the pot is on +pixpin = board.D0 # what pin the LEDs are on +numpix = 16 # number of LEDs in ring! +BPP = 4 # required for RGBW ring + +ring = neopixel.NeoPixel(pixpin, numpix, bpp=BPP, brightness=1.0) + +def val(pin): + # divides voltage (65535) to get a value between 0 and 255 + return pin.value / 257 + +while True: + # Two lines for troubleshooting to see analog value in REPL + # print("A0: %f" % (pot.value / 65535 * 3.3)) + # time.sleep(1) + + # change floating point value to an int + ring.fill(0, 0, 0, int(val(pot))) + time.sleep(0.01) diff --git a/NeoPixel_GoPro_Lens_Light/README.md b/NeoPixel_GoPro_Lens_Light/README.md new file mode 100644 index 000000000..75364c954 --- /dev/null +++ b/NeoPixel_GoPro_Lens_Light/README.md @@ -0,0 +1,4 @@ +# NeoPixel GoPro Lens Light + +Code to accompany this tutorial: +https://learn.adafruit.com/neopixel-gopro-lens-light/ \ No newline at end of file