1
0
mirror of https://github.com/s00500/SimpleExpressions synced 2024-11-23 11:00:54 +00:00

modified: simpleExpression_blocks.js

modified:   src/SimpleExpressions.cpp
	modified:   src/SimpleExpressions.h
This commit is contained in:
roboticafacil 2017-12-08 13:41:15 +01:00
parent 9310f8213c
commit 5e8dfc9920
3 changed files with 51 additions and 20 deletions

View File

@ -1,26 +1,40 @@
Facilino.LANG_COLOUR_SCREEN_LEDSTRIP = '#8EAC32';
Facilino.locales.defaultLanguage["LANG_SUBCATERGORY_WS2812"]="LED Strip";
Facilino.locales.defaultLanguage["LANG_SIMPLEEXPRESSIONS_PIN"]="PIN";
Facilino.locales.defaultLanguage["LANG_SIMPLEEXPRESSIONS_SHOWMOUTH_TOOLTIP"]="Draw an expression on the WS2812 led strip (ring-7)";
Blockly.Blocks['show_mouth'] = { Blockly.Blocks['show_mouth'] = {
category: 'SimpleExpressions', category: Facilino.locales.getKey('LANG_CATEGORY_SCREEN'),
colour: '#fbb117', subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_WS2812'),
helpUrl: Facilino.getHelpUrl('show_mouth'), category_colour: Facilino.LANG_COLOUR_SCREEN,
tags: [], colour: Facilino.LANG_COLOUR_SCREEN_LEDSTRIP,
examples: [], helpUrl: Facilino.getHelpUrl('show_mouth'),
init: function() { tags: [],
this.appendDummyInput() examples: [],
.appendField("showMouth"); init: function() {
this.appendValueInput("Color") this.appendDummyInput('').appendField("WS2812 7-Ring").appendField(new Blockly.FieldImage('img/blocks/led_strip.svg', 40*options.zoom, 40*options.zoom));
.setCheck(null) this.appendValueInput('PIN').appendField(Facilino.locales.getKey('LANG_SIMPLEEXPRESSIONS_PIN')).setAlign(Blockly.ALIGN_RIGHT).setCheck(Number);
.appendField("Color"); 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);
this.setColour("#fbb117"); var colour = new Blockly.FieldColour('#000000');
this.setTooltip(""); 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) { Blockly.Arduino['show_mouth'] = function(block) {
var input_color = Blockly.Arduino.valueToCode(block, 'Color', Blockly.Arduino.ORDER_ATOMIC); var input_expression = this.getFieldValue('EXPRESSION');
var code='SimpleExpressions.showMouth("'+'mouth_name'+'", ' + color + ')' ; var input_color = this.getFieldValue('COLOR');
code+= '\n'; var input_pin = Blockly.Arduino.valueToCode(this,'PIN',Blockly.Arduino.ORDER_ATOMIC) || '';
return code; 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'] = { Blockly.Blocks['play_sound'] = {

View File

@ -18,6 +18,21 @@ void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
clearMouth(); 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 ----------------------------------------// //-- MOUTHS ----------------------------------------//
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////

View File

@ -16,6 +16,8 @@ class SimpleExpressionsClass
public: public:
// General // General
void init(int mouthPin, int buzzerPin); void init(int mouthPin, int buzzerPin);
void initMouth(int mouthPin);
void initBuzzer(int buzzerPin);
// Mouths // Mouths
void printMouth(int number, int r, int g, int b); void printMouth(int number, int r, int g, int b);