mirror of
https://github.com/s00500/SimpleExpressions
synced 2024-12-03 13:01:29 +00:00
commit
1898615bab
1
img/blocks/credits.txt
Normal file
1
img/blocks/credits.txt
Normal file
@ -0,0 +1 @@
|
||||
Created by Leopoldo Armesto (based on the icon from Antoine Dieulesaint from the Noun Project)
|
95
img/blocks/led_strip.svg
Normal file
95
img/blocks/led_strip.svg
Normal file
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="32mm"
|
||||
height="32mm"
|
||||
viewBox="0 0 32 32"
|
||||
version="1.1"
|
||||
id="svg4534"
|
||||
inkscape:version="0.92.1 r15371"
|
||||
sodipodi:docname="led_strip.svg">
|
||||
<defs
|
||||
id="defs4528" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.35"
|
||||
inkscape:cx="-292.85714"
|
||||
inkscape:cy="560"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1366"
|
||||
inkscape:window-height="705"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata4531">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-265)">
|
||||
<g
|
||||
id="g4510"
|
||||
transform="matrix(-0.56126601,-0.56126601,0.56126601,-0.56126601,16.631231,337.25123)">
|
||||
<rect
|
||||
id="rect2"
|
||||
height="85.000999"
|
||||
width="1"
|
||||
transform="matrix(0.7071,0.7071,-0.7071,0.7071,42.9292,-17.7819)"
|
||||
y="0.42899999"
|
||||
x="42.429001" />
|
||||
<rect
|
||||
id="rect4"
|
||||
height="85"
|
||||
width="1"
|
||||
transform="matrix(0.7071,0.7071,-0.7071,0.7071,57.071,-23.6396)"
|
||||
y="14.571"
|
||||
x="56.570999" />
|
||||
<path
|
||||
id="path6"
|
||||
d="m 76.252,26.047 4.95,-4.95 -0.531,-0.53 -4.949,4.95 -1.06,-1.06 2.475,-2.475 c 0.059,-0.059 0.097,-0.136 0.106,-0.219 l 0.382,-3.098 0.572,-0.572 -0.531,-0.53 -0.663,0.663 c -0.059,0.059 -0.097,0.136 -0.106,0.219 l -0.382,3.098 -2.384,2.383 -2.563,-2.563 c -0.188,-0.188 -0.52,-0.188 -0.707,0 l -7.07,7.071 c -0.195,0.195 -0.195,0.512 0,0.707 l 1.149,1.149 -2.078,2.077 c -0.06,0.059 -0.098,0.136 -0.107,0.219 l -0.382,3.098 -2.383,2.383 -2.563,-2.563 c -0.195,-0.195 -0.512,-0.195 -0.707,0 l -7.071,7.071 c -0.094,0.094 -0.146,0.221 -0.146,0.354 0,0.133 0.053,0.26 0.146,0.354 l 1.149,1.149 -2.077,2.078 c -0.059,0.059 -0.097,0.136 -0.107,0.219 l -0.382,3.098 -2.384,2.383 -2.563,-2.563 c -0.188,-0.188 -0.52,-0.188 -0.707,0 l -7.071,7.071 c -0.195,0.195 -0.195,0.512 0,0.707 l 1.149,1.149 -2.077,2.077 c -0.059,0.06 -0.097,0.137 -0.107,0.22 L 34.09,63.97 31.706,66.353 29.143,63.79 c -0.195,-0.195 -0.512,-0.195 -0.707,0 l -7.071,7.07 c -0.094,0.094 -0.146,0.221 -0.146,0.354 0,0.133 0.053,0.26 0.146,0.354 l 1.149,1.149 -2.078,2.078 c -0.059,0.059 -0.097,0.136 -0.107,0.219 l -0.381,3.098 -0.97,0.969 0.53,0.531 1.061,-1.061 c 0.059,-0.06 0.097,-0.137 0.107,-0.22 l 0.381,-3.098 1.986,-1.987 2.475,2.475 -4.95,4.949 0.53,0.531 4.95,-4.95 2.386,2.386 c 0.094,0.094 0.221,0.146 0.354,0.146 0.133,0 0.26,-0.053 0.354,-0.146 l 7.071,-7.071 c 0.094,-0.094 0.146,-0.221 0.146,-0.354 0,-0.133 -0.053,-0.26 -0.146,-0.354 l -2.386,-2.386 6.364,-6.364 2.386,2.387 c 0.094,0.094 0.221,0.146 0.354,0.146 0.133,0 0.26,-0.053 0.354,-0.146 l 7.071,-7.071 c 0.195,-0.195 0.195,-0.512 0,-0.707 l -2.387,-2.387 6.364,-6.364 2.387,2.387 c 0.098,0.098 0.226,0.146 0.354,0.146 0.128,0 0.256,-0.049 0.354,-0.146 l 7.071,-7.071 c 0.094,-0.094 0.146,-0.221 0.146,-0.354 0,-0.133 -0.053,-0.26 -0.146,-0.354 l -2.387,-2.386 6.364,-6.364 2.386,2.386 c 0.094,0.094 0.221,0.146 0.354,0.146 0.133,0 0.26,-0.053 0.354,-0.146 l 7.071,-7.071 c 0.094,-0.094 0.146,-0.221 0.146,-0.354 0,-0.133 -0.053,-0.26 -0.146,-0.354 z m -47.465,51.53 -6.364,-6.364 6.364,-6.363 6.364,6.363 z m 4.507,-9.634 -1.06,-1.06 2.475,-2.474 c 0.059,-0.06 0.097,-0.137 0.107,-0.22 l 0.382,-3.099 1.986,-1.986 2.474,2.474 z m 9.635,-4.507 -6.364,-6.364 6.364,-6.364 6.364,6.364 z m 4.507,-9.636 -1.06,-1.06 2.475,-2.475 c 0.059,-0.059 0.097,-0.136 0.107,-0.219 l 0.382,-3.098 1.986,-1.986 2.474,2.474 z m 9.635,-4.507 -6.364,-6.364 6.364,-6.364 6.364,6.364 z m 4.508,-9.635 -1.06,-1.06 2.475,-2.475 c 0.059,-0.059 0.097,-0.136 0.106,-0.219 l 0.382,-3.098 1.987,-1.986 2.474,2.475 z m 9.634,-4.507 -6.363,-6.364 6.363,-6.364 6.364,6.364 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
id="path8"
|
||||
d="m 71.184,32.191 c -0.901,0 -1.749,-0.351 -2.387,-0.989 -0.637,-0.637 -0.988,-1.485 -0.988,-2.386 0,-0.901 0.352,-1.749 0.988,-2.387 1.275,-1.274 3.498,-1.274 4.773,0 0.637,0.638 0.988,1.485 0.988,2.387 0,0.902 -0.352,1.749 -0.989,2.386 -0.636,0.638 -1.483,0.989 -2.385,0.989 z m 0,-6 c -0.701,0 -1.36,0.273 -1.856,0.769 -0.495,0.496 -0.769,1.155 -0.769,1.856 0,0.701 0.273,1.36 0.769,1.856 0.992,0.992 2.722,0.992 3.712,0 0.496,-0.496 0.77,-1.155 0.77,-1.856 0,-0.701 -0.273,-1.36 -0.77,-1.856 -0.496,-0.496 -1.155,-0.769 -1.856,-0.769 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
id="path10"
|
||||
d="m 57.071,46.304 c -0.901,0 -1.749,-0.351 -2.387,-0.988 -0.637,-0.637 -0.988,-1.485 -0.988,-2.386 0,-0.902 0.352,-1.75 0.989,-2.387 1.273,-1.274 3.498,-1.274 4.771,0 0.638,0.637 0.989,1.485 0.989,2.387 0,0.901 -0.352,1.749 -0.989,2.386 -0.636,0.637 -1.483,0.988 -2.385,0.988 z m 0,-6 c -0.701,0 -1.36,0.273 -1.855,0.769 -0.496,0.496 -0.77,1.155 -0.77,1.856 0,0.701 0.273,1.36 0.769,1.856 0.992,0.991 2.721,0.991 3.713,0 0.495,-0.496 0.769,-1.155 0.769,-1.856 0,-0.702 -0.273,-1.361 -0.769,-1.856 -0.496,-0.496 -1.156,-0.769 -1.857,-0.769 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
id="path12"
|
||||
d="m 42.929,60.446 c -0.902,0 -1.75,-0.352 -2.387,-0.989 -0.637,-0.637 -0.988,-1.484 -0.988,-2.386 0,-0.902 0.351,-1.749 0.988,-2.387 1.273,-1.273 3.498,-1.275 4.773,0.001 0.637,0.637 0.988,1.484 0.988,2.386 0,0.902 -0.351,1.749 -0.988,2.386 -0.637,0.638 -1.484,0.989 -2.386,0.989 z m 0,-6 c -0.702,0 -1.361,0.273 -1.856,0.769 -0.496,0.496 -0.769,1.155 -0.769,1.856 0,0.701 0.273,1.36 0.769,1.856 0.991,0.99 2.721,0.99 3.712,0 0.496,-0.496 0.769,-1.155 0.769,-1.856 0,-0.701 -0.273,-1.36 -0.769,-1.855 -0.495,-0.496 -1.155,-0.77 -1.856,-0.77 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
id="path14"
|
||||
d="m 28.787,74.588 c -0.901,0 -1.749,-0.351 -2.386,-0.987 -1.315,-1.316 -1.315,-3.458 0,-4.773 1.274,-1.275 3.498,-1.274 4.773,-0.001 1.315,1.316 1.315,3.458 0,4.773 -0.638,0.637 -1.486,0.988 -2.387,0.988 z m 0,-6 c -0.701,0 -1.36,0.273 -1.856,0.769 -1.023,1.024 -1.023,2.689 0,3.714 0.991,0.99 2.72,0.991 3.712,-0.001 1.023,-1.023 1.023,-2.688 0,-3.713 -0.496,-0.496 -1.155,-0.769 -1.856,-0.769 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 7.0 KiB |
16
lang/SimpleExpressions.json
Normal file
16
lang/SimpleExpressions.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"langs":
|
||||
{
|
||||
"en-GB":
|
||||
{
|
||||
"keys":
|
||||
{
|
||||
"LANG_CATEGORY_SOUND": "User Sound",
|
||||
"LANG_SUBCATEGORY_BUZZER": "Buzzer",
|
||||
"LANG_PIEZO_BUZZER": "Buzzer",
|
||||
"LANG_PIEZO_BUZZER_PIN": "PIN",
|
||||
"LANG_PIEZO_BUZZER_PREDEF_SOUNDS_TOOLTIP": "Plays some basic sounds based on SimpleExpressions library"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +1,93 @@
|
||||
Facilino.LANG_COLOUR_SCREEN = '#ACCE42';
|
||||
Facilino.LANG_COLOUR_SCREEN_LEDSTRIP = '#8EAC32';
|
||||
|
||||
Blockly.Blocks['show_mouth'] = {
|
||||
category: 'SimpleExpressions',
|
||||
colour: '#fbb117',
|
||||
helpUrl: Facilino.getHelpUrl('show_mouth'),
|
||||
tags: [],
|
||||
examples: [],
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField("showMouth");
|
||||
this.appendValueInput("Color")
|
||||
.setCheck(null)
|
||||
.appendField("Color");
|
||||
this.setColour("#fbb117");
|
||||
this.setTooltip("");
|
||||
}
|
||||
category: Facilino.locales.getKey('LANG_CATEGORY_SCREEN'),
|
||||
subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_WS2812'),
|
||||
category_colour: Facilino.LANG_COLOUR_SCREEN,
|
||||
colour: Facilino.LANG_COLOUR_SCREEN_LEDSTRIP,
|
||||
helpUrl: Facilino.getHelpUrl('show_mouth'),
|
||||
tags: [],
|
||||
examples: [],
|
||||
init: function() {
|
||||
this.appendDummyInput('').appendField("WS2812 7-Ring").appendField(new Blockly.FieldImage('img/blocks/led_strip.svg', 40*options.zoom, 40*options.zoom));
|
||||
this.appendValueInput('PIN').appendField(Facilino.locales.getKey('LANG_SIMPLEEXPRESSIONS_PIN')).setAlign(Blockly.ALIGN_RIGHT).setCheck(Number);
|
||||
this.appendDummyInput('').appendField('Expression').appendField(new Blockly.FieldDropdown([['Zeros','zeros'],['Happy Small','happySmall'],['Happy Full','happyFull'],['Sad Small','sadSmall'],['Sad Full','sadFull'],['Neutral','neutral'],['Circle','circle'],['Center','center'],['Hook','hook'],['Upsidedown Hook','upsidedownhook'],['Kooh','kooh'],['Upsidedown Kooh','upsidedownkooh'],['Cross','cross'],['Rect','rect'],['Left Arrow','leftarrow'],['Right Arrow','rightarrow'],['Left Half','lefthalf'],['Right Half','righthalf']]),'EXPRESSION').setAlign(Blockly.ALIGN_RIGHT);
|
||||
var colour = new Blockly.FieldColour('#000000');
|
||||
colour.setColours(['#000000','#808080','#C0C0C0','#FFFFFF','#800000','#FF0000','#808000','#FFFF00','#008000','#00FF00','#008080','#00FFFF','#000080','#0000FF','#800080','#FF00FF']).setColumns(4);
|
||||
this.appendDummyInput('').appendField('Color').appendField(colour,'COLOR').setAlign(Blockly.ALIGN_RIGHT);
|
||||
this.setPreviousStatement(true,'code');
|
||||
this.setNextStatement(true,'code');
|
||||
this.setColour(Facilino.LANG_COLOUR_SCREEN_LEDSTRIP);
|
||||
this.setTooltip("");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Blockly.Arduino['show_mouth'] = function(block) {
|
||||
var input_color = Blockly.Arduino.valueToCode(block, 'Color', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var code='SimpleExpressions.showMouth("'+'mouth_name'+'", ' + color + ')' ;
|
||||
code+= '\n';
|
||||
return code;
|
||||
var input_expression = this.getFieldValue('EXPRESSION');
|
||||
var input_color = this.getFieldValue('COLOR');
|
||||
var input_pin = Blockly.Arduino.valueToCode(this,'PIN',Blockly.Arduino.ORDER_ATOMIC) || '';
|
||||
Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>';
|
||||
Blockly.Arduino.setups_['setup_simpleexpressions_mouth'] = 'SimpleExpressions.initMouth('+input_pin+');\n';
|
||||
var color_rgb=Facilino.hexToRgb(input_color);
|
||||
var code='SimpleExpressions.writeMouth("'+input_expression+'",'+color_rgb.r +','+color_rgb.g+','+color_rgb.b+');\n' ;
|
||||
code+= '\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Blocks['play_sound'] = {
|
||||
category: 'SimpleExpressions',
|
||||
colour: '#fbb117',
|
||||
helpUrl: Facilino.getHelpUrl('play_sound'),
|
||||
tags: [],
|
||||
examples: [],
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField("play Sound");
|
||||
this.setColour("#fbb117");
|
||||
this.setTooltip("");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Blockly.Arduino['play_sound'] = function(block) {
|
||||
var input_color = Blockly.Arduino.valueToCode(block, 'Color', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var code='';
|
||||
code+= '\n';
|
||||
return code;
|
||||
};
|
||||
Blockly.Arduino.dyor_piezo_buzzer_predef_sounds = function() {
|
||||
var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC) || '';
|
||||
var code= '';
|
||||
Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>';
|
||||
Blockly.Arduino.setups_['setup_simpleexpressions_buzzer'] = 'SimpleExpressions.initBuzzer('+dropdown_pin+');\n';
|
||||
code='SimpleExpressions.playSound('+this.getFieldValue('OPTION')+');\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Blocks.dyor_piezo_buzzer_predef_sounds = {
|
||||
category: Facilino.locales.getKey('LANG_CATEGORY_SOUND'),
|
||||
subcategory: Facilino.locales.getKey('LANG_SUBCATEGORY_BUZZER'),
|
||||
tags: ['buzzer','sound'],
|
||||
helpUrl: Facilino.getHelpUrl('dyor_piezo_buzzer_predef_sounds'),
|
||||
examples: [''],
|
||||
category_colour: Facilino.LANG_COLOUR_SOUND,
|
||||
colour: Facilino.LANG_COLOUR_SOUND_BUZZER,
|
||||
//dyor_piezo_buzzer initialization
|
||||
init: function() {
|
||||
this.setColour(Facilino.LANG_COLOUR_SOUND_BUZZER);
|
||||
this.appendDummyInput('')
|
||||
.appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER'))
|
||||
.appendField(new Blockly.FieldImage('img/blocks/buzzer.svg', 52*options.zoom, 35*options.zoom));
|
||||
this.appendValueInput('PIN')
|
||||
.appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PIN')).appendField(new Blockly.FieldImage("img/blocks/pwm_signal.svg",24*options.zoom,24*options.zoom))
|
||||
.setCheck(Number)
|
||||
.setAlign(Blockly.ALIGN_RIGHT);
|
||||
this.appendDummyInput('').appendField(new Blockly.FieldImage('img/blocks/speaker.svg', 24*options.zoom, 24*options.zoom))
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['CONNECTION', '0'],
|
||||
['DISCONNECTION', '1'],
|
||||
['BUTTON PUSHED', '2'],
|
||||
['MODE 1', '3'],
|
||||
['MODE 2', '4'],
|
||||
['MODE 3', '5'],
|
||||
['SURPRISE', '6'],
|
||||
['OHOOH', '7'],
|
||||
['OHOOH2', '8'],
|
||||
['CUDDLY', '9'],
|
||||
['SLEEPING','10'],
|
||||
['HAPPY','11'],
|
||||
['SUPER_HAPPY','12'],
|
||||
['HAPPY_SHORT','13'],
|
||||
['SAD','14'],
|
||||
['CONFUSED','15'],
|
||||
['FART1','16'],
|
||||
['FART2','17'],
|
||||
['FART3','18'],
|
||||
['PIRATES','19']
|
||||
]), 'OPTION').setAlign(Blockly.ALIGN_RIGHT);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true,'code');
|
||||
this.setNextStatement(true,'code');
|
||||
this.setTooltip(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PREDEF_SOUNDS_TOOLTIP'));
|
||||
}
|
||||
};
|
||||
|
@ -18,6 +18,21 @@ void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
|
||||
clearMouth();
|
||||
}
|
||||
|
||||
void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
|
||||
mouth = Adafruit_NeoPixel(7, aMouthPin, NEO_GRB + NEO_KHZ800);
|
||||
mouth.begin();
|
||||
clearMouth();
|
||||
}
|
||||
|
||||
void SimpleExpressionsClass::initBuzzer(int aBuzzerPin) {
|
||||
buzzerPin = aBuzzerPin;
|
||||
|
||||
#if defined(ESP32)
|
||||
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution
|
||||
ledcAttachPin(aBuzzerPin, ledc_channel);
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- MOUTHS ----------------------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
@ -16,6 +16,8 @@ class SimpleExpressionsClass
|
||||
public:
|
||||
// General
|
||||
void init(int mouthPin, int buzzerPin);
|
||||
void initMouth(int mouthPin);
|
||||
void initBuzzer(int buzzerPin);
|
||||
|
||||
// Mouths
|
||||
void printMouth(int number, int r, int g, int b);
|
||||
|
Loading…
Reference in New Issue
Block a user