Saturday, October 29, 2011

Ultrasonic Theremin

UPDATE: i have redone the code in the last hour with the help of some Arduino forum members (mainly "Nick Gammon", thanks!), and now it is way more responsive...New vid up

Friday night i made a thermin using a ultrasonic module. the arduino reads module which says how far away my hand is from it(the module) in centimeters. then according to how far my hand is away from the module, the Arduino plays a coordinating tone. the closer my hand is, the lower the tone the speaker plays and each tone has 5 centimeters. so the first 5cm in front of the sensor is dead space, then 5 to 10cm is the lowest tone, and 10 to 15cm is the a little higher tone and so on up to 70cm



The distortions are actually caused by the code being too efficient, i figured out that i needed to add a delay before the code loops again.

Code:

#define trig 7 //trigger pin on sonar module
#define echo 6 //echo pin
#define spkr 4
#define led 12
int dist; //how far the object is away from the module(cm)
float valueSensor=0;

//tones array which holds the frequency to play.
float pitchTable[] = {
  329.63, //E4
  349.23, //F4
  369.99, //F#4/Gb4
  392.00, // G4
  415.30, // G#4/Ab4
  440.000000, // A
  466.163757, // A#/Bb
  493.83301, // B
  523.251160, // C
  554.365234, // C#/Db
  587.329529, // D
  622.253967, // D#/Eb
  659.255127, // E
  698.456482, // F
  739.988831, // F#/Gb
  783.990845, // G
  830.609375, // G#/Ab
  880.00, //A5
  932.33 //A#5/Bb5
};

#define NUMITEMS(arg) (sizeof (arg) / sizeof (arg [0]))

void setup()
{
  pinMode(echo, INPUT);
  pinMode(trig, OUTPUT);
}

void loop()
{
  //send a trigger signal
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  //receive the trigger signal echo, and calculate cm to the object
  valueSensor= pulseIn(echo, HIGH);
  dist= valueSensor/58;

  // each 5 positions represents a different note
  byte i = dist / 5;

  // play note if in range
  if (i < NUMITEMS (pitchTable))
  {
    tone(spkr,pitchTable[i]);
  }
  else
  {
    tone(spkr,523.251160);
  }
  delay(125);
}


Code for Just Reading Sonar Value:

#define trig 7 //trigger pin on sonar module
#define echo 6 //echo pin
int dist; //how far the object is away from the module(cm)
int valueSensor = 0; //see here, just added this line

void setup()
{
  Serial.begin(9600);
  pinMode(echo, INPUT);
  pinMode(trig, OUTPUT);
}

void loop()
{
  //send a trigger signal
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  //receive the trigger signal echo, and calculate cm to the object
  valueSensor= pulseIn(echo, HIGH);
  dist= valueSensor/58; //converts raw to cm, valueSensor/74/2 = inches
 
  Serial.println(dist);
}


Pics:


LM386 scheme:

Sunday, October 23, 2011

Robot Club "NTX+TETRIX" Robot

Here are some pics of the NTX+TETRIX robot that i have been building for "robot club". Pretty much no one else showed up for the work day so i built this all by my self. All that's left pretty much, is to mount the NXT, battery, and the crate(or magnetic ball?) claw.

2 Motor and 1 Servo controller, with quick connect adapters connected.
Back View.
Quick connect power cables.
Front view.
Side view

Saturday, October 22, 2011

PIR sensor and RGB LED indicators

Using the same RGB LEDs from the last project, i hooked up a PIR sensor sample from Parallax. It takes about 30sec to configure its self each time it powers on, and blinks red from the first RGB LED while its configuring. Then it lays in wait for movement, and then vigorously blinks the RGB LEDs until the movement has stopped. The PIR sensor outputs Either LOW(0v) or HIGH(5v) to the digital Arduino pin it is connected to depending on the status of the sensor. If motion is present, the PIR goes HIGH, and goes to LOW every once in a while even if motion is present. Then once no more motion is detected, the PIR outputs LOW.

/*
* //////////////////////////////////////////////////
* //making sense of the Parallax PIR sensor's output
* //////////////////////////////////////////////////
*
* Switches a LED according to the state of the sensors output pin.
* Determines the beginning and end of continuous motion sequences.
*
* @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at
* @date: 3. September 2006
*
* kr1 (cleft) 2006
* released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license
* http://creativecommons.org/licenses/by-nc-sa/2.0/de/
*
*
* The Parallax PIR Sensor is an easy to use digital infrared motion sensor module.
* (http://www.parallax.com/detail.asp?product_id=555-28027)
*
* The sensor's output pin goes to HIGH if motion is present.
* However, even if motion is present it goes to LOW from time to time,
* which might give the impression no motion is present.
* This program deals with this issue by ignoring LOW-phases shorter than a given time,
* assuming continuous motion is present during these phases.
*
*/

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 2; //the digital pin connected to the PIR sensor's output

int colorz;
int LEDx;
int delayx;
int pinx;
int pinz;
int piny;
int blnd;

/////////////////////////////
//SETUP
void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);

pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
//LED2
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(8, OUTPUT);
//LED3
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);

//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}

////////////////////////////
//LOOP
void loop()
{

if(digitalRead(pirPin) == HIGH)
{
int ps = 50;
light(1,1,ps); //LED1-Red
light(2,2,ps); //LED2-green
light(3,3,ps); //LED3-blue

blend(1,1,ps); //LED1-purple RG
blend(2,2,ps); //LED2-light blue GB
blend(3,3,ps); //LED3-yellow RB
blend(1,4,ps); //LED1-White RGB //the led visualizes the sensors output pin state

if(lockLow)
{
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}

if(digitalRead(pirPin) == LOW)
{
LEDLOW(); //the led visualizes the sensors output pin state

if(takeLowTime)
{
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause)
{
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}

void LEDLOW()
{
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
}

void light(int LEDx,int colorz,int delayx)
{
if(LEDx == 1) //if LEDx is 1(which is the first LED(digital pins 13-11))
{
if(colorz == 1) //if colorz is 1 then turn on pin 13 with delay in on/off,
{ // which is red of first RGB LED
blinkz(13, delayx);
}

if(colorz == 2) //if colorz is 2 then turn on pin 12 with delay in on/off,
{ //which is green of first RGB LED
blinkz(12, delayx);
}

if(colorz == 3) //if colorz is 3 then turn on pin 11 with delay in on/off,
{ //which is blue of first RGB LED
blinkz(11, delayx);
} //and so on for the rest of the if statements
}

if(LEDx == 2)
{
if(colorz == 1)
{
blinkz(3, delayx); //uses digital pin 3
}

if(colorz == 2)
{
blinkz(4, delayx); //uses digital pin 4
}

if(colorz == 3)
{
blinkz(8, delayx); //uses digital pin 8
}
}

if(LEDx == 3)
{
if(colorz == 1)
{
blinkz(7, delayx);
}

if(colorz == 2)
{
blinkz(6, delayx);
}

if(colorz == 3)
{
blinkz(5, delayx);
}
}
}

void blinkz(int pinx, int delayx) //blinks one LED at a time on/off with an established time delay(delayx)
{
digitalWrite(pinx, HIGH);
delay(delayx);
digitalWrite(pinx, LOW);
delay(delayx);
}

void blend(int LEDx, int colorz, int delayx)
{
if(LEDx == 1)
{
if(colorz == 1)
{
//red+green, purple
mixblend(13,12,delayx); //two pins at once to mix colors, or random two pins of any LED at a time.
}

if(colorz == 2)
{
//Green+blue, light blue
mixblend(12,11,delayx);
}

if(colorz == 3)
{
//red+blue,
mixblend(13,11,delayx);
}

if(colorz == 4)
{
whiteblend(13,12,11,delayx); //makes white(if you do three pins from same RGB LED, or random three pins of any LED at a time.
}
}

if(LEDx == 2)
{
if(colorz == 1)
{
mixblend(3,4,delayx);
}

if(colorz == 2)
{
mixblend(4,8,delayx);
}

if(colorz == 3)
{
mixblend(3,8,delayx);
}

if(colorz == 4)
{
whiteblend(3,4,8,delayx);
}
}

if(LEDx == 3)
{
if(colorz == 1)
{
mixblend(7,6,delayx);
}

if(colorz == 2)
{
mixblend(6,5,delayx);
}

if(colorz == 3)
{
mixblend(7,5,delayx);
}

if(colorz == 4)
{
whiteblend(7,6,5,delayx);
}
}
}

//pinx, pinz, are any two LED pins
//you want to light at one time
void mixblend(int pinx, int pinz, int delayx) //tells which two LEDs to blend
{
digitalWrite(pinx, HIGH);
digitalWrite(pinz, HIGH);
delay(delayx);
digitalWrite(pinx, LOW);
digitalWrite(pinz, LOW);
delay(delayx);
}

//pinx, pinz, piny are any three LED pins
//you want to light at one time, do three from same LED for white
void whiteblend(int pinx, int pinz, int piny, int delayx)
{
digitalWrite(pinx, HIGH);
digitalWrite(pinz, HIGH);
digitalWrite(piny, HIGH);
delay(delayx);
digitalWrite(pinx, LOW);
digitalWrite(pinz, LOW);
digitalWrite(piny, LOW);
delay(delayx);
}

*use the "Auto Format"(Cntrl + T) option under the tool menu in the Arduino IDE to fix the formatting. As you can see i didn't write this code, only added the RGB LED stuff to it...but it is fairly simple. Thr following is the original code.


/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;      

//the time when the sensor outputs a low impulse
long unsigned int lowIn;        

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 7;    //the digital pin connected to the PIR sensor's output
int ledPin = 8;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;          
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec");
         delay(50);
         }        
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){      
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause,
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){
           //makes sure this block of code is only executed again after
           //a new motion sequence has been detected
           lockLow = true;                      
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

 Pics:
 The Arduino is waiting for the PIR sensor to configure, and blinking red while it waits.
Done configuring PIR sensor, and waiting for something to move!
I moved the camera too much, and so the PIR sensor has sensed motion is blinking all the LEDs!

Moppy - Playing Music with Floppy Drives!

I played MIDI music files through a JAVA app to my Arduino, which had 4 floppy drives connected. The code isnt mine; it was written by SammyIAm. Code for JAVA and Arduino here: Github SammyIAm Moppy Instructions at Github for how to install the Netbeans JAVA IDE and a general overview of the project.

Quick connect guide for the floppy, Arduino, and PSU.






























.
.


.

Rather than waste PSU floppy conenctors, i just took some solid core wire and parallel connected 5v and GND from each floppy drive, then used a jumper(see pic) for drive select, and connected the step(pin 20) and direction(pin 18) to the Arduino. Furthermore, contrary to "popular" belief, only five connections are required on each floppy drive. 12v(Yellow) is not required, and pin 1 of the floppy cable doesn't need to be grounded.

The following are the only required connections for each floppy drive:
Pin 14->GND this can be done by simply putting one of those IDE HDD 2 pin jumpers between pin 14 and a nearby GND pin on the floppy drives data port.
Pin 18->Arduino digital pin
Pin 20-> Arduino digital pin
5v(Red) to External 5v PSU
GND(either black wire) to Arduino AND external PSU GND

8 floppy setup:


Video of my results:


Controlling 3 RGB LEDs from arduino

basically i hooked up each pin(except for GND) of a common cathode RGB LED to the arduino with resistors, and then wrote a quick program to control all three color of each LEDs easily.

//light
//light(1,1,ps); light(LEDx,colorz,Time);
//
//LED: 1 or 2 or 3
//
//colorz: 1 -Red
//colorz: 2 -Green
//colorz: 3 -Blue
//
//time in ms


//blend
//blend(1,1,ps); blend(LEDx,colorz,Time);
//
//LED: 1 or 2 or 3
//
//colorz: 1 -RG yellow
//colorz: 2 -GB light blue
//colorz: 3 -RB purple/pink
//colorz: 4 -RGB white
//
//time in ms
int colorz;
int LEDx;
int delayx;
int pinx;
int pinz;
int piny;
int blnd;

void setup()
{
//LED1
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
//LED2
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(8, OUTPUT);
//LED3
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
}

void loop()
{
int ps = 75;
light(1,1,ps); //LED1-Red
light(2,2,ps); //LED2-green
light(3,3,ps); //LED3-blue

blend(1,1,ps); //LED1-purple RG
blend(2,2,ps); //LED2-light blue GB
blend(3,3,ps); //LED3-yellow RB
blend(1,4,ps); //LED1-White RGB
}

void light(int LEDx,int colorz,int delayx)
{
if(LEDx == 1) //if LEDx is 1(which is the first LED(digital pins 13-11))
{
if(colorz == 1) //if colorz is 1 then turn on pin 13 with delay in on/off,
{ // which is red of first RGB LED
blinkz(13, delayx);
}

if(colorz == 2) //if colorz is 2 then turn on pin 12 with delay in on/off,
{ //which is green of first RGB LED
blinkz(12, delayx);
}

if(colorz == 3) //if colorz is 3 then turn on pin 11 with delay in on/off,
{ //which is blue of first RGB LED
blinkz(11, delayx);
} //and so on for the rest of the if statements
}

if(LEDx == 2)
{
if(colorz == 1)
{
blinkz(3, delayx); //uses digital pin 3
}

if(colorz == 2)
{
blinkz(4, delayx); //uses digital pin 4
}

if(colorz == 3)
{
blinkz(8, delayx); //uses digital pin 8
}
}

if(LEDx == 3)
{
if(colorz == 1)
{
blinkz(7, delayx);
}

if(colorz == 2)
{
blinkz(6, delayx);
}

if(colorz == 3)
{
blinkz(5, delayx);
}
}
}

void blinkz(int pinx, int delayx) //blinks one LED at a time on/off with an established time delay(delayx)
{
digitalWrite(pinx, HIGH);
delay(delayx);
digitalWrite(pinx, LOW);
delay(delayx);
}

void blend(int LEDx, int colorz, int delayx)
{
if(LEDx == 1)
{
if(colorz == 1)
{
//red+green, purple
mixblend(13,12,delayx); //two pins at once to mix colors, or random two pins of any LED at a time.
}

if(colorz == 2)
{
//Green+blue, light blue
mixblend(12,11,delayx);
}

if(colorz == 3)
{
//red+blue,
mixblend(13,11,delayx);
}

if(colorz == 4)
{
whiteblend(13,12,11,delayx); //makes white(if you do three pins from same RGB LED, or random three pins of any LED at a time.
}
}

if(LEDx == 2)
{
if(colorz == 1)
{
mixblend(3,4,delayx);
}

if(colorz == 2)
{
mixblend(4,8,delayx);
}

if(colorz == 3)
{
mixblend(3,8,delayx);
}

if(colorz == 4)
{
whiteblend(3,4,8,delayx);
}
}

if(LEDx == 3)
{
if(colorz == 1)
{
mixblend(7,6,delayx);
}

if(colorz == 2)
{
mixblend(6,5,delayx);
}

if(colorz == 3)
{
mixblend(7,5,delayx);
}

if(colorz == 4)
{
whiteblend(7,6,5,delayx);
}
}
}

//pinx, pinz, are any two LED pins
//you want to light at one time
void mixblend(int pinx, int pinz, int delayx) //tells which two LEDs to blend
{
digitalWrite(pinx, HIGH);
digitalWrite(pinz, HIGH);
delay(delayx);
digitalWrite(pinx, LOW);
digitalWrite(pinz, LOW);
delay(delayx);
}

//pinx, pinz, piny are any three LED pins
//you want to light at one time, do three from same LED for white
void whiteblend(int pinx, int pinz, int piny, int delayx)
{
digitalWrite(pinx, HIGH);
digitalWrite(pinz, HIGH);
digitalWrite(piny, HIGH);
delay(delayx);
digitalWrite(pinx, LOW);
digitalWrite(pinz, LOW);
digitalWrite(piny, LOW);
delay(delayx);
}
*use the "Auto Format"(Cntrl + T) option under the tool menu in the Arduino IDE to fix the formatting. Pics:

Tuesday, October 18, 2011

Computer and/or Arduino controlled Etch-a-Sketch

Last weekends project was to make a Etch-a-sketch controlled by a Arduino and eventually a computer. It was pretty simple, only taking a few hours start to finish. i made both a computer controlled version(which will eventually take images and sketch them), and a simple Arduino version. the only difference really is that the computer version of the Arduino code has a serial interface for receiving commands.

Computer Version:
The computer interface is a simple C# forms program with buttons for up, down, left, right, and diagonals. I think eventually I will add shapes with custom dimensions features to the program.
using System;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;

namespace EASproject
{
public class EAS_ControlForm : System.Windows.Forms.Form
{
private Button Up4;
private Button Down3;
private Button Left2;
private Button Right1;
private Button Stop9;
private Button DLD5;
private Button DRD6;
private Button ULD7;
private Button URD8;

public EAS_ControlForm()
{
Text = "EAS Control";
Down3 = new Button ();
Up4 = new Button ();
Left2 = new Button ();
Right1 = new Button ();
Stop9 = new Button ();
DLD5 = new Button ();
DRD6 = new Button ();
ULD7 = new Button ();
URD8 = new Button ();
this.BackColor = System.Drawing.Color.LightBlue;

Down3.Text = "Down";
Down3.Name = "Down3";
Down3.Size = new System.Drawing.Size (72, 30);
Down3.Location = new System.Drawing.Point (105, 65);
Controls.AddRange(new System.Windows.Forms.Control[] {this.Down3});
Down3.Click += new System.EventHandler(OnClickDown3);

Up4.Text = "Up";
Up4.Name = "Up4";
Up4.Size = new System.Drawing.Size (72, 30);
Up4.Location = new System.Drawing.Point (105, 30);
Controls.AddRange(new System.Windows.Forms.Control[] {this.Up4});
Up4.Click += new System.EventHandler(OnClickUp4);

Left2.Text = "Left";
Left2.Name = "Left2";
Left2.Size = new System.Drawing.Size (72, 30);
Left2.Location = new System.Drawing.Point (27, 45);
Controls.AddRange(new System.Windows.Forms.Control[] {this.Left2});
Left2.Click += new System.EventHandler(OnClickLeft2);

Right1.Text = "Right";
Right1.Name = "Right1";
Right1.Size = new System.Drawing.Size (72, 30);
Right1.Location = new System.Drawing.Point (182, 45);
Controls.AddRange(new System.Windows.Forms.Control[] {this.Right1});
Right1.Click += new System.EventHandler(OnClickRight1);

DLD5.Text = "Down.Left diagonal";
DLD5.Name = "DLD5";
DLD5.Size = new System.Drawing.Size (72, 30);
DLD5.Location = new System.Drawing.Point (27, 170);
Controls.AddRange(new System.Windows.Forms.Control[] {this.DLD5});
DLD5.Click += new System.EventHandler(OnClickDLD5);

DRD6.Text = "Down.Right diagonal";
DRD6.Name = "DRD6";
DRD6.Size = new System.Drawing.Size (72, 30);
DRD6.Location = new System.Drawing.Point (182, 170);
Controls.AddRange(new System.Windows.Forms.Control[] {this.DRD6});
DRD6.Click += new System.EventHandler(OnClickDRD6);

ULD7.Text = "Up.Left diagonal";
ULD7.Name = "ULD7";
ULD7.Size = new System.Drawing.Size (72, 30);
ULD7.Location = new System.Drawing.Point (27, 135);
Controls.AddRange(new System.Windows.Forms.Control[] {this.ULD7});
ULD7.Click += new System.EventHandler(OnClickULD7);

URD8.Text = "Up.Right diagonal";
URD8.Name = "URD8";
URD8.Size = new System.Drawing.Size (72, 30);
URD8.Location = new System.Drawing.Point (182, 135);
Controls.AddRange(new System.Windows.Forms.Control[] {this.URD8});
URD8.Click += new System.EventHandler(OnClickURD8);

Stop9.Text = "Stop Motors!";
Stop9.Name = "Stop9";
Stop9.Size = new System.Drawing.Size (72, 30);
Stop9.Location = new System.Drawing.Point (105, 95);
Controls.AddRange(new System.Windows.Forms.Control[] {this.Stop9});
Stop9.Click += new System.EventHandler(OnClickStop9);
}

static SerialPort port;
static public void Main()
{
port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Open();

Application.Run(new EAS_ControlForm());
}

public static void Example()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

try {
throw new Exception("1");
} catch (Exception e)
{
MessageBox.Show("Catch clause caught : " + e.Message);
}

throw new Exception("2");
}

static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
}

static void OnClickDown3 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<3,100>");
}

static void OnClickUp4 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<4,100>");
}

static void OnClickLeft2 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<2,100>");
}

static void OnClickRight1 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<1,100>");
}

static void OnClickDLD5 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<5,100>");
}

static void OnClickDRD6 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<6,100>");
}

static void OnClickULD7 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<7,100>");
}

static void OnClickURD8 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
port.Write("<8,100>");
}

static void OnClickStop9 (object sender, System.EventArgs e)
{
port.Write("<9,100>");
}
}
}
As you can see, i really need to work on the repetition in the code...

Arduino Code:
#include

Servo Xaxis;
Servo Yaxis;

int started = 0;
char inData[8];
int ended = 0;
char index = 0;
int final = 0;

void setup()
{
Xaxis.write(90);
Xaxis.attach(6);

Yaxis.write(90);
Yaxis.attach(5);

Serial.begin(9600);
}

void loop()
{
while(Serial.available() > 0)
{
char aChar = Serial.read();
if(aChar == '<') { started = true; index = 0; inData[index] = '\0'; } else if(aChar == '>')
{
ended = true;
}

else if(started)
{
inData[index] = aChar;
index++;
inData[index] = '\0';
}

else if (aChar =='*')
{
final = true;
}
}

if(started && ended)
{
const char* strDelimiter = ",";

char* p;
int time;
int dir;

if ( p = strtok(inData, strDelimiter) )
{
dir = atoi(p);
}
if ( p = strtok(NULL, strDelimiter) )
{
time = atoi(p);
}

// Get ready for the next time
started = false;
ended = false;
index = 0;
inData[index] = '\0';

Move(dir, time);
}
}

//Servos move the dot on etch-a-sketch screen 1in/sec or 31/32
void Move(int dir, int time)
{
if(dir == 1)
{
//Xaxis Right
Xaxis.write(180);
//
}

if(dir == 2)
{
//Xaxis Left
Xaxis.write(0);
}

if(dir == 3)
{
//Yaxis Down
Yaxis.write(0);
}

if(dir == 4)
{
//Yaxis Up
Yaxis.write(180);
}

if(dir == 5)
{
//Down+Left diagonal
Yaxis.write(0);
Xaxis.write(0);
}

if (dir == 6)
{
//Down+Right diagonal
Yaxis.write(0);
Xaxis.write(180);
}

if (dir == 7)
{
//Up+Left diagonal
Yaxis.write(180);
Xaxis.write(0);
}

if (dir == 8)
{
//Up+Right diagonal
Yaxis.write(180);
Xaxis.write(180);
}

if(dir == 9)
{
//stop both motors
Yaxis.write(90);
Xaxis.write(90);
}
}
Basically how this works is: when a button is pressed in the C# program, it stops all previous motor activity by sending "<9,100>" over the serial port to the Arduino. then "<7,100>" is sent which is, in this case, the command for making a 45degree up and left diagonal line on the etch a sketch.
When the Arduino receives the "<7,100>" data, it first checks to make sure it has all of the data by checking for a "<" and a ">" at the beginning and end, respectively, of the line received. then it write the actual data, which is 7,100, to a index. Next, the strtok function reads the index and separates the data by the comma. "7" is written to int dir and "100" to int time. the number in int time isn't important in this version of the code, its only a space holder so i didn't have to rewrite some of the code. Then the line "Move(dir, time)" reads int dir, and turns on the correct motor full speed according to the number in int dir.

int time could be more accurately portrayed as "speed" but that's what i chose at the time of writing the code. In the lines "Yaxis.write(180); Xaxis.write(0);" the values 0 and 180 are full speed in opposite directions. Yaxis is the motor for moving the Etch-A-sketch "utensil" up and down, Xaxis -- left and right. 90 is for stopping the continuous servos(or some call the just motors).

Arduino only version:
#include

Servo Yaxis; // create servo object to control a servo
Servo Xaxis; // a maximum of eight servo objects can be created

int pos = 0;

void setup()
{
Serial.begin(9600);

Xaxis.write(90); //stop both servos
Yaxis.write(90);

Yaxis.attach(5); // attaches the servo on pin 9 to the servo object
Xaxis.attach(6);


Move(1,1950); //Xaxis right
}

void loop()
{
}

void Move(int dir, int time)
{
if (dir == 1)
{
Serial.print("Xaxis Right for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Xaxis.write(180);
delay(time);
Xaxis.write(90);
}

if (dir == 2)
{
Serial.print("Xaxis Left for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Xaxis.write(0);
delay(time);
Xaxis.write(90);
}

if (dir == 3)
{
Serial.print("Yaxis Down for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Yaxis.write(0);
delay(time);
Yaxis.write(90);
}

if (dir == 4)
{
Serial.print("Yaxis Up for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Yaxis.write(180);
delay(time);
Yaxis.write(90);
}

if (dir == 5)
{
Serial.print("Down+Left diagonal for ");
Serial.print(time);
Serial.print("ms");
Serial.println();

Yaxis.write(0); // tell servo to go to position in variable 'pos'
Xaxis.write(0);
delay(time); // waits 15ms for the servo to reach the position

Xaxis.write(90);
Yaxis.write(90);
}

if (dir == 6)
{
Serial.print("Down+Right diagonal for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Yaxis.write(0);
Xaxis.write(180);
delay(time);
Yaxis.write(90);
}

if (dir == 7)
{
Serial.print("Up+Left diagonal for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Yaxis.write(180);
Xaxis.write(0);
delay(time);
Yaxis.write(90);
}

if (dir == 8)
{
Serial.print("Up+Right diagonal for ");
Serial.print(time);
Serial.print("ms");
Serial.println();
Yaxis.write(180);
Xaxis.write(180);
delay(time);
Yaxis.write(90);
}
}
This version doesn't require a computer for moving the servos, instead the motors are told what to do in the actual code. (But i do have Serial.Print to debug the code, and make sure the code is working correctly.) This can be seen in "void setup()" with the "Move(1,1950);" line. Now, the Arduino does not only control which motor turns, but also how long. In the line above, "1,1950" is moving the Etch-a-Sketch "cursor" right along the X-Axis for 1950ms which is 1.95seconds once per time the Arduino code is ran.

Pics: I used the same breadboard Arduino for the RGB LEDs and the Etch-A-Sketch.