For our final project we decided to create an accessory to a GPS system that would help a driver park his or her car when faced with a  crowded parking lot.  We used a PDA and programed it to read directly from the arduino by projecting the exact image that was on our computer screen.  We did this to simulate what the GPS system would look like to the driver, a grid showing taken spots and open spots.  We also used a program called flash to create the image that was displayed on the PDA.  For each parking spot we envisioned using a weight sensor (regular switch) that would detect when a car was parked on it and then would send information to the GPS system (arduino)

Parking Lot Arduino

ARDUINO CODE


This is the website that we downloaded Flash from:

http://memewire.com/reference/Arduino_Flash



/* ------------------------------------------------

* Flash + Arduino LED Tester

* by Jonah Model <jmodel@parsaons.edu>

* modified from ARDUINO CONVERSATION, by beltran berrocal, b@progetto25zero1.com

* ------------------------------------------------ */

int activeLED ;              // What LED has Flash requested we turn on? Numbers

2-9, for a total of 8 possible LEDs

int switchState = 0;        // What is the current switch state?

int switchState2 = 0;

int switchState3 = 0;

int switchState4 = 0;

int switchState5 = 0;

int lastSwitchState = 0;    // Was the switch previously on, or off?

int lastSwitchState2 = 0;

int lastSwitchState3 = 0;

int lastSwitchState4 = 0;

int lastSwitchState5 = 0;

int switchPin = 7;         // Which digital i/o pin is setup for the switch?

int switchPin2 = 6;

int switchPin3 = 5;

int switchPin4 = 4;

int switchPin5 = 3;


//----------------------------------------------------------

void setup() {

  Serial.begin(19200);  //setup serial conversation at 19200 bauds

  pinMode(switchPin, INPUT);  // sets the switch pin as input

  pinMode(switchPin2, INPUT);

  pinMode(switchPin3, INPUT);

  pinMode(switchPin4, INPUT);

  pinMode(switchPin5, INPUT);

  for (int i=2; i<=9; i++) {

      pinMode(i, OUTPUT);      // sets the digital pins 2-9 as output

  }

}


void loop () {

 

  //------------------------------------------------------------------------ SWITCH

LOGIC

  // get the current state of the switch from our board

  switchState = digitalRead(switchPin);

  // if the switch has changed states, then let Flash know about it

  if (switchState != lastSwitchState) {

    if (switchState == 1){

      sendStringToFlash("switchoff");

    }

    else if (switchState == 0){

      sendStringToFlash("switchon");

    }

  }

  lastSwitchState = switchState;

 

  switchState2 = digitalRead(switchPin2);

  if (switchState  != lastSwitchState2)  {

    if (switchState2 == 1) {

      sendStringToFlash("switch2off");

    }

    else if (switchState2 == 0){

      sendStringToFlash("switch2on");

    }

  }

  // now store the state for later comparison

  lastSwitchState2 = switchState2;

 

  switchState3 = digitalRead(switchPin3);

  if (switchState !=lastSwitchState3)  {

    if (switchState3 == 1) {

      sendStringToFlash("switch3off");

    }

    else if (switchState3 == 0){

      sendStringToFlash("switch3on");

    }

  }

  lastSwitchState3 = switchState3;

 

    switchState4 = digitalRead(switchPin4);

  if (switchState !=lastSwitchState4)  {

    if (switchState4 == 1) {

      sendStringToFlash("switch4off");

    }

    else if (switchState4 == 0){

      sendStringToFlash("switch4on");

    }

  }

  lastSwitchState4 = switchState4;

 

    switchState5 = digitalRead(switchPin5);

  if (switchState !=lastSwitchState5)  {

    if (switchState5 == 1) {

      sendStringToFlash("switch5off");

    }

    else if (switchState5 == 0){

      sendStringToFlash("switch5on");

    }

  }

  lastSwitchState5 = switchState5;

 


 

 

  //------------------------------------------------------------------------ LED LOGIC

 

  // checks if a serial message has arrived to the board

   if(Serial.available() > 0) {     

          //must be a request to light up an LED  

          //activeLED should be a number 2-9, but in binary it will come in as 50-57

          activeLED = Serial.read();

    }   

   


   

    if(activeLED >= 50 && activeLED <= 57) {

      //a valid LED signal has been received from Flash

      // convert the byte to an int - getting ready for digitalWrite()

      int outputPort = activeLED-48;

     

      Serial.print("Requesting LED port:");

      Serial.println(outputPort);

     

      if(outputPort >= 2 && outputPort <= 9) {

            // turns all the LEDs OFF

            for (int i=2; i<=10; i++) {

             digitalWrite(i,LOW);

            }

            // then turns your selected LED ON

            digitalWrite(outputPort, HIGH);

      }

      

     

      // when we're done, default the activeLED to nothing

      activeLED = 0;

  }

  else if (activeLED) {

        Serial.print("Requesting invalid LED port:");

        Serial.println(activeLED,BYTE);

  }


 

  //slows down the visualization: each sentence will be emitted every .5 seconds

  delay(50);

 

}


//----------------------------------------------------------


/*send to flash

* 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

}

//------------------------------------------------------------------------ Basic

Arduino


import Arduino;


var port:Number = 5339;                // What socket port are we configured to use?

                                                        // See the net_port entries from serproxy.cfg


// Create a custom object from Flash's XMLSocket

var a:Arduino = new Arduino(port);



//------------------------------------------------------------------------ Listeners



// You can trigger custom actions by adding listners to the Arduino object. For

example, you can setup your

// ActionScript code to run a setup function when Flash successfully connects to the

socket listener


aListener = new Object();


aListener.onConnect = function() {

        setupBoard();

}


aListener.onReceiveData = function(evtObj:Object){

        //Store the received data in a string

        var str = evtObj.data

        trace("Arduino says -- " + str);

       

        //Tests for a particular message from Arduino, and acts accordingly

        if (str == "switchoff") {

                _root.park.gotoAndStop(1);

        }

        else if (str == "switchon") {

                _root.park.gotoAndStop(2);

        }

        if (str == "switch2off") {

                _root.park2.gotoAndStop(1);

        }

        else if (str == "switch2on")  {

                _root.park2.gotoAndStop(2);

        }

        if (str == "switch3off") {

                _root.park3.gotoAndStop(1);

        }

        else if (str == "switch3on") {

                _root.park3.gotoAndStop(2);

        }

        if (str == "switch4off") {

                _root.park4.gotoAndStop(1);

        }

        else if (str == "switch4on") {

                _root.park4.gotoAndStop(2);

        }

        if (str == "switch5off") {

                _root.park5.gotoAndStop(1);

        }

        else if (str == "switch5on") {

                _root.park5.gotoAndStop(2);

        }

}


// Binds your custom listeners to the Arduino object (a)

a.addEventListener("onConnect",aListener);

a.addEventListener("onReceiveData",aListener);


//------------------------------------------------------------------------ That's all!


function setupBoard() {

        trace("Connection established. Now setting up LEDs...");

       

        // Each physical LED gets a virtual copy in Flash

         for (var i=2;i<=9;i++) {

               

                // Associates a pin with each movieclip

                var mc:MovieClip = _root["led"+i];

                // Stores the digital i/o pin number for later use

                mc.pin = i.toString();

               

               

                var owner = this;

                mc.onPress = function() {

                        // Send the pin data to Arduino, telling it what pin to turn on

                        owner.a.send(this.pin);

                       

                        // Turn all virtual LEDs OFF

                        for (var i=2; i<=10; i++) {

                     _root["led"+i].gotoAndStop(1);

            }

                        // Now turn the selected virtual LED ON

            _root["led"+this.pin].gotoAndStop(2);

                }

        }

}

 
Comments Widget