 
  Assignment 13
     
     #include‹SoftwareSerial.h›
  
#define BUTTON PA3
#define x PA2
#define y PA3
#define btn PA4
#define val 0
#define tx PA0
#define rx PA1
SoftwareSerial ser(rx, tx);
void setup() {
  // put your setup code here, to run once:
ser.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
ser.print("Switch:  ");
  ser.print(digitalRead(btn));
  ser.print("\n");
  ser.print("X-axis: ");
  ser.print(analogRead(x))/100;
  ser.print("\n");
  ser.print("Y-axis: ");
  ser.println(analogRead(y)/100);
  ser.print("\n\n");
  delay(500);
}
     
    
    
    
 /**
 * Simple Read
 * 
 * Read data from the serial port and change the color of a rectangle
 * when a switch connected to a Wiring or Arduino board is pressed and released.
 * This example works with the Wiring / Arduino program that follows below.
 */
import processing.serial.*;
Serial myPort;  // Create object from Serial class
char val;      // Data received from the serial port
int x , y , btn;
void setup() 
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}
void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.readChar();         // read it and store it in val
    if (val == 'x')
  {
    if ( myPort.available() > 0) {  // If data is available,
    x = myPort.read();
    }
    
    
  }
  
    if (val == 'y')
  {
    if ( myPort.available() > 0) {  // If data is available,
    y = myPort.read();
    }
    
    
  }
  
    if (val == 'b')
  {
    if ( myPort.available() > 0) {  // If data is available,
    btn = myPort.read();
    }
    
    
  }
  
  }
  
  
  
  
  
  background(x);             // Set background to white
  if (btn == 1) {              // If the serial value is 0,
    fill(y);                   // set fill to black
  } 
  else {                       // If the serial value is not 0,
    fill(204-y);                 // set fill to light gray
  }
  rect(50, 50, 100, 100);
}
        
x=10
y=10
import time
import pyautogui
import serial
ser = serial.Serial('/dev/ttyUSB0')
kk=0
line1=0
line2=0
line3=0
while 1 :
	line = ser.read()
	print "---------"
	if line == 'x' :
		line1 = int(ser.readline())
		#x=x+line1
		x=line1
		x=x*5
		kk=0
	elif line == 'y' : 
		
		line2 = int(ser.readline())
		y=line2
		y=y*5
		#y=y+line1
		kk=1
	elif line == 'b' : 
		line3 = ser.readline()
		if line3 == '1' :
			pyautogui.click(x,y)
	if kk ==1 :
		pyautogui.moveTo(x, y)
	#time.sleep(1);
	print "btn = " , line1 , " x = " ,  line2 , " y = " , line3