Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
//add fsr
int fsrPin = A0;
int fsrReading = 0;
// add speaker
int speakerPin = D2;
int melody[] = {1908,2551,2551,2273,2551,0,2024,1908};
int noteDuration[] = {4,8,8,4,4,4,4,4 };
// add NEOPIXLE
#define PIXEL_PIN D3
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// set color
int red = 255;
int green = 255;
int blue = 255;

void setup()
{
    //neopixel start
    strip.begin();
    strip.clear();
    strip.show();
    
    // speaker start
    pinMode(speakerPin, OUTPUT);

    }


void loop()
{
    fsrReading = analogRead(fsrPin);
    if (fsrReading >= 1000){
       playNotes();    
       for(int i=10;i>0;i--){
      strip.setPixelColor(0, red/i, 0, 0);
       strip.show();
       delay(500);
       }
     strip.clear();
    }
    else if(fsrReading >= 400 && fsrReading < 2000){
        for(int i=10;i>0;i--){
       strip.setPixelColor(0, 0, green/i, blue/i);
       strip.show();
       delay(500);
        }
         strip.clear();
    }
    else if (fsrReading >= 100 ){
        for(int i=10;i>0;i--){
       strip.setPixelColor(0, red/i, green/i, blue/i);
       strip.show();
       delay(500);
        }
         strip.clear();
    }else{
        
         strip.clear();
    }
    
}

// set a tone
void playNotes()
{
    for (int note = 0; note < 8; note++){
        tone(speakerPin, melody[note], 1000/noteDuration[note]);
        int pauseBetweenNotes = 1000/noteDuration[note]*1.3;
        delay(pauseBetweenNotes);
        noTone(speakerPin);
    }
    
}
Click to Expand

Content Rating

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

0