Ice Breaker

Made by lingzhi2, smegbel and Zeynep Olcer

Found in DioT 2019: Social Objects - Part 2 · UNLISTED (SHOWN IN POOLS)

Our group intends to utilize the Internet of Things to break the awkwardness of being around new people or the awkwardness of silence through gamification.

0

Introduction

The awkwardness of silence and boredom are inevitable in most relationships. Our group intends to utilize the Internet of Things to promote an engaging environment through gamification. The devices of the users will be connected through the internet as each person will control the other person’s score. The game will be centered around an object that each person is expected to imitate in a given time interval. The object will be programmed to demonstrate the motions to the users. As each player imitates the object, the other player will decide on whether the movement was sufficient for the actor to earn a point. If either player believes that they can’t do one of the moves, they can wave and the object will interpret the motion as a “skip” through a distance sensor.


0

Interface

0

Story of Interaction

 Our project promotes interaction through the usage of music. In this interaction, by the press of a button, the piezo starts playing the music. We intended on using the music as a mediator for the interaction because music is a universal language that connects people. After the piezo plays the music, the servo would initiate a rotational motion. The intention behind the servo is to imitate a dancing motion as it generates a smooth flow. At the end of the interaction, in terms of application, one person is plays the music as the other dances.

0

Code


0
// This value will store the last time we published an event
long lastPublishedAt = 0;
// this is the time delay before we should publish a new event
// from this device
int publishAfter = 10000;

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup()
{
 myservo.attach(A5);  // attaches the servo on pin 9 to the servo object

  // We'll want to subscribe to an event thats fairly unique

  // From the Particle Docs
  // A subscription works like a prefix filter.
  // If you subscribe to "foo", you will receive any event
  // whose name begins with "foo", including "foo", "fool",
  // "foobar", and "food/indian/sweet-curry-beans".

  // Basically this will match any event that starts with 'db2018/paired/'
  // This is a feature we'll useto figure out if our event comes from
  // this device or another (see publishMyEvent below)

  Particle.subscribe(  "GRP5_SZL" , handleSharedEvent );

}

void loop()
{
    // publish my event
    // you'll want some more complex stuff here
    

    if (digitalRead(button)==LOW) {
        
        digitalWrite(sol, LOW);
        delay(200);
        digitalWrite(sol, HIGH);
        delay(200);
       
       publishMyEvent();
    }// delay for a bit
   
    // Particle.publish("val",String(digitalRead(buttonPin1)));
    // delay(1000);
}


void publishMyEvent()
{
  // Remember that a device can publish at rate of about 1 event/sec,
  // with bursts of up to 4 allowed in 1 second.
  // Back to back burst of 4 messages will take 4 seconds to recover.
  // So we want to limit the amount of publish events that happen.

  // check that it's been 10 secondds since our last publish
  if( lastPublishedAt + publishAfter < millis() )
  {
      // Remember our subscribe is matching  "db2018/paired/"
      // We'll append the device id to get more specific
      // about where the event came from

      // System.deviceID() provides an easy way to extract the device
      // ID of your device. It returns a String object of the device ID,
      // which is used to identify your device.

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

      // now we have something like "diot/2019/paired/0123456789abcdef"
      // and that corresponds to this devices info

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

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

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

}

// Our event handlde requires two bits of information
// This gives us:
// A character array that consists of the event name
// A character array that contains the data published in the event we're responding to.
void handleSharedEvent(const char *event, const char *data)
{
    // Now we're getting ALL events published using "db2018/paired/"
    // This includes events from this device.
    // So we need to ignore any events that we sent.

    // Let's check the event name
    String eventName = String( event ); // convert to a string object
    // This gives us access to a bunch of built in methods
    // Like indexOf()
    // Locates a character or String within another String.
    // By default, searches from the beginning of the String,
    // but can also start from a given index,
    // allowing for the locating of all instances of the character or String.
    // It Returns: The index of val within the String, or -1 if not found.

    // 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;
    } else {
        servoControl();
        //motor
    }

    // otherwise do your stuff to respond to
    // the paired device here

    //motorOn = true;

}

void servoControl()
{
    for (int i=0;i<2;i++) {
    for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(2);                       // waits 15ms for the servo to reach the position
  }
  
   delay(1000);
   
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(2);                       // waits 15ms for the servo to reach the position
  }
   delay(1000);
    }
}
Click to Expand
0
#define button D3
#define piezo D2


int speakerPin = D2; 
int melody[] = {1908,2551,2551,2273,2551,0,2024,1908};
int noteDurations[] = {4,8,8,4,4,4,4,4 };


long lastPublishedAt = 0;

int publishAfter = 10000;

void setup()
{

  Particle.subscribe(  "GRP5_SZL" , handleSharedEvent );
  pinMode(button, INPUT_PULLUP);
  pinMode(piezo, OUTPUT);

}

void loop()
{
    if (digitalRead(button)==LOW) {
        publishMyEvent();
    }
    
    delay(100);
}


void publishMyEvent()
{

  if( lastPublishedAt + publishAfter < millis() )
  {
      
      String eventName = "GRP5_SZL" + System.deviceID();

      Particle.publish( eventName, "data goes here" );

      lastPublishedAt = millis();
  }

}

void handleSharedEvent(const char *event, const char *data)
{
    
    String eventName = String( event ); 

    String deviceID = System.deviceID();

    if( eventName.indexOf( deviceID ) != -1 ){

      playNotes();
    }

}

void playNotes()
{
    
    for (int thisNote = 0; thisNote < 8; thisNote++) {

   
      int noteDuration = 1000/noteDurations[thisNote];
      tone(speakerPin, melody[thisNote],noteDuration);

     
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);
    
      noTone(speakerPin);
    }
}
Click to Expand
0

Process and Result

We primarily dealt with setting up the servo motor for movement and getting it working. The code of the servo motor was problematic. The first time we flashed the code, the servo motor turned 60 degrees and stopped. Then we changed the delay durations couple of times, increasing and decreasing, thinking that the delay might have been too short and the movement too fast to prevent the motor from turning 180 degrees probably. However, even with the same delays, the motor would sometimes work and sometimes would not. The movements were erratic and random. Finally, we realized that because there was no delay between the for loops, the motor couldn't find the moment to react to the code and do the second forloop to move backwards. After setting delays at the end of for loops and changed the delay durations for longer, our servo motor started moving back and forth with complete 180 degrees and normal pace. 

Then we also modified the SkillsDev code of piezo to respond to its own pushbutton with the melody that would also trigger the movement of the servomotor in the interaction. For this reason, we connected the objects (servo motor and piezo) through shared event code under GRP5_SZL by defining two new events (see below codes). As a result, when we push the button on piezo's circuit, the piezo plays the melody and the servo motor on the other circuit board moves (dances!) with the melody. 

0
x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

49713 Designing for the Internet of Things

· 18 members

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


About

Our group intends to utilize the Internet of Things to break the awkwardness of being around new people or the awkwardness of silence through gamification.

Created

February 11th, 2019