Pantalla táctil casera con sensor PING))) y Flash

Publicado por en Arduino el 06/07/2010

Miguel me envía un interesante proyecto realizado por James Alliban. Se trata de una pantalla táctil casera que utiliza dos sensores PING))) de Parallax para detectar la distancia vertical. Ha utilizado un pequeña script en Flash AS3 junto con Serproxy para dibujar unos botones e incluso un pequeño sistema de partículas.

No os perdais video y enlace a continuación...

Gracias Miguel por la noticia!

Enlace: Flash range sensor

Configuración serproxy

newlines_to_nils=false

comm_ports=3

comm_baud=57600
comm_databits=8
comm_stopbits=1
comm_parity=none

timeout=300

net_port3=5333 

 

ActionScript

/*
Author James Alliban - https://jamesalliban.wordpress.com

This code has been writted specifically to be used for interfacing with the PING Ultrasonic
Range Finder using the Arduino microcontroller and communicating via SerProxy. If anyone makes
anything interesting with it, or improves upon it in any way, please email me at
me@jamesalliban.co.uk

*/

package
{

	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.net.Socket;
	import flash.events.ProgressEvent;

	public class RangeFinderData
		extends Sprite
	{

		private var s				:	Socket;

		private var prevInput		:	String;		// the previously processed input (returned value)
		private var currInput		:	String;		// the currently processed input
		private var finalInput		:	String;		// the input after processing

		public function RangeFinderData()
		{
			init();
		}

		public function init() : void
		{

			s = new Socket("127.0.0.1", 5333);
			s.addEventListener(ProgressEvent.SOCKET_DATA, sData);

		}

		private function sData( e:ProgressEvent ) : void
		{

			// read the correct data from the socket. In this instance. This arrives in millimeters
			// preceeded by "A"
			var sData:String = s.readUTFBytes( s.bytesAvailable );

			if (isDataCorrect(sData)) {

				if (sData.indexOf( "A" ) == 0) {
					prevInput = currInput;
					currInput = sData.substr( 1 );
				} else {
					currInput += sData;
				}

				 trace( "prevInput = '" + prevInput + "'" );
			}
		}


		function isDataCorrect( sData:String ) : Boolean
		{
			// occasionally, between real results the data returned consists of a carriage return
			// then a zero.
			if (parseInt(sData) == 0 && sData.length > 1) return false;
			// another occasional unwanted reult
			if (sData == "") return false;
			if (sData == "0") return false;

			return true;
		}
	}
}

 

Programa Arduino

/* Ultrasound Sensor
 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * https://www.xlab.se | https://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */

int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  Serial.begin(9600);			// Sets the baud rate to 9600 - was Serial.begin(9600);
  pinMode(ledPin, OUTPUT);		// Sets the digital pin as output
}

void loop() {
  timecount = 0;
  val = 0;
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

  /* Send low-high-low pulse to activate the trigger pulse of the sensor
   * -------------------------------------------------------------------
   */

  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff

  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */

  pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  val = digitalRead(ultraSoundSignal); // Append signal value to val
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
  }

  while(val == HIGH) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
    timecount = timecount +1;		// Count echo pulse time
  }
  /* Writing out values to the serial port
   * -------------------------------------------------------------------
   */
  ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue
  serialWrite('A'); // Example identifier for the sensor
  printInteger(ultrasoundValue);
  serialWrite(10);
  serialWrite(13);

  /* Lite up LED if any value is passed by the echo pulse
   * -------------------------------------------------------------------
   */

  if(timecount > 0){
    digitalWrite(ledPin, HIGH);
  }

  /* Delay of program
   * -------------------------------------------------------------------
   */

  Serial.print( "val = " + val );
  delay(100);
}

 

Si te ha gustado, compártelo con tus amigos!

Uso de Cookies

Utilizamos cookies propias y de terceros para optimizar tu visita. No utilizamos cookies para recoger información de carácter personal.

Puedes permitir su uso o rechazarlo y cambiar su configuración cuando lo desees.

Cerrar

Más información en nuestra Política de Cookies.