I am experiencing flakey UTouch operation on my 2560mega R3 and 3.2" display..sometimes works perfect, but usually no touch working..I am chasing this problem down in the various Utouch files and i found a bit operation i cannot find any documentation on.. data <<= 1; what does this mean..is this just a typo error.. ??
it is in the Utouch file HW_AVR.inc line 26..its in the other hardware .inc files too.. (PIC and ARM)..
thanks for any help--
Whatever expression comes before that snippet, is going to have it's bits shifted 1 place to the left. (effectively it means the same as * 2 )
When this happens, is it right after you just uploaded a sketch or some time after?
Henning likes to write his code like this.
while (myTouch.dataAvailable());
myTouch.read();
This unfortunately doesn't work until the arduino is reset, so you cant touch the screen until then. To fix this, simply make that while into an if and it should fix your problem.
Note there may be more lines that that in bigger sketches.
while (myTouch.dataAvailable());
myTouch.read();
This unfortunately doesn't work until the arduino is reset, so you cant touch the screen until then. To fix this, simply make that while into an if and it should fix your problem.
And remove the erroneous semicolon on the first of those lines.
Sorry, I know it's not even your code. I'm just being a pedant ![]()
KenF:
Whatever expression comes before that snippet, is going to have it's bits shifted 1 place to the left. (effectively it means the same as * 2 )
What does the = do ?
i dont know what the = does..that is in fact my question to the forum.. i removed the = and the function results are totally different and not working.. but with it in there, the results are random..sometimes works great but usually no good..i think it is a typo error.. i was hoping someone could confirm that..
here is the entire function:
word UTouch::touch_ReadData()
{
word data = 0;
for(byte count=0; count<12; count++)
{
data <<= 1;
digitalWrite(T_CLK, HIGH);
digitalWrite(T_CLK, LOW);
if (digitalRead(T_DOUT))
data++;
}
return(data);
UKHeliBob:
What does the = do ?
In this case pretty much nothing. It just makes it an assignment, along the lines of += or *= So within this context, it's pointless, yet harmless.
if its harmless, then why(like i said) if i take out the = sign, the results are totally different..
i think it is mis-written statement.. but hey.. what do i know..
Actually the = does do something important.
Consider this sketch and its results.
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
word data = 0;
for(byte i=0;i<12;i++)
{
data <<= 1;
data++; // if digitalRead(T_DOUT) is always true
Serial.println(data); //print out the possible touch range
}
}
void loop() {
// put your main code here, to run repeatedly:
}
1
3
7
15
31
63
127
255
511
1023
2047
4095 -> maximum touch range
0 is the minimum range, but 1 is the minimum touch range.
If you take out the =, then the most it will return is 12. on a scale from 1 - 4096.
Consider this a bit version of the map() function
thankyou..
data <<= 1;
I'm sorry, but I still can't grasp this. Can you explain in words what this does and how it does it ?
I don't fully understand it either, but this is all I got so far.
These displays send out pulses depending on where you touch the screen.
What Henning has done, is essentially made a map function to convert those collected pulses into a usable range (0 - 4096). With this, he can determine the touched X and Y coordinates.