-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manipulate neopixel brightness using force sensor input
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* This is a minimal example, see extra-examples.cpp for a version | ||
* with more explantory documentation, example routines, how to | ||
* hook up your pixels and all of the pixel types that are supported. | ||
* | ||
*/ | ||
|
||
#include "Particle.h" | ||
#include "neopixel.h" | ||
|
||
SYSTEM_MODE(AUTOMATIC); | ||
|
||
// IMPORTANT: Set pixel COUNT, PIN and TYPE | ||
#define PIXEL_PIN D0 | ||
#define PIXEL_COUNT 4 | ||
#define PIXEL_TYPE WS2812B | ||
|
||
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); | ||
|
||
int analogVal = 0; | ||
int analogValMapped = 0; | ||
int counter = 0; | ||
|
||
// Prototypes for local build, ok to leave in for Build IDE | ||
void rainbow(uint8_t wait); | ||
uint32_t Wheel(byte WheelPos); | ||
|
||
void setup() | ||
{ | ||
strip.begin(); | ||
strip.show(); // Initialize all pixels to 'off' | ||
} | ||
|
||
void loop() { | ||
analogVal = analogRead(0); | ||
analogValMapped = map(analogVal, 0, 4095, 10, 255); | ||
strip.setBrightness(analogValMapped); | ||
Particle.publish("Force Value", analogValMapped); | ||
|
||
rainbow(24); | ||
|
||
} | ||
|
||
/* | ||
ORIGINAL NEOPIXEL RAINBOW METHOD | ||
void rainbow(uint8_t wait) { | ||
uint16_t i, j; | ||
|
||
for(j=0; j<256; j++) { | ||
for(i=0; i<strip.numPixels(); i++) { | ||
strip.setPixelColor(i, Wheel((i+j) & 255)); | ||
} | ||
strip.show(); | ||
delay(wait); | ||
} | ||
} */ | ||
|
||
void rainbow(uint8_t wait) { | ||
counter++; | ||
int j = counter%255; | ||
for(int i =0; i<strip.numPixels(); i++) { | ||
strip.setPixelColor(i, Wheel((i+j) & 255)); | ||
} | ||
strip.show(); | ||
delay(wait); | ||
|
||
} | ||
|
||
// Input a value 0 to 255 to get a color value. | ||
// The colours are a transition r - g - b - back to r. | ||
uint32_t Wheel(byte WheelPos) { | ||
if(WheelPos < 85) { | ||
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | ||
} else if(WheelPos < 170) { | ||
WheelPos -= 85; | ||
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); | ||
} else { | ||
WheelPos -= 170; | ||
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); | ||
} | ||
} |