Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
b26b7884
Commit
b26b7884
authored
Jan 17, 2016
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix analogWrite to list only PWM pins and warn if input is out of range.
Fixes #30
parent
bd5bfff6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
blockly/blocks/arduino/io.js
blockly/blocks/arduino/io.js
+2
-2
blockly/generators/arduino/io.js
blockly/generators/arduino/io.js
+8
-0
No files found.
blockly/blocks/arduino/io.js
View file @
b26b7884
...
@@ -124,7 +124,7 @@ Blockly.Blocks['io_analogwrite'] = {
...
@@ -124,7 +124,7 @@ Blockly.Blocks['io_analogwrite'] = {
this
.
appendDummyInput
(
''
)
this
.
appendDummyInput
(
''
)
.
appendField
(
'
set analogue pin#
'
)
.
appendField
(
'
set analogue pin#
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
.
appendField
(
new
Blockly
.
FieldDropdown
(
Blockly
.
Arduino
.
Boards
.
selected
.
analog
Pins
),
'
PIN
'
);
Blockly
.
Arduino
.
Boards
.
selected
.
pwm
Pins
),
'
PIN
'
);
this
.
appendValueInput
(
'
NUM
'
,
Blockly
.
StaticTyping
.
BlocklyType
.
NUMBER
)
this
.
appendValueInput
(
'
NUM
'
,
Blockly
.
StaticTyping
.
BlocklyType
.
NUMBER
)
.
appendField
(
'
to
'
)
.
appendField
(
'
to
'
)
.
setCheck
(
Blockly
.
StaticTyping
.
BlocklyType
.
NUMBER
);
.
setCheck
(
Blockly
.
StaticTyping
.
BlocklyType
.
NUMBER
);
...
@@ -138,7 +138,7 @@ Blockly.Blocks['io_analogwrite'] = {
...
@@ -138,7 +138,7 @@ Blockly.Blocks['io_analogwrite'] = {
* @this Blockly.Block
* @this Blockly.Block
*/
*/
updateFields
:
function
()
{
updateFields
:
function
()
{
Blockly
.
Arduino
.
Boards
.
refreshBlockFieldDropdown
(
this
,
'
PIN
'
,
'
analog
Pins
'
);
Blockly
.
Arduino
.
Boards
.
refreshBlockFieldDropdown
(
this
,
'
PIN
'
,
'
pwm
Pins
'
);
},
},
/** @return {!string} The type of input value for the block, an integer. */
/** @return {!string} The type of input value for the block, an integer. */
getBlockType
:
function
()
{
getBlockType
:
function
()
{
...
...
blockly/generators/arduino/io.js
View file @
b26b7884
...
@@ -94,6 +94,14 @@ Blockly.Arduino['io_analogwrite'] = function(block) {
...
@@ -94,6 +94,14 @@ Blockly.Arduino['io_analogwrite'] = function(block) {
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, OUTPUT);
'
;
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, OUTPUT);
'
;
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
// Warn if the input value is out of range
if
(
(
stateOutput
<
0
)
||
(
stateOutput
>
255
))
{
block
.
setWarningText
(
'
The analgue value must be between 0 and 255
'
,
'
pwm_value
'
);
}
else
{
block
.
setWarningText
(
null
,
'
pwm_value
'
);
}
var
code
=
'
analogWrite(
'
+
pin
+
'
,
'
+
stateOutput
+
'
);
\n
'
;
var
code
=
'
analogWrite(
'
+
pin
+
'
,
'
+
stateOutput
+
'
);
\n
'
;
return
code
;
return
code
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment