-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5e9feb
commit deee5a3
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
### Usage | ||
```js | ||
// Invoke this method to set the pull mode. | ||
// pullType can be - pullup, pulldown or none. | ||
pin.pull(pullType, callback); | ||
``` | ||
|
||
|
||
Example of the `pin.pull(mode)` command using a pushbutton. The code example given below turns on the Blue LED of the Tessel module when the pushbutton is pressed and turns off the Blue LED when the pushbutton is not pressed. | ||
|
||
```js | ||
var tessel= require('tessel'); // Import Tessel | ||
|
||
var pin = tessel.port.A.pin[2]; // Select pin 2 on port A | ||
|
||
var pullType = "pullup"; // Set the mode of `pin.pull to pullup` | ||
|
||
var led = tessel.led[3]; // Blue LED of Tessel | ||
|
||
pin.pull(pullType,(error, buffer) => { // Pin 2 pulled high | ||
|
||
if (error){ | ||
throw error; | ||
} | ||
}); | ||
|
||
setInterval({ | ||
pin.read(function(error, number){ | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
|
||
// Pin 2 reads high when the pushbutton is not pressed since it is pulled up | ||
console.log(number); | ||
if (number == 1){ | ||
led.off(); | ||
} | ||
|
||
// Pin 2 reads low when the pushbutton is pressed since its connection with ground gets complete | ||
else{ | ||
led.on(); | ||
} | ||
|
||
}); | ||
|
||
}, 500); | ||
``` |