How To: Communicate Over Serial With Flash and Arduino

Hi there! Back from the holidays with an update on getting started with Arduino and serial communication. In this case communication with the Adobe Flash player. For all the details please watch both Flash videos linked below. You can refer back to this post with the links for the dependencies below as well. Also, there is serial debugging built into the Arduino IDE – as a separate project I will look at how to integrate that into the process, for now the external monitor ( serproxy ) is what I used. Enjoy!

The Environment:

Environment: Mac OS X Snow Leopard ( 10.6.2 )
Arduino: Arduino Duemilanove 328
Flash: CS4, ActionScript 3, Debug Player 10.0.42.34
Arduino IDE: 0017
FTDI Drivers: 2.2.14
AS3 Glue: v2_beta2
Firmata: Firmata-2.1 beta7
Serial Proxy: SerProxy-0.1.3

The Dependencies:

Serial Proxy Config:

# Config file for serproxy
# See serproxy's README file for documentation

# Transform newlines coming from the serial port into nils
# true (e.g. if using Flash) or false
newlines_to_nils=true

# Serial Devices on each port
serial_device1=/dev/cu.usbserial-A9007Vp3

# Comm ports used
comm_ports=1,2,3,4

# Default settings
comm_baud=57600
comm_databits=8
comm_stopbits=1
comm_parity=none

# Idle time out in seconds
timeout=300

# Port 1 settings (ttyS0)
net_port1=5331

# Port 2 settings (ttyS1)
net_port2=5332

# Port 3 settings (ttyS2)
net_port3=5333

# Port 4 settings (ttyS3)
net_port4=5334

The Example:

* Make sure to change the publish settings in the demo Flash file to point to your classpath of where you extract/download the AS3 Glue library.
Compressed Flash CS4 example (download and unzip)

The Screen-Casts:

* Apologies for the rushed ending of the 2nd part of the walkthroughs… I had to wrap up before the 5 minute time limit on the trial version and didn’t want to push it to a 3 part series!

Part 1: ( Dependencies & Setup )
Watch It
Part 2: ( Configuration & Demo )
Watch It

Posted in ActionScript 3, Arduino, How-To | Tagged , , , , , , , | 4 Comments

Dynamically Controlling Mature Content In Video Games

Throughout my time as a gamer I have welcomed the presence of “adult-oriented” content in video games. I like my “Mature” rated games and all the ingredients that come with them – profanity, excessive violence, etc, etc. But, as I’ve become a father I started to think about sharing the gaming experience with my son and how that would all play out with what I consider to be epic-must-play games and the content they depict. It led me to think about how the mature content ( and subsequently the rating ) on games vs. the configuration I have as the player to finely tweak them have become less inter-twined. For example, although I still see some games where you can toggle “gore”… in the good ol’ days I remember that setting to be much more configurable.
Ie:

  • - No blood
  • . Some blood
  • . Lots o’ blood
  • . Heads explode
  • + Alien blood

On that note, what if I see fit as a parent to allow my child to play & or watch me play “Kill Zone 2″… but in order for it to pass my parental guidelines the only thing I’m concerned about blocking is the excessive profanity in that game. How can I do that? Currently I don’t know of a way ( short of muting the audio ). What I’m proposing is that the video game companies ( or maybe even digital media companies as a whole? ) standardize a way in which, at least, profanity can be completely toggled. Ultimately it would be great if the platform could control that setting globally via the parental controls, but I imagine that would be a much larger change architecturally on both sides. Maybe subtitles and caption information could be “tagged” to various levels of profanity, cut-scenes that contained mature content could as well and then the ESRB would be describing what the highest level of those configurations would allow in the game, but not what it could be throttled back to. Granted some games are doing this — but not at the level in which I am suggesting and obviously there are limitations and it would potentially require more work. But, I think starting with profanity toggling may reveal more avenues of what could be possible.

Posted in Opinions, PS3 | Tagged , , , , , , | Leave a comment

Getting Coordinates Relative To The Viewport In JavaScript

When you are doing certain calculations, sometimes it’s nice to work with DOM elements using one coordinate system. Those familiar with Adobe Flash can think of this as the (global) Stage coordinates of a Display object. Anyway, one of the features I miss in ActionScript is the localToGlobal() and globalToLocal() methods available on Display objects. So, I set out to find comparable functionality in JavaScript. Unfortunately, the features that’ll get you there are not supported widely enough to be of much use to me yet. The features I am writing about are getClientRects() and getBoundingClientRect(). When ( and if ) they are implemented widely, this little utility script I’ve written will be happily deprecated.

So how’s it work? Well, you pass it a DOM element and it will return to you an object ( representing a rectangle: top, right, bottom, left ) containing coordinates where that element is positioned relative to the top left corner of the view-port. Those familiar to the ActionScript equivalent will notice that the arguments and return values are not exactly the same. I prefer passing in the element that you want converted as opposed to the Points representing the local coordinates. I also chose to return the coordinates of in rectangle format rather than the converted (x,y) Point since I thought it would be more useful to return all the corner values. Be mindful though about how often/successively you execute this function since it contains recursion.

Demo: Example

Tested:
OS X: FireFox 3.5, Safari 4, Opera 9.64
Windows: IE8, FireFox 3.5, Safari 3.1.1, Chrome 2

Source:
local-to-global.js

localToGlobal: function( _el ) {
					var
					   target = _el,
					   target_width = target.offsetWidth,
					   target_height = target.offsetHeight,
					   target_left = target.offsetLeft,
					   target_top = target.offsetTop,
					   gleft = 0,
					   gtop = 0,
					   rect = {};

					var moonwalk = function( _parent ) {
						if (!!_parent) {
							gleft += _parent.offsetLeft;
							gtop += _parent.offsetTop;
							moonwalk( _parent.offsetParent );
						} else {
							return rect = {
							     top: target.offsetTop + gtop,
								 left: target.offsetLeft + gleft,
								 bottom: (target.offsetTop + gtop) + target_height,
								 right: (target.offsetLeft + gleft) + target_width
						    };
						}
					};
				    moonwalk( target.offsetParent );
					return rect;
				}
Posted in Javascript | Tagged , , , , , , | Leave a comment