# Stuck with SIZE command

**URL:** https://discourse.processing.org/t/stuck-with-size-command/4441
**Category:** Electronics (Arduino, etc.)
**Created:** [October 13, 2018, 9:15pm UTC](https://discourse.processing.org/t/stuck-with-size-command/4441 "2018-10-13T21:15:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sljivan](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sljivan](https://discourse.processing.org/u/sljivan)
#### Post date: [October 13, 2018, 9:15pm UTC](https://discourse.processing.org/t/stuck-with-size-command/4441/1 "2018-10-13T21:15:33Z")

</div>

Hello guys.  
I am trying to control my servo with Processing. And it actually works.  
But I wanted to fool around with the code a bit to get a grip off it, and I started changing a [tutorial code](https://www.arduino.cc/en/Tutorial/Dimmer) a bit.  
And I ran into a wall which I can not figure out.

Originally window size is (256x150) and I have tryed to change it. When I expanded or shrunk the Y axis, it was all good.  
But when I expanded the X axis the problems occurred whether I was shrunk it or expanded it. It gave me a border inside the window, and when I crossed it with mouse, the servo jumped back to 0 position, telling me that it mouseX read a 0 again, though I haven’t reached the end of my window.

This is my code:

> [@](#):
>
> import processing.serial.\*;  
> Serial port;
> 
> void setup() {  
> size( **300** , 300);
> 
> ```
> println("Available serial ports:");
> // if using Processing 2.1 or later, use Serial.printArray()
> println(Serial.list());
> 
> port = new Serial(this, Serial.list()[1], 9600);
> 
> ```
> 
> }
> 
> void draw() {  
> // draw a gradient from black to white  
> for (int i = 0; i \< 300; i++) {  
> // color  
> stroke(i);  
> // x1 y1 x2 y2  
> line(i, 0, i, **300** );  
> }

I have altered my Arduino code, and it works OK. It seems that I ran into some sort of boundary in Processing.  
Anyone knows what I did wrong?

Picture depicts, how my window looks like.  
 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/707c7d4d82cd247ede52253fe6abe48fcc6e1776.gif)

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [October 13, 2018, 10:21pm UTC](https://discourse.processing.org/t/stuck-with-size-command/4441/2 "2018-10-13T22:21:12Z")

</div>

The problem has got to be something related to the fact that you are using a single byte to communicate. With one byte, the values that byte can represent range from 0 (0x00000000) to 255 (0x111111111). If you try to store more than 255 in a byte, it wraps around, back to 0, because it can only copy the lowest 8 bits!

---

<div class="post-metadata">

### Author: ![sljivan](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sljivan](https://discourse.processing.org/u/sljivan)
#### Post date: [October 13, 2018, 10:33pm UTC](https://discourse.processing.org/t/stuck-with-size-command/4441/3 "2018-10-13T22:33:38Z")

</div>

@TfGuy44 thank you for your reply. I was so excited about your anser that I tried it immediately.  
I have done the following:

> [@](#):
>
> import processing.serial.\*;  
> Serial port;  
> **_int mousepos;_**

and also:

> [@](#):
>
> mousepos=mouseX;  
> port.write(mousepos);

so I have made it an integer. Still, I face the same problem. 😓

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [October 13, 2018, 10:38pm UTC](https://discourse.processing.org/t/stuck-with-size-command/4441/4 "2018-10-13T22:38:16Z")

</div>

😔

You should be able to write ints.

[https://processing.org/reference/libraries/serial/Serial\_write\_.html](https://processing.org/reference/libraries/serial/Serial_write_.html)

Can we see your full code?

---

<div class="post-metadata">

### Author: ![sljivan](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sljivan](https://discourse.processing.org/u/sljivan)
#### Post date: [October 13, 2018, 10:44pm UTC](https://discourse.processing.org/t/stuck-with-size-command/4441/5 "2018-10-13T22:44:58Z")

</div>

there it is:

> [@](#):
>
> import processing.serial.\*;  
> Serial port;  
> int mousepos;
> 
> void setup() {  
> size(300, 150);
> 
> ```
> println("Available serial ports:");
> // if using Processing 2.1 or later, use Serial.printArray()
> println(Serial.list());
> 
> // Uses the first port in this list (number 0). Change this to select the port
> // corresponding to your Arduino board. The last parameter (e.g. 9600) is the
> // speed of the communication. It has to correspond to the value passed to
> // Serial.begin() in your Arduino sketch.
> port = new Serial(this, Serial.list()[1], 9600);
> 
> // If you know the name of the port used by the Arduino board, you can specify
> // it directly like this.
> //port = new Serial(this, "COM1", 9600);
> 
> ```
> 
> }
> 
> void draw() {  
> // draw a gradient from black to white  
> for (int i = 0; i \< 300; i++) {  
> // color  
> stroke(i);  
> // x1 y1 x2 y2  
> line(i, 0, i, 150);  
> }
> 
> ```
> // write the current X-position of the mouse to the serial port as
> // a single byte
> mousepos=mouseX;
> port.write(mousepos);
> 
> ```
> 
> }

on the arduino side I have also turned all variables into integers.  
@TfGuy44 - Thanks man!
