Skip to main content
Auto format code
Source Link
per1234
  • 4.3k
  • 2
  • 24
  • 44

Interface Processing with Arduino to operate a servo by MouseX.

I want to make a servo change its angle using my mouse. When I move mouse horizontally the servo should change its angle correspondingly. This is the sketch I wrote, unfortunately the servo doesn't move one bit. HELP.

Processing Code:

// Processing Code   
import processing.serial.*;
Serial port;
void setup() {
  size(256, 150);
  println("Available serial ports:");
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());
  port = new Serial(this, Serial.list()[1], 9600);
 }

void draw() {
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
    stroke(i);
    line(i, 0, i, height);
  }
  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
  println(mouseX);
}

//Arduino Arduino Code:

#include <Servo.h>
Servo myservo;
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the servo:
  myservo.attach(10);
 }
void loop() {
  byte pos;
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    pos = Serial.read();
    // set the angle of the servo:
    myservo.write(map(pos, 0, 255, 0, 180));
  }
}

Interface Processing with Arduino to operate a servo by MouseX.

I want to make a servo change its angle using my mouse. When I move mouse horizontally the servo should change its angle correspondingly. This is the sketch I wrote, unfortunately the servo doesn't move one bit. HELP.

// Processing Code   
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
 }

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, height);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
println(mouseX);
}

//Arduino Code

#include <Servo.h>
Servo myservo;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the servo:
myservo.attach(10);
 }
void loop() {
byte pos;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
pos = Serial.read();
// set the angle of the servo:
myservo.write(map(pos,0,255,0,180));
 }
}

Interface Processing with Arduino to operate a servo by MouseX

I want to make a servo change its angle using my mouse. When I move mouse horizontally the servo should change its angle correspondingly. This is the sketch I wrote, unfortunately the servo doesn't move one bit. HELP.

Processing Code:

import processing.serial.*;
Serial port;
void setup() {
  size(256, 150);
  println("Available serial ports:");
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());
  port = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
    stroke(i);
    line(i, 0, i, height);
  }
  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
  println(mouseX);
}

Arduino Code:

#include <Servo.h>
Servo myservo;
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the servo:
  myservo.attach(10);
}
void loop() {
  byte pos;
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    pos = Serial.read();
    // set the angle of the servo:
    myservo.write(map(pos, 0, 255, 0, 180));
  }
}
Post Closed as "Needs details or clarity" by CommunityBot, per1234, Michel Keijzers, gre_gor, KIIV
added 226 characters in body
Source Link

Interface Processing with Arduino to operate a servo by MouseX. Processing sends in bytes

I want to make a servo change its angle using my mouse. When I move mouse horizontally the servo should change its angle correspondingly. This is the sketch I wrote, unfortunately the servo doesn't move one bit. HELP.

// Processing Code   
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
 }

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, height);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
println(mouseX);
}

//Arduino Code

#include <Servo.h>
Servo myservo;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the servo:
myservo.attach(10);
 }
void loop() {
byte pos;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
pos = Serial.read();
// set the angle of the servo:
myservo.write(map(pos,0,255,0,180));
 }
}

Interface Processing with Arduino to operate a servo by MouseX. Processing sends in bytes

// Processing Code   
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
 }

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, height);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
println(mouseX);
}

//Arduino Code

#include <Servo.h>
Servo myservo;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the servo:
myservo.attach(10);
 }
void loop() {
byte pos;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
pos = Serial.read();
// set the angle of the servo:
myservo.write(map(pos,0,255,0,180));
 }
}

Interface Processing with Arduino to operate a servo by MouseX.

I want to make a servo change its angle using my mouse. When I move mouse horizontally the servo should change its angle correspondingly. This is the sketch I wrote, unfortunately the servo doesn't move one bit. HELP.

// Processing Code   
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
 }

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, height);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
println(mouseX);
}

//Arduino Code

#include <Servo.h>
Servo myservo;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the servo:
myservo.attach(10);
 }
void loop() {
byte pos;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
pos = Serial.read();
// set the angle of the servo:
myservo.write(map(pos,0,255,0,180));
 }
}
Source Link

Interface Processing with Arduino to operate a servo by MouseX. Processing sends in bytes

// Processing Code   
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
 }

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, height);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
println(mouseX);
}

//Arduino Code

#include <Servo.h>
Servo myservo;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the servo:
myservo.attach(10);
 }
void loop() {
byte pos;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
pos = Serial.read();
// set the angle of the servo:
myservo.write(map(pos,0,255,0,180));
 }
}