I am serializing a key stroke in processing and looking for the serialized data in my arduino sketch. When the key (r) is pressed the motor turns to the right for a set amount of time for each key press. Everything is working, however, after what seems to be a random time the serial stops reading and getting the data that processing is trying to send. I have noooo idea why. am i sending too much data too fast? is the arduino not getting enough power (powered by an IMac usb port)? I just don't know.
using an Arduino UNO,
using a SpringRC SM-S4303R servo motor...
this is my processing sketch:
import processing.serial.*;
Serial port;
int c=0;
void setup() {
size(600,600);
println(Serial.list());
port = new Serial(this, Serial.list()[5], 9600);
}
void keyPressed() {
String s = "0";
if (key == 'r') {
s = "1\n";
port.write(s);
}
}
void draw() {
}
and this is my arduino sketch:
#include <Servo.h>
Servo servoLeft;
void setup() {
Serial.begin(9600);
servoLeft.attach(13);
}
void loop() {
while (Serial.available() > 0){
int right = Serial.parseInt();
Serial.print(right);
if (Serial.read() == '\n') {
servoLeft.write(180);
delay(50); //time for the servo to move
servoLeft.write(90);
}
}
}
Thanks for all your help!!