I am having trouble getting servos attached to a TLC5940 to respond to serial input from Processing (Simple Write sketch).
I have tried setting a variable as int or char, and I can see the Tx light going off on the Arduino board, but no movement.
The servo will respond to tlc_setServo command without serial input. Thanks in advance for any advice.
[arduino code]
#include "Tlc5940.h"
#include "tlc_servos.h"
int numberOfServos = 1; //how many servos on the chain?
void setup(){
Serial.begin(9600);
tlc_initServos(); // Note: this will drop the PWM freqency down to 50Hz.
}
void loop(){
while (Serial.available() >0) {
int v = Serial.read();
tlc_setServo(1, v);
Tlc.update();
delay(200);
}
}
[/arduino code]
[Processing code]
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
String portName = Serial.list()[3];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(255);
if (mouseOverRect() == true) { // If mouse is over square,
fill(204); // change color and
myPort.write("15");
println('H'); // send an H to indicate mouse is over square
}
rect(50, 50, 100, 100); // Draw a square
}
boolean mouseOverRect() { // Test if mouse is over square
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}
[/Processing code]