I've been trying to teach myself Arduino and Processing, and I've been hitting a few problems. I had a previous post Here, but it was getting a bit crowded with code, so I thought I'd start a new post.
I've been trying to send an integer value from Processing to Arduino via serial, to set the brightness of the on-board LED. The arduino sketch works, and I've tested it with the serial monitor. When I try to control it with my Processing sketch, though, it only adjusts between 47-60 rather than the full range of 0-100. I'm using the ControlP5 and serial libraries in processing, and the softPWM library on the arduino to PWM the onboard LED.
Code:
Arduino;
#include <SoftPWM.h>
#include <SoftPWM_timer.h>
int LED = 13;
int dim = 0;
void setup() {
Serial.begin(2400);
SoftPWMBegin();
SoftPWMSet(LED,0);
}
void loop() {
while (Serial.available() > 0) {
int dim = Serial.parseInt();
if (Serial.read() == '\n') {
SoftPWMSetPercent(LED,dim);
}
}
}
Processing (The reason the value is called servo is because I'd intended to control a servo, but didn't get round to it);
import processing.serial.*;
Serial myPort;
import controlP5.*;
ControlP5 cp5;
int Servo = 0;
int out = 0;
Knob controller;
void setup() {
size (200,200);
myPort = new Serial(this, "COM6", 2400);
smooth();
noStroke();
cp5 = new ControlP5(this);
controller = cp5.addKnob("Servo")
.setRange(47,60)
.setValue(0)
.setPosition(50,50)
.setRadius(50)
.setDragDirection(Knob.HORIZONTAL)
;
}
void draw() {
background(5);
myPort.write(Servo);
delay(15);
myPort.write('\n');
}
Any Ideas?
PS; can the arduino provide MIDI over USB?
Thanks in advance.