How can i convert textbox value to integer?

I’m trying to control stepper motor by arduino and processing. I want to control the step value of motor which I entered the interface textbox but it doesnt work and program give error always.
Arduino Code

#include <AFMotor.h>
AF_Stepper motor(200, 2);
int i=0;
void setup() {

void loop(){
if(Serial.available() > 0) {
   int value  = Serial.parseInt();
char stepState =;
if(stepState == 'a'){

motor.step(value, FORWARD, SINGLE);

if(stepState == 'b'){

motor.step(value, BACKWARD, SINGLE);



Processing Code

import controlP5.*;
import processing.serial.*;
Serial myPort;
boolean bas=false;
boolean acibas=true;
int rectX, rectY; // Position of square button
int rectSize = 120;     // Diameter of rect
color rectColor, baseColor;
color rectHighlight;
color currentColor;
boolean rectOver = false;
boolean rectOver2 = false;
int yon=0;
ControlP5 cp5;

void setup() {
  size(600, 550);
  rectColor = color(0);
  rectX = 350;
  rectY = 80;
  rect(rectX, rectY, rectSize, rectSize);
  rect(130, 80, rectSize, rectSize);
  cp5 = new ControlP5(this);
  cp5.addTextfield("ANGLE").setPosition(75, 300).setSize(200, 80).setFont(createFont("arial",32)).setAutoClear(false);

  text("C-CW", 130, 60);
  text("CW", 350, 60);
  cp5.addBang("SUBMIT").setPosition(325, 300).setFont(createFont("arial",32)).setSize(160, 80); 
  myPort = new Serial(this, "COM3", 9600);

void draw() {
  int adim;
  String Sadim = cp5.get(Textfield.class,"ANGLE").getText();
  adim = Integer.parseInt(Sadim);
  update(mouseX, mouseY);

void controlEvent(ControlEvent deger) {
  if(deger.isAssignableFrom(Textfield.class)) {
    println("controlEvent: accessing a string from controller '"+deger.getName()+"': "

void update(int x, int y) {
  if ( overRect(rectX, rectY, rectSize, rectSize) ) {
    rectOver = true;
    rectOver2 = false;
  } else if( overRect(130, 80, rectSize, rectSize) ){
    rectOver2 = true;
    rectOver = false;
  } else {
   rectOver = rectOver2 = false;

void mousePressed() {
  if (rectOver) {
  }else if (rectOver2) {

boolean overRect(int x, int y, int width, int height)  {
  if (mouseX >= x && mouseX <= x+width && 
      mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;

Please describe what you want to see and what the program is doing instead. If you have an error, added to your conversation and also tell us what line gets highlighted in your code if you get an error, that is. Notice this is an arduino, and it is very unlikely people will try to setup an arduino to test your code.


The main issue with your code is this line:

adim = Integer.parseInt(Sadim);

At least, that’s what I can tell from the Processing-side of things. I tried figuring out what the variable “Sadim” actually contained, but it didn’t seem to have anything being stored in it. So if you’re trying to parseInt(something that doesn't really exist) that’s not going to work.