Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>


#define PIXEL_COUNT 1
#define PIXEL_PIN D7
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

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 photoCellPin = A0;
int fsrPin = A2;
int photoCellReading = 0;
int ledPin = D3;
int ledBrightness = 0;
int fsrReading = 0;
int ledPinRed = D4;
int ledBrightnessRed = 0;
int hit = 0;
int HIT = 0;
int number = 0;
int NUMBER = 0;
int speakerPin = D2;




void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(ledPinRed, OUTPUT);
    Particle.variable("light", &photoCellReading, INT);
    strip.begin();
    pinMode( speakerPin, OUTPUT );
}

void loop() {
    photoCellReading = analogRead(photoCellPin);
    fsrReading = analogRead(fsrPin);
    
    if( photoCellReading>600 )  
    {
        if(HIT >=3)
        {
            setRGBColor(0,0,0);
        }
        else if(NUMBER % 3 == 0)
        {
            setRGBColor(255,0,0);
        }
        else if(NUMBER % 3 == 1)
        {
            setRGBColor(0,255,0);
        }
        else 
        {
            setRGBColor(0,0,255);
        }
        
        
        if(HIT >= 3)
        {
            digitalWrite( ledPin, LOW);
            noTone(speakerPin);
        }
        else
        {
            digitalWrite( ledPin, HIGH);
            tone(speakerPin,500,50);
        }
        
    }
    else{
    digitalWrite( ledPin, LOW);
    setRGBColor(0,0,0);
    noTone(speakerPin);
    }
  
    if(fsrReading>1500)
    {
        if(NUMBER % 3 == 0)
        {
            hit=hit + 1;
            digitalWrite( ledPinRed, HIGH);
        }
        else
        {
            hit=hit - 1;
        }
    }
    else
    {
        digitalWrite( ledPinRed, LOW);
    }



    if(number==30)
    {
        number=0;
        NUMBER=NUMBER + 1;
    }
    else
    {number=number + 1;}
    
    if(hit==10)
    {
        hit=0;
        HIT=HIT + 1;
        NUMBER=NUMBER +1;
        number=0;
    }
    
    Particle.variable("HIT", &HIT, INT );
    
    delay(100);
    
    
    
}


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!

0