need some help

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jinjin12
 
Posts: 8
Joined: Sun Sep 26, 2010 9:23 pm

need some help

Post by jinjin12 »

so i am trying to build a arduino that uses photoresistors to move the mouse, i am using aac keys as the gobetween. now i have a problem, i want to move the arduino depending on the resistance of the photoresistor, here's a portion of my code, part of void loop(), where there is the problem.

Code:

Serial.print("\033,move, analogRead(photosensorPin)/20, 0.");





i am trying to move the mouse to the right x-coordinate depending on the value of the photosensor pin, however the problem is that since analogRead(photosensorPin)/20 is inside quotations, it read it a string, and does not take the value. however, i need the x coord aka analogRead(photosensorPin)/20 to be inside quotations for it to work since it has to adhere to this format:
Code:

<SERIAL-MARKER><esc>,move,+5,0. //Moves the mouse cursor 5 pixels to the right.




anyone knows a way to solve this problem? to make the software read the value of the function inside quotations and not take it as a literal? anyone tried to use aakeys and arduino to use it as a mouse before and have encountered this?

jinjin12
 
Posts: 8
Joined: Sun Sep 26, 2010 9:23 pm

Re: need some help

Post by jinjin12 »

i found a solution, but it's slow, i was wndering if anyone knew of a fast way;

here's my solution:

Code: Select all

 Serial.print("\033, move,");
  Serial.print(val);
  Serial.print (", 0.");
 
in c++ you could do something like

Code: Select all

 cout << "hehie" << val << "ok";
it is possible to do the same in the arduino sofware?

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: need some help

Post by mtbf0 »

it's not that slow. probably no slower than using cout if it were available.

User avatar
chatham
 
Posts: 144
Joined: Thu Feb 04, 2010 2:30 am

Re: need some help

Post by chatham »

Agreed. Based on my knowledge of how compilers usually work, and how the USART (the hardware that does the serial communication on the Arduino) works, doing Serial.print(ALL THE INFORMATION) isn't going to be any faster than doing it in multiple lines.

Basically, the Arduino is screaming along at 16MHz, but the USART is only able to send out commands as fast as the bitrate will allow. Which is relatively pretty dang slow. And it transmits those commands one letter at a time, one bit at a time, so I'm going to assume that Serial.print() just copies the first character from the string you're transmitting to the outgoing serial register, waits for that to transmit, then writes the next character to the register, and so on until it hits the end of the line. So the overhead for the Serial.print() function is minimal; any slowness is coming from the fact that the USART is slow as hell.

Basically, the only thing you can do is to push your baud rate (set in Serial.begin()) as high as you can, and you should see the speed differences there.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”