Skip to content

Commit

Permalink
modify example code so it's easier for people to modify the touch han…
Browse files Browse the repository at this point in the history
…dler on the fly
  • Loading branch information
gfwilliams committed May 7, 2014
1 parent a5c3374 commit 98e231f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions devices/Touchscreen.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ Using the touchscreen is as easy as writing ```require("Touchscreen").connect( .
The following example draws a rectangle at each point that is reported when you drag your finger.

```
require("Touchscreen").connect(function(x,y) {
function onTouch(x,y) {
if (x!==undefined)
LCD.fillRect(x-1,y-1,x+1,y+1);
});
}
require("Touchscreen").connect(onTouch);
```

In most cases you'll want to know when the user's finger was first pressed. You can do this by remembering when the user last lifted their finger. The following example shows how to draw lines - note that it uses ```moveTo``` when the user first presses their finger.
Expand All @@ -23,7 +25,8 @@ In most cases you'll want to know when the user's finger was first pressed. You
var fingerLifted = true;
LCD.clear();
require("Touchscreen").connect(function(x,y) {
function onTouch(x,y) {
if (x===undefined) {
fingerLifted = true;
} else {
Expand All @@ -37,6 +40,8 @@ require("Touchscreen").connect(function(x,y) {
}
}
});
require("Touchscreen").connect(onTouch);
```

Using
Expand Down

0 comments on commit 98e231f

Please sign in to comment.