Servo motor + Arduino + Processing

edited March 2014 in Arduino

Hello,

I am trying to make Servo motor work using processing 1.0, I did everything what is necessary already, uploaded firmata code to the arduino board and it works perfectly with processing 2.0, the code where I can control servo motor with mouse, but when I put the code to the processing 1.0 the controlling becomes very poor. So I thought to write the code where I can control the servo motor without the mouse, but have no Idea how. I would appreciate any tips.

The code for controlling the motor with mouse is:

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

void setup() {
  size(512, 200);

  // Prints out the available serial ports.
  println(Arduino.list());

  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, Arduino.list()[0], 57600);

  // Alternatively, use the name of the serial port corresponding to your
  // Arduino (in double-quotes), as in the following line.
  //arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
}

void draw() {
  background(constrain(mouseX / 2, 0, 180));

  // Output analog values (PWM waves) to digital pins 9 and 11.
  // Note that only certain Arduino pins support analog output (PWM).
  // See the documentation for your board for details.
  arduino.analogWrite(9, constrain(mouseX / 2, 0, 180));
  arduino.analogWrite(11, constrain(180 - mouseX / 2, 0, 180));
}

But what should be the void draw code just to tell the motor how much to move by the code, not the mouse.

Thank you Ignas

Tagged:

Answers

Sign In or Register to comment.