0

Purpose

Our team is going to explore a common social scenario; waiting to cross the street at a stop light. We are interested in transforming what is normally a boring waste of time into a fun playful experience. Our goal is to create an augmented object to allow pedestrians to interact with other pedestrians on the other side of the street.

When waiting at the light and pressing the push-to-walk button, people are often bored and inpatient. We are going to create a gamified button instead which pedestrians can challenge each other to see who can press the button the fastest within the limited time. We believe that adding this simple tug-of-war type game will make waiting to cross the street more entertaining.

0

Process

We started with designing the game and trying different sensors. We first tried the accelerometers. We encountered some technical issues and eventually decided to use button instead.

0

We then drafted the flow of how the buttons on both sides trigger the game, how the inputs can be passed in the cloud and how to set the threshold for the game outcome.

0

Outcome

0

The game needs two sides of the pedestrians to participate. Once both people press the start button, the neopixel will light up to indicate that the game has started. Within a limited time (before the red light turns to green), they will hit the button as fast as they can and the first person reaches the threshold number will win the game. The neopicxel on the winner's side will have a flash effect and the one on the loser's side will go off.

0

Code

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

int startButtonPin = D5;
int buttonPin = D7;    
int ledPin = D2;       

int counter = 0;
int buttonState;
int startButtonState;

long lastPublishedAt = 0;
int publishAfter = 10000;

bool myState = false; //indicate my ready state
bool yourState = false; //indicate the other person's ready state

#define PIXEL_PIN D2
#define PIXEL_COUNT 14
#define PIXEL_TYPE WS2812

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

void setup() {

  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(startButtonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  Particle.subscribe(  "gameStart" , handleSharedEvent ); // Subscribe to game starting event
  Particle.subscribe(  "gameEnd" , handleSharedEvent );  // Subscribe to game ending event 
  strip.begin();
}

void loop() {
  startButtonState = digitalRead(startButtonPin);
  buttonState = digitalRead(buttonPin);

  if (startButtonState == LOW) {
      publishStartingEvent();
  }
      
  if (myState == true and yourState == true){
      counts();
      //light effect function
      uint32_t c = strip.Color(0, 0, 255); // Blue
      for(int i = 0; i<14; i++){
        strip.setPixelColor(i, c); // set a color 
        strip.show();
      }
  }
 
      
  if (counter >= 10){
      publishEndingEvent();
      //light effect function 2
        uint32_t c = strip.Color(0, 143, 255); // Blue
        uint32_t b = strip.Color(0, 32, 0); // Blue
        uint32_t a = strip.Color(255, 10, 10); // Blue
         
        for( int i = 0; i < strip.numPixels(); i++ ){
           strip.setPixelColor(i, c); // set a color 
           strip.show();
           delay( 50 );
        }
         
        for( int i = 0; i < strip.numPixels(); i++ ){
           strip.setPixelColor(i, b); // set a color 
           strip.show();
           delay( 50 );
        }
        
        for( int i = 0; i < strip.numPixels(); i++ ){
           strip.setPixelColor(i, a); // set a color 
           strip.show();
           delay( 10 );
        }    
      counter = 0;
  }

}

void counts()
{
   if (buttonState == LOW){
       counter += 1;
       delay(50);
          } 
}

void publishStartingEvent() // Publish function for the starting event 
{

  // check that it's been 10 secondds since our last publish
  if( lastPublishedAt + publishAfter < millis() )
  {

      String eventName = "gameStart" + System.deviceID();

      // then we share it out
      Particle.publish( eventName, "data goes here" );

      // And this will get shared out to all devices using this code

      // we just pubished so capture this.
      // lastPublishedAt = millis();
      myState = true;
  }

}

void publishEndingEvent() // Publish function for the ending event
{

  // check that it's been 10 secondds since our last publish
  if( lastPublishedAt + publishAfter < millis() )
  {

      String eventName = "gameEnd" + System.deviceID();

      // then we share it out
      Particle.publish( eventName, "data goes here" );

      // And this will get shared out to all devices using this code

      // we just pubished so capture this.
      // lastPublishedAt = millis();
      myState = false;
      //LED effects
  }

}

void handleSharedEvent(const char *event, const char *data){ // Only need one handle event function for both events 

    // Let's check the event name
    String eventName = String( event ); // convert to a string object

    // We can use this to check if our event name contains the
    // id of this device

    String deviceID = System.deviceID();

    // device id = 0123456789abcdef
    // event = "diot/2019/paired/0123456789abcdef"

    if( eventName.indexOf( deviceID ) != -1 ){
      // if we get anything other than -1
      // the event came from this device.
      // so stop doing stuff
      return;
    }
    
    if(eventName.startsWith("gameStart")){

        yourState = true;

    }
    
    if(eventName.startsWith("gameEnd")){
        
        yourState = false;
    }
 

}
Click to Expand
x
Share this Project

Courses

49713 Designing for the Internet of Things

· 18 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


Focused on
About

~

Created

February 12th, 2019