// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 1
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// Define a pin that we'll place the FSR on
// Remember to add a 10K Ohm pull-down resistor too.
int redValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255</td>
int flexPin = A0;
// Create a variable to hold the FSR reading
int flexReading;
// Our button wired to D0
int buttonPin = D3;
// Define a pin we'll place an LED on
int ledPin = D2;
// Create a variable to store the LED brightness.
int ledBrightness = 0;
// Our button wired to D0
int buttonPin = D3;
void setup() {
// Set up the LED for output
pinMode(ledPin, OUTPUT);
pinMode(PIXEL_PIN, OUTPUT);
// Create a cloud variable of type integer
// called 'light' mapped to photoCellReading
Particle.variable("force", &flexReading, INT);
strip.begin();
pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
// We also want to use the LED
pinMode( ledPin , OUTPUT ); // sets pin as output
}
void loop() {
// Use analogRead to read from the sensor
// This gives us a value from 0 to 4095
flexReading = analogRead(flexPin);
// Map this value into the PWM range (0-255)
// and store as the led brightness
ledBrightness = map(flexReading, 0, 160, 0, 255);
setRGBColor( ledBrightness,0,(256 - ledBrightness));
// fade the LED to the desired brightness
analogWrite(ledPin, ledBrightness);
// wait 1/10th of a second and then loop
delay(100);
// // First... On
// digitalWrite(ledPin, HIGH); // Turn ON the LED pins
// delay(500); // Wait for 1000mS = 1 second
// // Now... Off
// digitalWrite(ledPin, LOW); // Turn OFF the LED pins
// delay(3000); // Wait for 1000mS = 1 second
// // rinse + repeat
// find out if the button is pushed
// or not by reading from it.
int buttonState = digitalRead( buttonPin );
// remember that we have wired the pushbutton to
// ground and are using a pulldown resistor
// that means, when the button is pushed,
// we will get a LOW signal
// when the button is not pushed we'll get a HIGH
// let's use that to set our LED on or off
if( buttonState == LOW )
{
// turn the LED On
digitalWrite( ledPin, HIGH);
}else{
// otherwise
// turn the LED Off
digitalWrite( ledPin, LOW);
}
}
void setRGBColor( int r, int g, int b ){
redValue = r;
greenValue = g;
blueValue = b;
strip.setPixelColor(0, redValue, greenValue, blueValue);
strip.show();
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .