Project 004

From keywoniki

Jump to: navigation, search

Contents

[edit] Adruino + Flash: IR Sensor Game

Sensor input + Flash output

Control on-screen Flash game with an IR proximity sensor, get digital and physical feedback when you score!

Thumbnail here

Duration: 2007-07-26 ~ 2007-07-27


[edit] Process

[edit] Concept

  • One IR proximity sensor is attached to the back of the chair, controls the size of a circle on screen
  • Another IR sensor is attached to the player's body (shoulder, lap, forehead), controls the color of a circle on screen.
Fig 1. Concept Sketch
Fig 1. Concept Sketch

[edit] Flash Only Version: 2 Inputs

Download FLA

_xmouse controls circle size, _ymouse controls circle color (red, yellow, green, blue)




[edit] IR Sensor Version: 1 Input

Wiring

Fig 2. Wiring Arduino with a pair of IR Emitter and Detector
Fig 2. Wiring Arduino with a pair of IR Emitter and Detector
Fig 3. Wiring Arduino with a Sharp proximity sensor. Red: 5V, Orange: Gnd, Green: Analog in
Fig 3. Wiring Arduino with a Sharp proximity sensor. Red: 5V, Orange: Gnd, Green: Analog in


Arduino Coding

/* ------------------------------------------------
* Sensor input to Flash output
* By Keywon Chung
* ------------------------------------------------ */
#include <stdlib.h>                   // for itoa

int value = 0;                        // variable to keep the actual value coming from the sensor
int irPin = 2;                        // input pin: IR sensor connected to analog pin 2

void setup() 
{ 
  // to use serial print command later, should match the baud setting in serproxy.cfg
  Serial.begin(9600);                 
} 

void loop() 
{ 
  value = analogRead(irPin);         // read the value from the sensor (0-1024)
  //value = (value-150)/2;           // calibrate 150-700 down to 0-255
  if (value < 0) {
    value = 0;
  }
  if (value > 1024) {
    value = 1024;
  }

  // convert int var "value" into a 10-base string, store it in vString
  char vString[10];
  itoa(value, vString, 10);  

  // send the value to Flash in a string format       
  sendStringToFlash(vString);
}

/*send to flash: Taken from Jonah Model's LED Tester
* inspired by D.Mellis printString function. it simply adds the byte(0) at the end 
* needed by the XMLSocket to know that the transmission is over.
* read the XMLSocket Actionscript Class documentation for more details
*/
void sendStringToFlash (char *s) {
   while (*s) {
	    printByte(*s++);
        }
        printByte(0); //notify the XMLSocket that the comunication is over
}


Flash Coding

This was written using XMLScoket directly, instead of using the Arduino class: Download FLA

Add this to the end of the Main timeline frame 1 actionscript (in the initializing section):

// CONNECT TO ARDUINO
var a:XMLSocket = new XMLSocket();
a.connect("localhost", 5331);
a.onConnect = function(isSuccess) {
	//trace(isSuccess);
}
a.send("send");
a.onData = function(str) {
	//trace("onData: " + str);
	sizeReading = str*2;
}


Running

  1. Reset Arduino board by pressing the built-in button (or your own button connected to Arduino Mini), upload Arduino code.
  2. After "Done Uploading" message appears on Arduino, run servproxy.cfg on Terminal/Cmd window:
    1. Open Terminal/Cmd window, find your way down to the folder where serproxy is located:
      cd Desktop/Projects/serproxy-0.1.3.-3
    2. Run/Open serproxy.cfg with the application serproxy:
      ./serproxy serproxy.cfg
    3. FYI: Screenshot here.
  3. Launch swf by pressing Control/Command + Enter from Flash professional.
  4. Enjoy the interaction.
  5. Stop serial communication by pressing Control (not Command) + C in Termial.

[edit] Result

With small pair of IR Emitter/Detector: Not very reliable :(

Click below to play Video


With a Sharp proximity sensor: More responsive

Click below to play Video

Personal tools