Back to Parent

#include <neopixel.h>                                           // This #include statement was automatically added by the Particle IDE.
    
#define PIXEL_PIN A5                                            // IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2812
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


int fsrPin = A0;                                                 // Define a pin that we'll place the FSR on. Remember to add a 10K Ohm pull-down resistor too.
int fsrReading = 0;                                             // Create a variable to hold the FSR reading
int ledPin = D2;                                                // Define a pin we'll place an LED on
int ledBrightness = 0;                                          // Create a variable to store the LED brightness.


void setup() {
    
    pinMode(ledPin, OUTPUT);                                    // Set up the LED for output

    strip.begin();
    uint32_t c = strip.Color(0, 0, 0);                          // Turn off neoPixel
    strip.show();                                               // set updates to the strip
    delay( 100 );
  
    Particle.variable("force", &fsrReading, INT);               // Create a cloud variable of type integer called 'force' mapped to flexReading
  
}

void loop(){

    int state = LOW;                                            // Turn ledPin off
    strip.begin();
    uint32_t c = strip.Color(0, 0, 0);                          // Set color to white
    for( int i = 0; i < strip.numPixels(); i++ ){               
    strip.setPixelColor(i, 0);                                  // Turn off neoPixel 
    strip.show();
    delay( 100 );
    
    } 

    fsrReading = analogRead(fsrPin);                            // Use analogRead to read from the sensor. This gives us a value from 0 to 4095
    ledBrightness = map(fsrReading, 0, 4095, 0, 255);           // Map this value into the PWM range (0-255) // Map this value into the PWM range (0-255)
    analogWrite(ledPin, ledBrightness);                         // fade the LED to the desired brightness
    delay(100);
  
  if( fsrReading > 100 && fsrReading < 500 ){
  
    uint32_t c = strip.Color( 0, 0, 255 );                      // Set color to Blue
    
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c);                               // Set a color 
        strip.show();
        delay(10 );
    
        Particle.publish("SupBae", "sent");
        delay(2000);
    }
  }else if( fsrReading > 1000 ){
  
    uint32_t c = strip.Color( 255, 0, 255 );                    // Set color to Blue
    
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c);                              // Set a color 
        strip.show();
        delay(10 );
    
        Particle.publish("LetsGo", "sent2");
        delay(2000);
    
}
}
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0