int value = Fadebar.Value * 10;
Why isn't the range of the Fadebar simply 0 to 255? Then, there would be no reason to multiply by 10.
int stringToNumber(String thisString) {
int i, value, length;
length = thisString.length();
char new[(length)];
for(i=0; i<length; i++) {
new[i] = thisString.charAt(i);
}
value = atoi(blah);
return value;
}
Extract the data into an array called new. Then, convert the data in blah to an int, and return that value. blah isn't even defined.
The String class, which has documented issues, has a toInt() method. Why aren't you using it?
The String class has a toCharArray() method. Why aren't you using it?
Why doesnt work?
It does work. As a matter of fact, it's working perfectly. It just, clearly, doesn't do what you want, or expect, it to. So, what does it do? What do you expect it to do? How do those differ?
1. How can i send an int value through an serialport?
How is the Arduino supposed to know when the integer value, converted to a string, has been fully received? You are sending an int, now, but the Arduino has no way of knowing when the whole string has arrived. Supposed that Fadebar has a value of 14. You multiply that by 10 (why is a mystery) and send 140, as '1', '4', '0'.
Now some data arrives at the Arduino. Likely, just the '1'.
That clearly isn't a NULL (which will never be sent), so you add it to the String. Then, sometime later, the '4' arrives, so you add it to the String. Later, the '0' arrives, so you add it to the String.
No NULL ever gets sent, so, your String just keeps filling up. Clearly, you need to send something to indicate that the end of the packet has arrived, and you need to read the data until that end of packet marker arrives. That end of packet marker can NOT be a NULL.
2. How can i print my fadeValue (Serial.print(fadeValue)) ? It appears "Serial Port "COM6" is already in use...".
COM6 is in use by your C# application, which, believe it or not, is perfectly capable of reading serial data, too. So, the Arduino can send serial data back.
3. Can i debug arduino code?
Yes, but it is far better to not write buggy code in the first place.