Skip to content

Commit

Permalink
Create neopixil+forceSensor
Browse files Browse the repository at this point in the history
manipulate neopixel brightness using force sensor input
  • Loading branch information
eagboola authored Jun 6, 2017
1 parent 7649f95 commit da4931c
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions neopixil+forceSensor
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);
}
}

0 comments on commit da4931c

Please sign in to comment.