36 lines
775 B
Text
36 lines
775 B
Text
|
|
import cc.arduino.*;
|
||
|
|
import processing.serial.*;
|
||
|
|
|
||
|
|
Arduino arduino;
|
||
|
|
int servo1Pin = 9; // Control pin for servo motor
|
||
|
|
int servo2Pin = 10; // Control pin for servo motor
|
||
|
|
int servo3Pin = 11; // Control pin for servo motor
|
||
|
|
int penposn;
|
||
|
|
|
||
|
|
void setup(){
|
||
|
|
|
||
|
|
size (180, 180);
|
||
|
|
background(255);
|
||
|
|
arduino = new Arduino(this, Arduino.list()[1]);
|
||
|
|
arduino.pinMode(servo1Pin, Arduino.OUTPUT);
|
||
|
|
arduino.pinMode(servo2Pin, Arduino.OUTPUT);
|
||
|
|
arduino.pinMode(servo3Pin, Arduino.OUTPUT);
|
||
|
|
arduino.analogWrite(servo3Pin, 50); // the servo moves to the horizontal location of the mouse
|
||
|
|
penposn = 50;
|
||
|
|
}
|
||
|
|
|
||
|
|
void draw(){
|
||
|
|
|
||
|
|
arduino.analogWrite(servo1Pin, mouseX);
|
||
|
|
arduino.analogWrite(servo2Pin, mouseY);
|
||
|
|
if (mousePressed)
|
||
|
|
{
|
||
|
|
penposn = 23;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{penposn = 50;}
|
||
|
|
|
||
|
|
arduino.analogWrite(servo3Pin, penposn);
|
||
|
|
}
|
||
|
|
|