Hi everyone, Im trying to move my mouse with arduino leonardo with python code. As you know there is X and Y axis for mouse movements. Python and Arduino communicates with serial band. which is "Serial.readBytes();" There is a question on me. i can send the values which is like x = 5 y = 5 because those are positive values. But when i try to send negative values like x = -5 etc. it fails. i've got some value error like "ValueError: byte must be in range(0, 256)" arduino accepts only 0,256 value so how can i receive negative values ?
According to Mouse.move() - Arduino Reference the Mouse.move() method takes the X and Y parameters are two signed integers. You are wrongly supplying just two bytes/chars. Assuming we are talking of the same library as you, you need to read two strings from the input and convert them to signed integer values.
Your first job is to define the format of the input. I would use to integers as decimal strings and separate them with a comma. For example, one posssiblility, something like "12,-5". Then split the input into the two separate strings and use atoi() to convert them to signed integers.
skyvan:
According to Mouse.move() - Arduino Reference the Mouse.move() method takes the X and Y parameters are two signed integers. You are wrongly supplying just two bytes/chars. Assuming we are talking of the same library as you, you need to read two strings from the input and convert them to signed integer values.
Your first job is to define the format of the input. I would use to integers as decimal strings and separate them with a comma. For example, one posssiblility, something like "12,-5". Then split the input into the two separate strings and use atoi() to convert them to signed integers.
First of all thank your for commant. I'ts hard to get it for me , I need to make a converter which is converting my int values to signed ints then i'll convert them to byte and use them like Mouse.move(x,y)
x = converted signed int, converted to byte, and y is same do i correct ? if not can you explain more simple please
@phantomninja
Your duplicate post in another forum section has been deleted
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a timeout from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.