Trouble with arduino/processing

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.

Range yes, but also the int

I would have to say the 47,60 in the range variable is something to look at, but it should be noted that you are sending an INT via serial and it does not look like you are taking it apart (into bytes) first. If you are only using a 0-100 range (or even a 0-255 range), I would use a byte for your “servo” variable instead.

Thans for the reply. I’ve

Thans for the reply. I’ve given using byte instead of int a shot, but had no luck. The 47,60 range variable was origeonally 0,100, but I changed it to see how smooth it was within those values. It’s just the range for the knob. I’ve also tried changing the port settings (parity etc.), but it didn’t help, so I set it back. Do you have any idea how to monitor serial activity? I was just wondering if it’s possible to use a bit of software to compare what the arduino serial terminal and the processing sketch were sending, so I could have a better guess as to what’s wrong.