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
601b4a40
Commit
601b4a40
authored
Jul 31, 2014
by
Carlos Pereira Atencio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separated base functions into time and io, others still required.
parent
54fafdc4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
197 additions
and
151 deletions
+197
-151
generators/arduino/base.js
generators/arduino/base.js
+6
-151
generators/arduino/io.js
generators/arduino/io.js
+155
-0
generators/arduino/text.js
generators/arduino/text.js
+2
-0
generators/arduino/time.js
generators/arduino/time.js
+34
-0
No files found.
generators/arduino/base.js
View file @
601b4a40
/**
* @license
* Visual Blocks Language
*
* Copyright 2012 Fred Lin.
...
...
@@ -19,29 +20,17 @@
/**
* @fileoverview Helper functions for generating Arduino blocks.
* Originally developed by the author below and modified for Ardublockly
* @author gasolin@gmail.com (Fred Lin)
*/
'
use strict
'
;
//To support syntax defined in http://arduino.cc/en/Reference/HomePage
//define blocks
if
(
!
Blockly
.
Language
)
Blockly
.
Language
=
{};
goog
.
provide
(
'
Blockly.Arduino.loops
'
);
goog
.
require
(
'
Blockly.Arduino
'
);
Blockly
.
Language
.
base_delay
=
{
category
:
'
Control
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/delay
'
,
init
:
function
()
{
this
.
setColour
(
120
);
this
.
appendValueInput
(
"
DELAY_TIME
"
,
Number
)
.
appendTitle
(
"
Delay
"
)
.
setCheck
(
Number
);
this
.
setInputsInline
(
true
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Delay specific time
'
);
}
};
Blockly
.
Language
.
base_map
=
{
category
:
'
Math
'
,
...
...
@@ -62,91 +51,6 @@ Blockly.Language.base_map = {
}
};
Blockly
.
Language
.
inout_buildin_led
=
{
category
:
'
In/Out
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/DigitalWrite
'
,
init
:
function
()
{
this
.
setColour
(
190
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
Build-in LED Stat
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
([[
"
HIGH
"
,
"
HIGH
"
],
[
"
LOW
"
,
"
LOW
"
]]),
"
STAT
"
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
light or off the build-in LED
'
);
}
};
Blockly
.
Language
.
inout_digital_write
=
{
category
:
'
In/Out
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/DigitalWrite
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
DigitalWrite PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
digital
),
"
PIN
"
)
.
appendTitle
(
"
Stat
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
([[
"
HIGH
"
,
"
HIGH
"
],
[
"
LOW
"
,
"
LOW
"
]]),
"
STAT
"
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Write digital value to a specific Port
'
);
}
};
Blockly
.
Language
.
inout_digital_read
=
{
category
:
'
In/Out
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/DigitalRead
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
DigitalRead PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
digital
),
"
PIN
"
);
this
.
setOutput
(
true
,
Boolean
);
this
.
setTooltip
(
''
);
}
};
Blockly
.
Language
.
inout_analog_write
=
{
category
:
'
In/Out
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/AnalogWrite
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
AnalogWrite PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
analog
),
"
PIN
"
);
this
.
appendValueInput
(
"
NUM
"
,
Number
)
.
appendTitle
(
"
value
"
)
.
setCheck
(
Number
);
this
.
setInputsInline
(
true
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Write analog value between 0 and 255 to a specific Port
'
);
}
};
Blockly
.
Language
.
inout_analog_read
=
{
category
:
'
In/Out
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/AnalogRead
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
AnalogRead PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
analog
),
"
PIN
"
);
this
.
setOutput
(
true
,
Number
);
this
.
setTooltip
(
'
Return value between 0 and 1024
'
);
}
};
Blockly
.
Language
.
inout_highlow
=
{
category
:
'
In/Out
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/Constants
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
([[
"
HIGH
"
,
"
HIGH
"
],
[
"
LOW
"
,
"
LOW
"
]]),
'
BOOL
'
)
this
.
setOutput
(
true
,
Boolean
);
this
.
setTooltip
(
Blockly
.
LANG_LOGIC_BOOLEAN_TOOLTIP_1
);
}
};
//servo block
//http://www.seeedstudio.com/depot/emax-9g-es08a-high-sensitive-mini-servo-p-760.html?cPath=170_171
...
...
@@ -205,15 +109,10 @@ Blockly.Language.serial_print = {
}
};
// define generators
Blockly
.
Arduino
=
Blockly
.
Generator
.
get
(
'
Arduino
'
);
Blockly
.
Arduino
.
base_delay
=
function
()
{
var
delay_time
=
Blockly
.
Arduino
.
valueToCode
(
this
,
'
DELAY_TIME
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
1000
'
var
code
=
'
delay(
'
+
delay_time
+
'
);
\n
'
;
return
code
;
};
Blockly
.
Arduino
.
base_map
=
function
()
{
var
value_num
=
Blockly
.
Arduino
.
valueToCode
(
this
,
'
NUM
'
,
Blockly
.
Arduino
.
ORDER_NONE
);
var
value_dmax
=
Blockly
.
Arduino
.
valueToCode
(
this
,
'
DMAX
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
);
...
...
@@ -221,50 +120,6 @@ Blockly.Arduino.base_map = function() {
return
[
code
,
Blockly
.
Arduino
.
ORDER_NONE
];
};
Blockly
.
Arduino
.
inout_buildin_led
=
function
()
{
var
dropdown_stat
=
this
.
getTitleValue
(
'
STAT
'
);
Blockly
.
Arduino
.
setups_
[
'
setup_output_13
'
]
=
'
pinMode(13, OUTPUT);
'
;
var
code
=
'
digitalWrite(13,
'
+
dropdown_stat
+
'
);
\n
'
return
code
;
};
Blockly
.
Arduino
.
inout_digital_write
=
function
()
{
var
dropdown_pin
=
this
.
getTitleValue
(
'
PIN
'
);
var
dropdown_stat
=
this
.
getTitleValue
(
'
STAT
'
);
Blockly
.
Arduino
.
setups_
[
'
setup_output_
'
+
dropdown_pin
]
=
'
pinMode(
'
+
dropdown_pin
+
'
, OUTPUT);
'
;
var
code
=
'
digitalWrite(
'
+
dropdown_pin
+
'
,
'
+
dropdown_stat
+
'
);
\n
'
return
code
;
};
Blockly
.
Arduino
.
inout_digital_read
=
function
()
{
var
dropdown_pin
=
this
.
getTitleValue
(
'
PIN
'
);
Blockly
.
Arduino
.
setups_
[
'
setup_input_
'
+
dropdown_pin
]
=
'
pinMode(
'
+
dropdown_pin
+
'
, INPUT);
'
;
var
code
=
'
digitalRead(
'
+
dropdown_pin
+
'
)
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
Blockly
.
Arduino
.
inout_analog_write
=
function
()
{
var
dropdown_pin
=
this
.
getTitleValue
(
'
PIN
'
);
//var dropdown_stat = this.getTitleValue('STAT');
var
value_num
=
Blockly
.
Arduino
.
valueToCode
(
this
,
'
NUM
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
);
//Blockly.Arduino.setups_['setup_output'+dropdown_pin] = 'pinMode('+dropdown_pin+', OUTPUT);';
var
code
=
'
analogWrite(
'
+
dropdown_pin
+
'
,
'
+
value_num
+
'
);
\n
'
;
return
code
;
};
Blockly
.
Arduino
.
inout_analog_read
=
function
()
{
var
dropdown_pin
=
this
.
getTitleValue
(
'
PIN
'
);
//Blockly.Arduino.setups_['setup_input_'+dropdown_pin] = 'pinMode('+dropdown_pin+', INPUT);';
var
code
=
'
analogRead(
'
+
dropdown_pin
+
'
)
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
Blockly
.
Arduino
.
inout_highlow
=
function
()
{
// Boolean values HIGH and LOW.
var
code
=
(
this
.
getTitleValue
(
'
BOOL
'
)
==
'
HIGH
'
)
?
'
HIGH
'
:
'
LOW
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
/*
//servo
#include <Servo.h>
...
...
generators/arduino/io.js
0 → 100644
View file @
601b4a40
/**
* @fileoverview Blocks extension for Arduino Digital and Analogue input/output functions.
* The Arduino built in functions syntax can be found in http://arduino.cc/en/Reference/HomePage
*/
'
use strict
'
;
/**
* Description
*/
Blockly
.
Blocks
[
'
io_digitalwrite
'
]
=
{
category
:
'
Input/Output
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/DigitalWrite
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
DigitalWrite PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
digital
),
"
PIN
"
)
.
appendTitle
(
"
Stat
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
([[
"
HIGH
"
,
"
HIGH
"
],
[
"
LOW
"
,
"
LOW
"
]]),
"
STAT
"
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Write digital value to a specific Port
'
);
}
};
Blockly
.
Arduino
[
'
io_digitalwrite
'
]
=
function
(
block
)
{
var
dropdown_pin
=
block
.
getFieldValue
(
'
PIN
'
);
var
dropdown_stat
=
block
.
getFieldValue
(
'
STAT
'
);
Blockly
.
Arduino
.
setups_
[
'
setup_output_
'
+
dropdown_pin
]
=
'
pinMode(
'
+
dropdown_pin
+
'
, OUTPUT);
'
;
var
code
=
'
digitalWrite(
'
+
dropdown_pin
+
'
,
'
+
dropdown_stat
+
'
);
\n
'
return
code
;
};
/**
* Description
*/
Blockly
.
Blocks
[
'
io_digitalread
'
]
=
{
category
:
'
Input/Output
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/DigitalRead
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
DigitalRead PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
digital
),
"
PIN
"
);
this
.
setOutput
(
true
,
Boolean
);
this
.
setTooltip
(
''
);
}
};
Blockly
.
Arduino
[
'
io_digitalread
'
]
=
function
(
block
)
{
var
dropdown_pin
=
block
.
getFieldValue
(
'
PIN
'
);
Blockly
.
Arduino
.
setups_
[
'
setup_input_
'
+
dropdown_pin
]
=
'
pinMode(
'
+
dropdown_pin
+
'
, INPUT);
'
;
var
code
=
'
digitalRead(
'
+
dropdown_pin
+
'
)
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
/**
* Description
*/
Blockly
.
Blocks
[
'
io_builtin_led
'
]
=
{
category
:
'
Input/Output
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/DigitalWrite
'
,
init
:
function
()
{
this
.
setColour
(
190
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
Build-in LED Stat
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
([[
"
HIGH
"
,
"
HIGH
"
],
[
"
LOW
"
,
"
LOW
"
]]),
"
STAT
"
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Turn on or off the built in LED
'
);
}
};
Blockly
.
Arduino
[
'
io_builtin_led
'
]
=
function
(
block
)
{
var
dropdown_stat
=
block
.
getFieldValue
(
'
STAT
'
);
Blockly
.
Arduino
.
setups_
[
'
setup_output_LED_BUILTIN
'
]
=
'
pinMode(LED_BUILTIN, OUTPUT);
'
;
var
code
=
'
digitalWrite(LED_BUILTIN,
'
+
dropdown_stat
+
'
);
\n
'
return
code
;
};
/**
* Description
*/
Blockly
.
Blocks
[
'
io_analogwrite
'
]
=
{
category
:
'
Input/Output
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/AnalogWrite
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
AnalogWrite PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
analog
),
"
PIN
"
);
this
.
appendValueInput
(
"
NUM
"
,
Number
)
.
appendTitle
(
"
value
"
)
.
setCheck
(
Number
);
this
.
setInputsInline
(
true
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Write analog value between 0 and 255 to a specific Port
'
);
}
};
Blockly
.
Arduino
[
'
io_analogwrite
'
]
=
function
(
block
)
{
var
dropdown_pin
=
block
.
getFieldValue
(
'
PIN
'
);
//var dropdown_stat = this.getTitleValue('STAT');
var
value_num
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
NUM
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
);
//Blockly.Arduino.setups_['setup_output'+dropdown_pin] = 'pinMode('+dropdown_pin+', OUTPUT);';
var
code
=
'
analogWrite(
'
+
dropdown_pin
+
'
,
'
+
value_num
+
'
);
\n
'
;
return
code
;
};
/**
* Description
*/
Blockly
.
Blocks
[
'
io_analogread
'
]
=
{
category
:
'
Input/Output
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/AnalogRead
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
"
AnalogRead PIN#
"
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
analog
),
"
PIN
"
);
this
.
setOutput
(
true
,
Number
);
this
.
setTooltip
(
'
Return value between 0 and 1024
'
);
}
};
Blockly
.
Arduino
[
'
io_analogread
'
]
=
function
(
block
)
{
var
dropdown_pin
=
block
.
getFieldValue
(
'
PIN
'
);
//Blockly.Arduino.setups_['setup_input_'+dropdown_pin] = 'pinMode('+dropdown_pin+', INPUT);';
var
code
=
'
analogRead(
'
+
dropdown_pin
+
'
)
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
/**
* Description
*/
Blockly
.
Blocks
[
'
io_highlow
'
]
=
{
category
:
'
Input/Output
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/Constants
'
,
init
:
function
()
{
this
.
setColour
(
230
);
this
.
appendDummyInput
(
""
)
.
appendTitle
(
new
Blockly
.
FieldDropdown
([[
"
HIGH
"
,
"
HIGH
"
],
[
"
LOW
"
,
"
LOW
"
]]),
'
BOOL
'
)
this
.
setOutput
(
true
,
Boolean
);
this
.
setTooltip
(
Blockly
.
LANG_LOGIC_BOOLEAN_TOOLTIP_1
);
}
};
Blockly
.
Arduino
[
'
io_highlow
'
]
=
function
(
block
)
{
// Boolean values HIGH and LOW.
var
code
=
(
block
.
getFieldValue
(
'
BOOL
'
)
==
'
HIGH
'
)
?
'
HIGH
'
:
'
LOW
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
generators/arduino/text.js
View file @
601b4a40
...
...
@@ -20,6 +20,7 @@
/**
* @fileoverview Generating Arduino for text blocks.
* Implements the Serial interface in Arduino: http://arduino.cc/en/Reference/Serial
*/
'
use strict
'
;
...
...
@@ -294,6 +295,7 @@ Blockly.Arduino['text_prompt'] = function(block) {
}
return
[
code
,
Blockly
.
Arduino
.
ORDER_UNARY_POSTFIX
];
};
Blockly
.
Arduino
[
'
text_prompt_ext
'
]
=
function
(
block
)
{
// Prompt function (external message).
var
func
=
[];
...
...
generators/arduino/time.js
0 → 100644
View file @
601b4a40
/**
* @fileoverview Blocks extension for Arduino Time functions.
* The arduino built in functions syntax can be found in http://arduino.cc/en/Reference/HomePage
*/
'
use strict
'
;
//TODO: When confirm working, replicate for millis(), micros(), and delayMicroseconds()
/**
* Delay block definition
*/
Blockly
.
Blocks
[
'
time_delay
'
]
=
{
category
:
'
Time
'
,
helpUrl
:
'
http://arduino.cc/en/Reference/delay
'
,
init
:
function
()
{
this
.
setColour
(
120
);
this
.
appendValueInput
(
"
DELAY_TIME
"
,
Number
)
.
appendTitle
(
"
Delay
"
)
.
setCheck
(
Number
);
this
.
setInputsInline
(
true
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Delay specific time
'
);
}
};
/**
* Delay Arduino code generator
*/
Blockly
.
Arduino
[
'
time_delay
'
]
=
function
(
block
)
{
var
delay_time
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
DELAY_TIME
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
1000
'
var
code
=
'
delay(
'
+
delay_time
+
'
);
\n
'
;
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