Skill Dev V

Made by Felicia Luo and Donner Kahl

Connecting two Neopixels through webhooks.

Created: December 18th, 2022

0

Outcome

0

Process

  • I first coded up to locally control my Neopixels to light up in sequence when I pressed the button, and turn off when I released the button. And then I tried to publish an event to Particle cloud when the button was pressed. And lastly, I subscribed to Donner's event through webhooks, and call the function to blink the Neopixel when he published an event.

0

Reflection

  • Code and testing step by step has been proven very helpful in several lab practices. I will continue to do so. Setting up webhooks also has been straightforward following instructions, and is very helpful to our final project as well.
  • I wonder if I could get away with the variable bool doBlink and the function void blinkNP , and instead just call code the blinking part in function void handleBlinkNP.

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

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


bool doBlink = false;


// Our button wired to D3
int buttonPin = D3;

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

    pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
	
	// blink the LED when the setup is complete
    blinkNP();
    
    // subscribe to Donner
    Particle.subscribe( "Donner_to_Felicia", handleBlinkNP );


}

void loop()
{
  // find out if the button is pushed
  // or not by reading from it.
    int buttonState = digitalRead( buttonPin );
    // set up NP pixel num and color constants
    uint16_t i;
    // NP on - white
    uint32_t w = strip.Color(255, 255, 255);
    // NP off
    uint32_t b = strip.Color(0, 0, 0);

  // 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 NP on or off

  if( buttonState == LOW )
  {
    // turn the NP On
    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, w );
		strip.show();
		delay( 100 );
    }
    // publish event
    Particle.publish( "Felicia_to_Donner" );
    
  }else{
    // otherwise
    // turn the NP Off
    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, b );
		strip.show();
		delay( 100 );
  }

  }
	delay( 100 );
	
	// blinking
	if( doBlink == true ){
    blinkNP();
    doBlink = false;
    }

}

void blinkNP(){
    
    // set up NP pixel num and color constants
    uint16_t i;
    // NP on - white
    uint32_t w = strip.Color(255, 255, 255);
    // NP off
    uint32_t b = strip.Color(0, 0, 0);
    

    
    for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, w );
	strip.show();
// 	delay( 100 );
    }
    
    delay(500);
        
    for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, b );
	strip.show();
    // delay( 100 );
    }
    
    delay(500);

}


void handleBlinkNP(const char *event, const char *data){
    doBlink = true;
    
}
Click to Expand
x
Share this Project

Courses

About

Connecting two Neopixels through webhooks.