Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analogWrite demo code #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions example/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ $(document).ready(function($) {
// setup buttons
var digitalButton = $('#digital')[0];
var analogButton = $('#analog')[0];
var analogWriteButton = $('#analogWrite')[0];
digitalButton.disabled = true;
analogButton.disabled = true;
analogWriteButton.disabled = true;


board.on("ready", function() {
Expand All @@ -48,6 +50,7 @@ $(document).ready(function($) {

board.queryAnalogMapping(function (mapping){
analogButton.disabled = false;
analogWriteButton.disabled = false;
});
// var state = 1;
// this.pinMode(13, this.MODES.OUTPUT);
Expand Down Expand Up @@ -104,6 +107,18 @@ $(document).ready(function($) {
}
}

analogWriteButton.onclick = function () {
if (board.isReady){
var pin = $('#awpin').val();
var value = $('.analogWrite .value').val();
console.log("analogWrite("+pin+")");
board.setSamplingInterval(200);
board.analogWrite(pin, value);
console.log("Sent analog value: "+ value);
log.appends("Analog Pin " + pin + ": " + value);
}
}

$('#reset').click(function () {
board.reset();
});
Expand Down
18 changes: 9 additions & 9 deletions example/bundle.js

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Commands</h2>
<button id="capab">Query Capabilities</button>
<button id="firmware">Query Firmware</button>

<div class="connected">
<div class="connected digitalWrite">
<button id="digital">digitalWrite</button>
<select id="pin">
<option>0</option>
Expand All @@ -44,6 +44,23 @@ <h2>Commands</h2>
</select>
</div>

<div class="connected analogWrite">
<button id="analogWrite">analogWrite</button>
<select id="awpin">
<option value="0">A0</option>
<option value="1">A1</option>
<option value="2">A2</option>
<option value="3">A3</option>
<option value="4">A4</option>
<option value="5">A5</option>
</select>
<select class="value">
<option value="0">0</option>
<option value="128">128</option>
<option value="255" selected>255</option>
</select>
</div>

<div class="connected">
<button id="analog">analogRead</button>
<select id="apin">
Expand Down
8 changes: 4 additions & 4 deletions example/jquery.min.js

Large diffs are not rendered by default.