Difference between revisions of "Students/Simon Quiroz"

From Robert-Depot
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 23: Line 23:
 
'''Diagram'''
 
'''Diagram'''
  
[[Image:diag2.jpg]]
+
[[Image:diag3.jpg]]
 +
 
 +
or
 +
 
 +
[[Image:diag4.jpg]]
 +
 
 +
 
 +
'''Final Project Version 1.0 (Subject to change without prior notification):'''
 +
'''Paranormal Events'''
 +
 
 +
Currently our socieety faces many issues that have a direct impact in the psychological mind state of the individual. Largely speaking this translates to a big sociological pathos. Having said this, people's emotional instabilty incites the appearance of what can normally be considered by traditional psychiatrists as severe psychological disorders. Nevertheless, these moments of uncertainty and paranoia also create an environment where "supernatural" events occur with more frequency. Using the Arduino technology, taking data from the environment, people's mind states and the internet(whichh largely reflect societal trends) the Arduino will detect and showcase in some form(yet to be discovered) the amount of supernatural events that occur parallel to our immediate reality which we cannot perceive through our normal senses.
 +
 
 +
Images:
 +
 
 +
[[Image:p1.jpg]]
 +
[[Image:p2.jpg]]
 +
[[Image:p3.jpg]]
 +
[[Image:p4.jpg]]
 +
[[Image:p5.jpg]]
 +
[[Image:p6.jpg]]
 +
 
 +
'''FINAL:'''
 +
 
 +
The aesthetics of this device function in complete contradiction with the ones of a cheap popular culture. Unconcerned with making of this project  a pretty, flashy product, its raw image reflects the current mental state of mind of its creator under circumstances of lack of sleep, stress and time created by the mechanisms surrounding him. As a matter of fact, its separation from a shallow aesthetic showcases the harsh reality, everyday events and stressful circumstances to which individuals are subjected to due to current conditions. More and more individuals are in danger to develop an unstable state of mind. This unstable state of mind translates to increase in the amount of paranormal activity detected in a place. The device’s functions in collaboration with a C# application, in order to reveal different levels of paranormal activity and how it increases as people’s unstable mental state increases at the same time social conditions become more and more deplorable.
 +
 
 +
[[Image:E1.jpg]]
 +
[[Image:E2.jpg]]
 +
[[Image:E3.jpg]]
 +
[[Image:E4.jpg]]
 +
[[Image:E5.jpg]]
 +
 
 +
Code Arduino:
 +
 
 +
//SQ
 +
 
 +
int photopin = 5;
 +
int motionpin = 6;
 +
int offpin = 3;
 +
int onpin = 4;
 +
 
 +
int switchpin = 2;
 +
 
 +
int speakerpin = 10;
 +
 
 +
int lights[] = {7,8,9,12};
 +
 
 +
//ActivationVars
 +
int registered, activated,action;
 +
int reader;
 +
 
 +
//Controllers
 +
int photovalue;
 +
int motionvalue;
 +
 
 +
//SoundVars
 +
 
 +
int melody[] = {2100,17.32,18.35,19.45,20.6,21.83,23.12,24.5,25.96,
 +
                27.5,29.14,30.87,32.7,34.65,36.71,38.89,41.2,43.65,
 +
                46.25,49,51.91,55,58.27,61.74,65.41,69.3,73.42,77.78,
 +
                82.41,87.31,92.5,98,103.83,110,116.54,123.47,130.81,
 +
                138.59,146.83,155.56,164.81,174.61,185,196,207.65,
 +
                220,233.08,246.94,261.63,277.18,293.66,311.13,329.63,
 +
                349.23,369.99,392,415.3,440,466.16,493.88,523.25,
 +
                554.37,587.33,622.25,659.26,698.46,739.99,783.99,
 +
                830.61,880,932.33,987.77,1046.5,1108.73,1174.66,
 +
                1244.51,1318.51,1396.91,1479.98,1567.98,1661.22,
 +
                1760,1864.66,1975.53,2093,2217.46,2349.32,2489.02,
 +
                2637.02,2793.83,2959.96,3135.96,3322.44,3520,3729.31,
 +
                3951.07,4186.01,4434.92,4698.64,4978.03};
 +
 +
int MC = sizeof(melody);
 +
long tempo = 100;
 +
int pause = 1000;
 +
 
 +
int toneb = 0;
 +
int beat = 0;
 +
long duration  = 0;
 +
int rest_count = 100;
 +
 
 +
 
 +
void setup() {
 +
  pinMode(offpin, OUTPUT);
 +
  pinMode(onpin, OUTPUT);
 +
  pinMode(photopin, INPUT);
 +
  pinMode(switchpin, INPUT);
 +
  pinMode(motionpin, INPUT);
 +
  pinMode(speakerpin, OUTPUT);
 +
  pinMode(lights[0], OUTPUT);
 +
  pinMode(lights[1], OUTPUT);
 +
  pinMode(lights[2], OUTPUT);
 +
  pinMode(lights[3], OUTPUT);
 +
  Serial.begin(9600);
 +
}
 +
 
 +
void loop() {
 +
mySerialRead();
 +
 
 +
  //ACTIONS
 +
 
 +
  if (registered != 1 && activated != 1) {
 +
    Serial.println("ParaDetector@0001mx@555@12EE@Lumalin");
 +
    intermitter(offpin, 100);
 +
  }
 +
 
 +
  if (registered == 1 && activated != 1) {
 +
    intermitter(onpin,250);
 +
    valuesprinter();   
 +
  }
 +
 
 +
  if (activated == 1 && action == 0) {
 +
    valuesprinter();
 +
    intermitter(onpin,50);
 +
  }
 +
 
 +
  if (activated == 1 && action == 1) {
 +
    for (int i=0;i<4;i++) {
 +
      intermitter(lights[i],20);
 +
    }
 +
    playsounds(random(3500));
 +
  }
 +
 
 +
}
 +
 
 +
//FUNCTIONS
 +
 
 +
void playsounds(int durationb) {
 +
  toneb = melody[random(MC)];
 +
    duration = durationb;
 +
    playtoneb();
 +
    delayMicroseconds(pause);
 +
}
 +
 
 +
void dimmer(int pin,int delayer) {
 +
  for (int i=0;i<255;i++) {
 +
    analogWrite(pin, i);
 +
    delay(delayer);
 +
  }
 +
  for (int i=255;i>0;i--) { 
 +
    analogWrite(pin, i);
 +
    delay(delayer); 
 +
  }
 +
  analogWrite(pin, 0);
 +
}
 +
 
 +
void intermitter(int pin,int delayer) {
 +
  digitalWrite(pin, HIGH);
 +
  delay(delayer);
 +
  digitalWrite(pin, LOW);
 +
  delay(delayer);
 +
}
 +
 
 +
void mySerialRead() {
 +
if (Serial.available()>0) {
 +
    reader = Serial.read();
 +
    if (reader == 'O') {
 +
        registered = 0;
 +
        activated = 0;
 +
        action = 0;
 +
      }
 +
    if (registered != 1) {
 +
      if (reader == 'H') {
 +
        registered = 1;
 +
      } 
 +
    }
 +
    if (registered == 1) {
 +
      if (reader == 'A') {
 +
        activated = 1;
 +
        action = 0;
 +
      }
 +
      if (reader == 'P') {
 +
        activated = 0;
 +
        action = 0;
 +
      }
 +
      if (reader == 'Y') {
 +
        activated = 1;
 +
        action = 1;
 +
      }
 +
    } 
 +
  }
 +
}
 +
 
 +
void valuesprinter() {
 +
  //if (digitalRead(switchpin) == HIGH) {
 +
      motionvalue = digitalRead(motionpin);
 +
      photovalue = analogRead(photopin);
 +
      Serial.print("Values");
 +
      Serial.print("@");
 +
      Serial.print(photovalue);
 +
      Serial.print("@");
 +
      Serial.println(motionvalue);
 +
  // }
 +
    //else {
 +
    // Serial.print("Values@NoValue");
 +
    // Serial.print("@");
 +
    // Serial.println(motionvalue);
 +
    //}
 +
}
 +
 
 +
void playtoneb() {
 +
  long elapsed_time = 0;
 +
  if (toneb > 0) { // if this isn't a Rest beat, while the toneb has
 +
    //  played less long than 'duration', pulse speaker HIGH and LOW
 +
    while (elapsed_time < duration) {
 +
 
 +
      digitalWrite(speakerpin,HIGH);
 +
      delayMicroseconds(toneb);
 +
 
 +
      // DOWN
 +
      digitalWrite(speakerpin, LOW);
 +
      delayMicroseconds(toneb);
 +
 
 +
      // Keep track of how long we pulsed
 +
      elapsed_time += (toneb);
 +
    }
 +
  }
 +
  else { // Rest beat; loop times delay
 +
    for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
 +
      delayMicroseconds(duration); 
 +
    }                               
 +
  }                               
 +
}
 +
 
 +
 
 +
 
 +
 
 +
Code C#: (Excerpt)
 +
 
 +
using System;
 +
using System.Collections.Generic;
 +
using System.ComponentModel;
 +
using System.Data;
 +
using System.Drawing;
 +
using System.Linq;
 +
using System.Text;
 +
using System.Windows.Forms;
 +
using System.IO.Ports;
 +
using System.Threading;
 +
using System.IO;
 +
using System.Runtime.InteropServices;
 +
 
 +
namespace ParaDetector_V1
 +
{
 +
    public partial class Form1 : Form
 +
    {
 +
 
 +
       
 +
        bool detected = false, reading = false, success = false, allowcancel = false, playonce = false;
 +
        int portind = 0, currentport = 0, lightvalue = 60, activity = 0;
 +
        string ports = "None", currentportname = "None", value;
 +
        string[] vals = new string[40];
 +
        string linelight = "60";
 +
 
 +
        //Mediaplayer
 +
        private string _command;
 +
        private bool isOpen;
 +
        [DllImport("winmm.dll")]
 +
        private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
 +
        //EndMediaPlayer
 +
 
 +
        //StartPlayer
 +
        void closeplayer()
 +
        {
 +
            _command = "close MediaFile";
 +
            mciSendString(_command, null, 0, IntPtr.Zero);
 +
            isOpen = false;
 +
        }
 +
        public void OpenPlayer(string sFileName)
 +
        {
 +
            _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
 +
            mciSendString(_command, null, 0, IntPtr.Zero);
 +
            isOpen = true;
 +
        }
 +
        public void PlayPlayer(bool loop)
 +
        {
 +
            if (isOpen)
 +
            {
 +
                _command = "play MediaFile";
 +
                if (loop)
 +
                    _command += " REPEAT";
 +
                mciSendString(_command, null, 0, IntPtr.Zero);
 +
            }
 +
        }
 +
        //EndPlayer
 +
        //END
 +
 
 +
 
 +
        public Form1()
 +
        {
 +
            InitializeComponent();
 +
        }
 +
 
 +
        private void Detector_Tick(object sender, EventArgs e)
 +
        {
 +
            string[] ports2 = SerialPort.GetPortNames();
 +
            if (!detected && !reading)
 +
            {
 +
                if (ports2.Length != 0)
 +
                {
 +
                    if (portind < ports2.Length)
 +
                    {
 +
                       
 +
                        ports = ports2[portind];
 +
                        mystatus.Text = ports;
 +
                        myPort.PortName = ports;
 +
                        reading = true;
 +
                        OpenPort();
 +
                        portind++;
 +
 
 +
                    }
 +
                }
 +
                else
 +
                {
 +
                    mystatus.Text = "No Detector Detected";
 +
                }
 +
            }
 +
            if (detected)
 +
            {
 +
                //StreamData
 +
                if (success)
 +
                {
 +
                    success = false;
 +
                    myPort.Write("H");
 +
                    mystatus.Text = "Device Detected";
 +
                    Show();
 +
                    WindowState = FormWindowState.Normal;
 +
                    if (isOpen)
 +
                    {
 +
                        closeplayer();
 +
                    }
 +
                    OpenPlayer(".\\intro.wav");
 +
                    PlayPlayer(false);
 +
                }
 +
                else
 +
                {
 +
                    textBox1.AppendText(value + "\n");
 +
                    activetext.AppendText("Activity Detected: " + activity.ToString() + "\n");
 +
                }
 +
                //Disconnect
 +
                if (currentportname != "None")
 +
                {
 +
                    if (ports2.Length != 0)
 +
                    {
 +
                        if (ports2[currentport] != currentportname)
 +
                        {
 +
                            ForceClose();
 +
                        }
 +
                    }
 +
                    else
 +
                    {
 +
                        ForceClose();
 +
                    }
 +
                }
 +
            }
 +
        }
 +
 
 +
        void ForceClose()
 +
        {
 +
            allowcancel = true;
 +
            Close();
 +
        }
 +
 
 +
        private void myPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
 +
        {
 +
            try
 +
            {
 +
                value = myPort.ReadLine();
 +
                value = value.Trim();
 +
                vals = value.Split('@');
 +
                if (vals[0] == "Values" && vals[1] != "NoValue")
 +
                {
 +
                    int getlightval = Convert.ToInt32(vals[1]);
 +
                    int getmotionval = Convert.ToInt32(vals[2]);
 +
                    if (getlightval < lightvalue)
 +
                    {
 +
                        myPort.Write("A");
 +
                        if (!playonce)
 +
                        {
 +
                            if (isOpen)
 +
                            {
 +
                                closeplayer();
 +
                            }
 +
                            OpenPlayer(".\\paranormal.wav");
 +
                            PlayPlayer(false);
 +
                            playonce = true;
 +
                        }
 +
                        if (getmotionval > 0)
 +
                        {
 +
                            myPort.Write("Y");
 +
                            Random randomer = new Random();
 +
                            activity = lightvalue * randomer.Next(150);
 +
                        }
 +
                    }
 +
                    else
 +
                    {
 +
                        myPort.Write("P");
 +
                        playonce = false;
 +
                    }
 +
                }
 +
                if (vals[0] == "ParaDetector" && vals[1] == "0001mx" && vals[2] == "555" && vals[3] == "12EE" && vals[4] == "Lumalin")
 +
                {
 +
                    if (!detected)
 +
                    {
 +
                        currentport = portind - 1;
 +
                        currentportname = ports;
 +
                        detected = true;
 +
                        reading = true;
 +
                        success = true;
 +
                    }
 +
                }
 +
                else
 +
                {
 +
                    reading = false;
 +
                    myPort.PortName = currentportname;
 +
                }
 +
            }
 +
            catch { }
 +
            finally
 +
            {
 +
                //this.Invoke(new EventHandler(OnDetect));
 +
               
 +
            }
 +
        }
 +
 
 +
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 +
        {
 +
        }
 +
       
 +
           
 +
        void OpenPort()
 +
        {
 +
            try
 +
            {
 +
                myPort.Open();
 +
            }
 +
            catch
 +
            {
 +
                MessageBox.Show("No port detected");
 +
            }
 +
        }
 +
 
 +
        private void Form1_Load(object sender, EventArgs e)
 +
        {
 +
            try
 +
            {
 +
                StreamReader sr = new StreamReader(".\\options.dat");
 +
                linelight = sr.ReadLine();
 +
                lightvalue = Convert.ToInt32(linelight);
 +
                sr.Close();
 +
                lightval.Value = lightvalue;
 +
            }
 +
            catch
 +
            {
 +
            }
 +
        }
 +
 
 +
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 +
        {
 +
            if (!allowcancel)
 +
            {
 +
                Hide();
 +
                e.Cancel = true;
 +
            }
 +
            if (allowcancel == true)
 +
            {
 +
                e.Cancel = false;
 +
                try
 +
                {
 +
                    myPort.Write("O");
 +
                    Thread.Sleep(200);
 +
                    myPort.Close();
 +
                }
 +
                catch
 +
                {
 +
                }
 +
            }
 +
        }
 +
 
 +
        private void button1_Click(object sender, EventArgs e)
 +
        {
 +
            try
 +
            {
 +
                StreamWriter sw = new StreamWriter(".\\paranormal_data.dat");
 +
                sw.WriteLine(value);
 +
                sw.Close();
 +
            }
 +
            catch
 +
            {
 +
            }
 +
 
 +
        }
 +
 
 +
        private void TrayMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 +
        {
 +
 
 +
        }
 +
 
 +
        private void Form1_Activated(object sender, EventArgs e)
 +
        {
 +
           
 +
        }
 +
 
 +
        private void Form1_Resize(object sender, EventArgs e)
 +
        {
 +
            if (FormWindowState.Minimized == WindowState)
 +
                Hide();
 +
        }
 +
 
 +
        private void myTray_DoubleClick(object sender, EventArgs e)
 +
        {
 +
            Show();
 +
            WindowState = FormWindowState.Normal;
 +
        }
 +
 
 +
        private void TrayMenu_Opening(object sender, CancelEventArgs e)
 +
        {
 +
 
 +
        }
 +
 
 +
        private void AllowClose_Click(object sender, EventArgs e)
 +
        {
 +
            allowcancel = true;
 +
            Close();
 +
        }
 +
 
 +
        private void Restore_Click(object sender, EventArgs e)
 +
        {
 +
            Show();
 +
            WindowState = FormWindowState.Normal;
 +
        }
 +
 
 +
        private void lightval_ValueChanged(object sender, EventArgs e)
 +
        {
 +
            lightvalue = lightval.Value;
 +
            try
 +
            {
 +
                StreamWriter SWB = new StreamWriter(".\\options.dat");
 +
                SWB.Write(lightvalue.ToString());
 +
                SWB.Close();
 +
            }
 +
            catch
 +
            {
 +
            }
 +
        }
 +
 
 +
        private void lightval_Scroll(object sender, EventArgs e)
 +
        {
 +
 
 +
        }
 +
 
 +
 
 +
    }
 +
}

Latest revision as of 23:51, 19 March 2010

My name is Simon Quiroz, I am in my fifth year at UCSD which is by the way my last year. I am double majoring in Visual Arts Media with emphasis in computing and theater.

Although I do not consider myself an artistic person overall, I am attracted to the idea of technology as an art form and the ways in which this one manipulates, reshapes or confirms our values and perceptions of reality. Furthermore, technology is what at a great extent impacts the individual and the current society in terms of politics, economics, etc.

I do not have very much experience when it comes to electronics. However, in my short experience I have managed to learn a few computer languages such as C, php, python, perl, etc.

Other interests include cinema and its forms of production and the ways in which we can incorporate different technologies in its ways of production and distribution. Also, I am a co-founder of a production company in which we can incorporate many of this ideas, named Lumalin.

Example1.jpg Example2.jpg Example3.jpg Example4.jpg Example5.jpg

Midterm Proposal:

Although I might change my mind for something else that crosses my mind, I propose, for now, the idea to build a two switch project dedicated to the separation of two camera shoes to mount two cameras for stereography. The project would consist on a rotatory switch that would let one select between a) close and b) spread and the second switch that would execute the movement, action. The camera shoes would be attached to a motor that would separate them or bring them close.

What it'd look like

Look.jpg

Diagram

Diag3.jpg

or

Diag4.jpg


Final Project Version 1.0 (Subject to change without prior notification): Paranormal Events

Currently our socieety faces many issues that have a direct impact in the psychological mind state of the individual. Largely speaking this translates to a big sociological pathos. Having said this, people's emotional instabilty incites the appearance of what can normally be considered by traditional psychiatrists as severe psychological disorders. Nevertheless, these moments of uncertainty and paranoia also create an environment where "supernatural" events occur with more frequency. Using the Arduino technology, taking data from the environment, people's mind states and the internet(whichh largely reflect societal trends) the Arduino will detect and showcase in some form(yet to be discovered) the amount of supernatural events that occur parallel to our immediate reality which we cannot perceive through our normal senses.

Images:

P1.jpg P2.jpg P3.jpg P4.jpg P5.jpg P6.jpg

FINAL:

The aesthetics of this device function in complete contradiction with the ones of a cheap popular culture. Unconcerned with making of this project a pretty, flashy product, its raw image reflects the current mental state of mind of its creator under circumstances of lack of sleep, stress and time created by the mechanisms surrounding him. As a matter of fact, its separation from a shallow aesthetic showcases the harsh reality, everyday events and stressful circumstances to which individuals are subjected to due to current conditions. More and more individuals are in danger to develop an unstable state of mind. This unstable state of mind translates to increase in the amount of paranormal activity detected in a place. The device’s functions in collaboration with a C# application, in order to reveal different levels of paranormal activity and how it increases as people’s unstable mental state increases at the same time social conditions become more and more deplorable.

E1.jpg E2.jpg E3.jpg E4.jpg E5.jpg

Code Arduino:

//SQ

int photopin = 5; int motionpin = 6; int offpin = 3; int onpin = 4;

int switchpin = 2;

int speakerpin = 10;

int lights[] = {7,8,9,12};

//ActivationVars int registered, activated,action; int reader;

//Controllers int photovalue; int motionvalue;

//SoundVars

int melody[] = {2100,17.32,18.35,19.45,20.6,21.83,23.12,24.5,25.96,

               27.5,29.14,30.87,32.7,34.65,36.71,38.89,41.2,43.65,
               46.25,49,51.91,55,58.27,61.74,65.41,69.3,73.42,77.78,
               82.41,87.31,92.5,98,103.83,110,116.54,123.47,130.81,
               138.59,146.83,155.56,164.81,174.61,185,196,207.65,
               220,233.08,246.94,261.63,277.18,293.66,311.13,329.63,
               349.23,369.99,392,415.3,440,466.16,493.88,523.25,
               554.37,587.33,622.25,659.26,698.46,739.99,783.99,
               830.61,880,932.33,987.77,1046.5,1108.73,1174.66,
               1244.51,1318.51,1396.91,1479.98,1567.98,1661.22,
               1760,1864.66,1975.53,2093,2217.46,2349.32,2489.02,
               2637.02,2793.83,2959.96,3135.96,3322.44,3520,3729.31,
               3951.07,4186.01,4434.92,4698.64,4978.03};

int MC = sizeof(melody); long tempo = 100; int pause = 1000;

int toneb = 0; int beat = 0; long duration = 0; int rest_count = 100;


void setup() {

 pinMode(offpin, OUTPUT);
 pinMode(onpin, OUTPUT);
 pinMode(photopin, INPUT);
 pinMode(switchpin, INPUT);
 pinMode(motionpin, INPUT);
 pinMode(speakerpin, OUTPUT);
 pinMode(lights[0], OUTPUT);
 pinMode(lights[1], OUTPUT);
 pinMode(lights[2], OUTPUT);
 pinMode(lights[3], OUTPUT);
 Serial.begin(9600);

}

void loop() {

mySerialRead();
 //ACTIONS
 if (registered != 1 && activated != 1) {
   Serial.println("ParaDetector@0001mx@555@12EE@Lumalin");
   intermitter(offpin, 100);
 }
 if (registered == 1 && activated != 1) {
   intermitter(onpin,250);
   valuesprinter();    
 }
 
 if (activated == 1 && action == 0) {
   valuesprinter();
   intermitter(onpin,50);
 }
 
 if (activated == 1 && action == 1) {
   for (int i=0;i<4;i++) {
     intermitter(lights[i],20);
   }
   playsounds(random(3500));
 }

}

//FUNCTIONS

void playsounds(int durationb) {

 toneb = melody[random(MC)];
   duration = durationb; 
   playtoneb(); 
   delayMicroseconds(pause);

}

void dimmer(int pin,int delayer) {

 for (int i=0;i<255;i++) {
   analogWrite(pin, i);
   delay(delayer);
 }
 for (int i=255;i>0;i--) {  
   analogWrite(pin, i);
   delay(delayer);   
 }
 analogWrite(pin, 0);

}

void intermitter(int pin,int delayer) {

 digitalWrite(pin, HIGH);
 delay(delayer);
 digitalWrite(pin, LOW);
 delay(delayer);

}

void mySerialRead() {

if (Serial.available()>0) {
   reader = Serial.read();
   if (reader == 'O') {
       registered = 0;
       activated = 0;
       action = 0;
     }
   if (registered != 1) {
     if (reader == 'H') {
       registered = 1;
     }  
   }
   if (registered == 1) {
     if (reader == 'A') {
       activated = 1;
       action = 0;
     }
     if (reader == 'P') {
       activated = 0;
       action = 0;
     }
     if (reader == 'Y') {
       activated = 1;
       action = 1; 
     }
   }  
 }

}

void valuesprinter() {

 //if (digitalRead(switchpin) == HIGH) {
     motionvalue = digitalRead(motionpin);
     photovalue = analogRead(photopin);
     Serial.print("Values");
     Serial.print("@");
     Serial.print(photovalue);
     Serial.print("@");
     Serial.println(motionvalue); 
  // }
   //else {
    // Serial.print("Values@NoValue");
    // Serial.print("@");
    // Serial.println(motionvalue);
   //}

}

void playtoneb() {

 long elapsed_time = 0;
 if (toneb > 0) { // if this isn't a Rest beat, while the toneb has 
   //  played less long than 'duration', pulse speaker HIGH and LOW
   while (elapsed_time < duration) {
     digitalWrite(speakerpin,HIGH);
     delayMicroseconds(toneb);
     // DOWN
     digitalWrite(speakerpin, LOW);
     delayMicroseconds(toneb);
     // Keep track of how long we pulsed
     elapsed_time += (toneb);
   } 
 }
 else { // Rest beat; loop times delay
   for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
     delayMicroseconds(duration);  
   }                                
 }                                 

}



Code C#: (Excerpt)

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO.Ports; using System.Threading; using System.IO; using System.Runtime.InteropServices;

namespace ParaDetector_V1 {

   public partial class Form1 : Form
   {


       bool detected = false, reading = false, success = false, allowcancel = false, playonce = false;
       int portind = 0, currentport = 0, lightvalue = 60, activity = 0;
       string ports = "None", currentportname = "None", value;
       string[] vals = new string[40];
       string linelight = "60";
       //Mediaplayer
       private string _command;
       private bool isOpen;
       [DllImport("winmm.dll")]
       private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
       //EndMediaPlayer
       //StartPlayer
       void closeplayer()
       {
           _command = "close MediaFile";
           mciSendString(_command, null, 0, IntPtr.Zero);
           isOpen = false;
       }
       public void OpenPlayer(string sFileName)
       {
           _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
           mciSendString(_command, null, 0, IntPtr.Zero);
           isOpen = true;
       }
       public void PlayPlayer(bool loop)
       {
           if (isOpen)
           {
               _command = "play MediaFile";
               if (loop)
                   _command += " REPEAT";
               mciSendString(_command, null, 0, IntPtr.Zero);
           }
       }
       //EndPlayer
       //END


       public Form1()
       {
           InitializeComponent();
       }
       private void Detector_Tick(object sender, EventArgs e)
       {
           string[] ports2 = SerialPort.GetPortNames();
           if (!detected && !reading)
           {
               if (ports2.Length != 0)
               {
                   if (portind < ports2.Length)
                   {
                       
                       ports = ports2[portind];
                       mystatus.Text = ports;
                       myPort.PortName = ports;
                       reading = true;
                       OpenPort();
                       portind++;
                   }
               }
               else
               {
                   mystatus.Text = "No Detector Detected";
               }
           }
           if (detected)
           {
               //StreamData
               if (success)
               {
                   success = false;
                   myPort.Write("H");
                   mystatus.Text = "Device Detected";
                   Show();
                   WindowState = FormWindowState.Normal;
                   if (isOpen)
                   {
                       closeplayer();
                   }
                   OpenPlayer(".\\intro.wav");
                   PlayPlayer(false);
               }
               else
               {
                   textBox1.AppendText(value + "\n");
                   activetext.AppendText("Activity Detected: " + activity.ToString() + "\n");
               }
               //Disconnect
               if (currentportname != "None")
               {
                   if (ports2.Length != 0)
                   {
                       if (ports2[currentport] != currentportname)
                       {
                           ForceClose();
                       }
                   }
                   else
                   {
                       ForceClose();
                   }
               }
           }
       }
       void ForceClose()
       {
           allowcancel = true;
           Close();
       }
       private void myPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
       {
           try
           {
               value = myPort.ReadLine();
               value = value.Trim();
               vals = value.Split('@');
               if (vals[0] == "Values" && vals[1] != "NoValue")
               {
                   int getlightval = Convert.ToInt32(vals[1]);
                   int getmotionval = Convert.ToInt32(vals[2]);
                   if (getlightval < lightvalue)
                   {
                       myPort.Write("A");
                       if (!playonce)
                       {
                           if (isOpen)
                           {
                               closeplayer();
                           }
                           OpenPlayer(".\\paranormal.wav");
                           PlayPlayer(false);
                           playonce = true;
                       }
                       if (getmotionval > 0)
                       {
                           myPort.Write("Y");
                           Random randomer = new Random();
                           activity = lightvalue * randomer.Next(150);
                       }
                   }
                   else
                   {
                       myPort.Write("P");
                       playonce = false;
                   }
               }
               if (vals[0] == "ParaDetector" && vals[1] == "0001mx" && vals[2] == "555" && vals[3] == "12EE" && vals[4] == "Lumalin")
               {
                   if (!detected)
                   {
                       currentport = portind - 1;
                       currentportname = ports;
                       detected = true;
                       reading = true;
                       success = true;
                   }
               }
               else
               {
                   reading = false;
                   myPort.PortName = currentportname;
               }
           }
           catch { }
           finally
           {
               //this.Invoke(new EventHandler(OnDetect));
               
           }
       }
       private void Form1_FormClosed(object sender, FormClosedEventArgs e)
       {
       }
       
           
       void OpenPort()
       {
           try
           {
               myPort.Open();
           }
           catch
           {
               MessageBox.Show("No port detected");
           }
       }
       private void Form1_Load(object sender, EventArgs e)
       {
           try
           {
               StreamReader sr = new StreamReader(".\\options.dat");
               linelight = sr.ReadLine();
               lightvalue = Convert.ToInt32(linelight);
               sr.Close();
               lightval.Value = lightvalue;
           }
           catch
           {
           }
       }
       private void Form1_FormClosing(object sender, FormClosingEventArgs e)
       {
           if (!allowcancel)
           {
               Hide();
               e.Cancel = true;
           }
           if (allowcancel == true)
           {
               e.Cancel = false;
               try
               {
                   myPort.Write("O");
                   Thread.Sleep(200);
                   myPort.Close();
               }
               catch
               {
               }
           }
       }
       private void button1_Click(object sender, EventArgs e)
       {
           try
           {
               StreamWriter sw = new StreamWriter(".\\paranormal_data.dat");
               sw.WriteLine(value);
               sw.Close();
           }
           catch
           {
           }
       }
       private void TrayMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
       {
       }
       private void Form1_Activated(object sender, EventArgs e)
       {
           
       }
       private void Form1_Resize(object sender, EventArgs e)
       {
           if (FormWindowState.Minimized == WindowState)
               Hide();
       }
       private void myTray_DoubleClick(object sender, EventArgs e)
       {
           Show();
           WindowState = FormWindowState.Normal;
       }
       private void TrayMenu_Opening(object sender, CancelEventArgs e)
       {
       }
       private void AllowClose_Click(object sender, EventArgs e)
       {
           allowcancel = true;
           Close();
       }
       private void Restore_Click(object sender, EventArgs e)
       {
           Show();
           WindowState = FormWindowState.Normal;
       }
       private void lightval_ValueChanged(object sender, EventArgs e)
       {
           lightvalue = lightval.Value;
           try
           {
               StreamWriter SWB = new StreamWriter(".\\options.dat");
               SWB.Write(lightvalue.ToString());
               SWB.Close();
           }
           catch
           {
           }
       }
       private void lightval_Scroll(object sender, EventArgs e)
       {
       }


   }

}