Skip to content

Commit

Permalink
rgb block and updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cparrapa committed Jun 11, 2021
1 parent 732bdf8 commit 2c08343
Show file tree
Hide file tree
Showing 68 changed files with 6,525 additions and 5,133 deletions.
94 changes: 36 additions & 58 deletions www/blocs&generateurs/actionneur.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,18 +640,20 @@ Blockly.Python.definitions_["pin_"+profile[card].BUILTIN_LED]="BROCHE_"+profile[
return "BROCHE_"+profile[card].BUILTIN_LED+".value(0)\ntime.sleep_ms("+dropdown_speed+")\nBROCHE_"+profile[card].BUILTIN_LED+".value(1)\ntime.sleep_ms("+dropdown_speed+")\n"
};
//////////////
Blockly.Blocks['rvb_init']={init:function() {
Blockly.Blocks['rgb_init']={init:function() {
var card=window.localStorage.card;
this.appendDummyInput() .appendField(new Blockly.FieldImage('media/rgb.png', 48, 48, "*")) .appendField(Blockly.Msg.rvb_init);
this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("R").appendField(new Blockly.FieldDropdown(profile[card].dropdownPWM), "rouge");
this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("G").appendField(new Blockly.FieldDropdown(profile[card].dropdownPWM), "vert");
this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("B").appendField(new Blockly.FieldDropdown(profile[card].dropdownPWM), "bleu");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour("#4b009f");
this.setTooltip(Blockly.Msg.rvb_init_tooltip);
this.setHelpUrl('http://www.mon-club-elec.fr/pmwiki_reference_arduino/pmwiki.php?n=Main.ReferenceMaxi')}
};
Blockly.Arduino['rvb_init'] = function(block) {
Blockly.Arduino['rgb_init'] = function(block) {
var value_rouge = block.getFieldValue('rouge');
var value_vert = block.getFieldValue('vert');
var value_bleu = block.getFieldValue('bleu');
Expand All @@ -660,7 +662,7 @@ Blockly.Arduino['rvb_init'] = function(block) {
Blockly.Arduino.setups_['rvb_'+value_rouge]='pinMode(greenPin, OUTPUT);\n pinMode(redPin, OUTPUT);\n pinMode(bluePin, OUTPUT);';
return '';
};
Blockly.Python['rvb_init'] = function(block) {
Blockly.Python['rgb_init'] = function(block) {
var value_rouge = block.getFieldValue('rouge');
var value_vert = block.getFieldValue('vert');
var value_bleu = block.getFieldValue('bleu');
Expand All @@ -671,31 +673,8 @@ Blockly.Python['rvb_init'] = function(block) {
return '';
};

Blockly.Blocks['rvb_init_2']={init:function() {
var card=window.localStorage.card;
this.appendDummyInput() .appendField(new Blockly.FieldImage('media/rgb.png', 48, 48, "*")) .appendField(Blockly.Msg.rvb_init);
this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("R").appendField(new Blockly.FieldDropdown(profile[card].dropdownPWM), "rouge");
this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("G").appendField(new Blockly.FieldDropdown(profile[card].dropdownPWM), "vert");
this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("B").appendField(new Blockly.FieldDropdown(profile[card].dropdownPWM), "bleu");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour("#4b009f");
this.setTooltip(Blockly.Msg.rvb_init_tooltip);
this.setHelpUrl('http://www.mon-club-elec.fr/pmwiki_reference_arduino/pmwiki.php?n=Main.ReferenceMaxi')}
};
Blockly.Arduino['rvb_init_2'] = function(block) {
var value_rouge = block.getFieldValue('rouge');
var value_vert = block.getFieldValue('vert');
var value_bleu = block.getFieldValue('bleu');
Blockly.Arduino.variables_['rvb_'+value_rouge] = '#define redPin '+value_rouge+'\n#define greenPin '+value_vert+'\n#define bluePin '+value_bleu;
Blockly.Arduino.userFunctions_['rvb_'+value_rouge] = 'void setColor(int redValue, int greenValue, int blueValue) {\n analogWrite(redPin, redValue);\n analogWrite(greenPin, greenValue);\n analogWrite(bluePin, blueValue);\n}';
Blockly.Arduino.setups_['rvb_'+value_rouge]='pinMode(greenPin, OUTPUT);\n pinMode(redPin, OUTPUT);\n pinMode(bluePin, OUTPUT);';
return '';
};

//////////////
Blockly.Blocks['rvb_set']={init:function() {
Blockly.Blocks['rgb_set']={init:function() {
this.appendDummyInput() .appendField(Blockly.Msg.rvb_set);
this.appendValueInput("r") .setCheck("Number") .setAlign(Blockly.ALIGN_RIGHT) .appendField("R");
this.appendValueInput("v") .setCheck("Number") .setAlign(Blockly.ALIGN_RIGHT) .appendField("G");
Expand All @@ -705,32 +684,52 @@ Blockly.Blocks['rvb_set']={init:function() {
this.setNextStatement(true);
this.setColour("#4b009f");
this.setTooltip(Blockly.Msg.rvb_set_tooltip);
this.setHelpUrl('http://www.mon-club-elec.fr/pmwiki_reference_arduino/pmwiki.php?n=Main.ReferenceMaxi')}
this.setHelpUrl('https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds/')}
};
Blockly.Arduino['rvb_set'] = function(block) {
Blockly.Arduino['rgb_set'] = function(block) {
var value_r = Blockly.Arduino.valueToCode(block, 'r', Blockly.Arduino.ORDER_ATOMIC);
var value_v = Blockly.Arduino.valueToCode(block, 'v', Blockly.Arduino.ORDER_ATOMIC);
var value_b = Blockly.Arduino.valueToCode(block, 'b', Blockly.Arduino.ORDER_ATOMIC);
var code = 'setColor('+value_r+','+value_v+','+value_b+');\n';
return code;
};
Blockly.Python['rvb_set'] = function(block) {
Blockly.Python['rgb_set'] = function(block) {
var value_r = Blockly.Python.valueToCode(block, 'r', Blockly.Python.ORDER_ATOMIC);
var value_v = Blockly.Python.valueToCode(block, 'v', Blockly.Python.ORDER_ATOMIC);
var value_b = Blockly.Python.valueToCode(block, 'b', Blockly.Python.ORDER_ATOMIC);
var code = 'setColor('+value_r+','+value_v+','+value_b+')\n';
return code;
}

Blockly.Blocks["rgb_setcolor"]={init:function(){
this.appendDummyInput() .appendField(Blockly.Msg.rvb_set);
this.appendDummyInput().appendField(new Blockly.FieldColour("#ff0000"), "color");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour("#4b009f");
this.setTooltip(Blockly.Msg.rvb_set_tooltip);
this.setHelpUrl("https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds/")}
};
Blockly.Arduino["rgb_setcolor"]=function(block){
var color=block.getFieldValue("color");
var colorR=color[1] + color[2], colorG=color[3] + color[4], colorB=color[5] + color[6];
var red=parseInt(colorR,16), green=parseInt(colorG,16), blue=parseInt(colorB,16);
var code = 'setColor('+red+','+green+','+blue+');\n';
return code;
};
//////////////

Blockly.Blocks["bargraphe"]={init:function(){
this.appendDummyInput().appendField(new Blockly.FieldImage('media/LEDbar.png', 48, 48, "*"))
.appendField(Blockly.Msg.bargraphe);
this.appendValueInput("clk", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField("DCKI");
this.appendValueInput("data", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField("DI");
this.setColour("#4b009f");
this.setTooltip(Blockly.Msg.bargraphe_tooltip);
this.setHelpUrl("http://wiki.seeed.cc/Grove-LED_Bar/")}
this.appendDummyInput().appendField(new Blockly.FieldImage('media/LEDbar.png', 48, 48, "*"))
.appendField(Blockly.Msg.bargraphe);
this.appendValueInput("clk", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField("DCKI");
this.appendValueInput("data", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField("DI");
this.setColour("#4b009f");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.bargraphe_tooltip);
this.setHelpUrl("http://wiki.seeed.cc/Grove-LED_Bar/")}
};
Blockly.Arduino["bargraphe"]=function(block){
var _clock=Blockly.Arduino.valueToCode(block, 'clk', Blockly.Arduino.ORDER_ATOMIC);
Expand All @@ -748,27 +747,6 @@ Blockly.Python["bargraphe"]=function(block){
Blockly.Python.definitions_["pin_"+_clock+"_"+_data]="ledbar = MY9221(di=Pin("+_data+"), dcki=Pin("+_clock+"))";
return ""
};

Blockly.Blocks["bargraphe_2"]={init:function(){
this.appendDummyInput().appendField(new Blockly.FieldImage('media/LEDbar.png', 48, 48, "*"))
.appendField(Blockly.Msg.bargraphe);
this.appendValueInput("clk", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField("DCKI");
this.appendValueInput("data", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField("DI");
this.setColour("#4b009f");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.bargraphe_tooltip);
this.setHelpUrl("http://wiki.seeed.cc/Grove-LED_Bar/")}
};
Blockly.Arduino["bargraphe_2"]=function(block){
var _clock=Blockly.Arduino.valueToCode(block, 'clk', Blockly.Arduino.ORDER_ATOMIC);
var _data=Blockly.Arduino.valueToCode(block, 'data', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_["ledbar"]="unsigned char _state[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};";
Blockly.Arduino.codeFunctions_["ledbar"]="void sendData(unsigned int data) {\n for (unsigned char i=0; i < 16; i++){\n unsigned int state=(data&0x8000) ? HIGH : LOW;\n digitalWrite(" + _data + ", state);\n state=digitalRead(" + _clock + ") ? LOW : HIGH;\n digitalWrite(" + _clock + ", state);\n data <<= 1;\n }\n}\nvoid setData(unsigned char _state[]) {\n sendData(0x00);\n for (unsigned char i=0; i<10; i++) sendData(_state[10-i-1]);\n sendData(0x00);\n sendData(0x00);\n digitalWrite(" + _data + ", LOW);\n delayMicroseconds(10);\n for (unsigned char i=0; i<4; i++){\n digitalWrite(" + _data + ", HIGH);\n digitalWrite(" + _data + ", LOW);\n }\n}\nvoid SetLevel(float level) {\n level=max(0, min(10, level));\n level *= 8;\n for (byte i=0; i<10; i++) {\n _state[i]=(level>8) ? ~0 : (level>0) ? ~(~0 << byte(level)) : 0;\n level -= 8;\n };\n setData(_state);\n}";
Blockly.Arduino.setups_["ledbar"]="pinMode(" + _clock + ", OUTPUT);\n pinMode(" + _data + ", OUTPUT);";
return ""
};

//////////////
Blockly.Blocks["bargraphe_allume"]={init:function(){
this.appendValueInput("del", "Number").appendField(Blockly.Msg.bargraphe_allume);
Expand Down
7 changes: 3 additions & 4 deletions www/blocs&generateurs/neopixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ goog.require('Blockly.Types');

//////////////

Blockly.Blocks["pixel_init_2"]={init:function(){
Blockly.Blocks["pixel_init"]={init:function(){
this.appendDummyInput() .appendField(new Blockly.FieldImage('media/neopixel.png', 33, 33, "*")).appendField(Blockly.Msg.pixel1);
this.appendValueInput("pin", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.pin);
this.appendValueInput("num", "Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.pixel4);
Expand All @@ -16,7 +16,7 @@ Blockly.Blocks["pixel_init_2"]={init:function(){
this.setTooltip(Blockly.Msg.pixel1_tooltip);
this.setHelpUrl("https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use")}
};
Blockly.Arduino["pixel_init_2"]=function(block){
Blockly.Arduino["pixel_init"]=function(block){
var pin=Blockly.Arduino.valueToCode(block, "pin", Blockly.Arduino.ORDER_ASSIGNMENT);
var number=Blockly.Arduino.valueToCode(block, "num", Blockly.Arduino.ORDER_ASSIGNMENT);
Blockly.Arduino.includes_["pixel"]="#include <Adafruit_NeoPixel.h>";
Expand All @@ -25,7 +25,7 @@ Blockly.Arduino["pixel_init_2"]=function(block){
+'pixel.clear();\n';
return ""
};
Blockly.Python["pixel_init_2"]=function(block){
Blockly.Python["pixel_init"]=function(block){
var pin=Blockly.Python.valueToCode(block, "pin", Blockly.Python.ORDER_ASSIGNMENT);
var number=Blockly.Python.valueToCode(block, "num", Blockly.Python.ORDER_ASSIGNMENT);
Blockly.Python.imports_["neopixel"]="from neopixel import NeoPixel";
Expand Down Expand Up @@ -149,7 +149,6 @@ Blockly.Arduino["pixel_clear"]=function(block){
return code;
};


//////////////
Blockly.Blocks["pixel_setbrightness"]={init:function(){
this.appendValueInput("brightness") .setCheck("Number").appendField(Blockly.Msg.pixel5);
Expand Down
25 changes: 25 additions & 0 deletions www/blocs&generateurs/oled.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ Blockly.Blocks['OLED_scroll'] = {
}
return code
};
Blockly.Blocks['OLED_invert'] = {
init: function() {
this.appendDummyInput() .appendField("🖥️ invert") .appendField(new Blockly.FieldDropdown([[Blockly.Msg.yes, "true"], [Blockly.Msg.no, "false"]]), "mode") ;
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour("#4b009f");
this.setTooltip('');
this.setHelpUrl('https://learn.adafruit.com/monochrome-oled-breakouts/arduino-library-and-examples');
}
};

Blockly.Arduino['OLED_invert'] = function(block) {
var mode = block.getFieldValue('mode');
var code = '';
switch(mode) {
case 'true':
code = 'display.invertDisplay(true);\n';
break;
case 'false':
code = 'display.invertDisplay(false);\n';
break;
}
return code
};
Blockly.Blocks['OLED_pixel'] = {
init: function() {
Blockly.FieldCheckbox.CHECK_CHAR= '▉'
Expand Down
8 changes: 2 additions & 6 deletions www/blocs&generateurs/otto.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Blockly.Arduino['otto9_home'] = function(block) {
+ '#define PIN_YR 3 // right leg, servo[1]\n'
+ '#define PIN_RL 4 // left foot, servo[2]\n'
+ '#define PIN_RR 5 // right foot, servo[3]\n'
+ '#define PIN_Trigger 8 // ultrasound \n'
+ '#define PIN_Echo 9 // ultrasound \n'
+ '#define PIN_Trigger 8 // ultrasonic \n'
+ '#define PIN_Echo 9 // ultrasonic \n'
+ '#define PIN_Buzzer 13 //buzzer';
Blockly.Arduino.setups_['otto9_init']='Otto.init(PIN_YL, PIN_YR, PIN_RL, PIN_RR, true, A6, PIN_Buzzer, PIN_Trigger, PIN_Echo);';
var code = 'Otto.home();\n';
Expand Down Expand Up @@ -573,8 +573,6 @@ Blockly.Arduino['otto9_getdistance'] = function(block) {
Blockly.Arduino.includes_['otto9_lib_dist'] = '#include <US.h>';
Blockly.Arduino.variables_['otto9_distance'] = 'int distance;\n'
+ 'bool obstacleDetected = false;';
Blockly.Arduino.definitions_['otto9_distance'] = '#define PIN_Trigger 8 // ultrasound \n'
+ '#define PIN_Echo 9 // ultrasound';
var code = 'Otto.getDistance()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
Expand All @@ -600,8 +598,6 @@ Blockly.Arduino['otto9_obstacle'] = function(block) {
Blockly.Arduino.includes_['otto9_lib_dist'] = '#include <US.h>';
Blockly.Arduino.variables_['otto9_distance'] = 'int distance;\n'
+ 'bool obstacleDetected = false;';
Blockly.Arduino.definitions_['otto9_distance'] = '#define PIN_Trigger 8 // ultrasound \n'
+ '#define PIN_Echo 9 // ultrasound';
var code = '(Otto.getDistance() <' + dropdown_obstacle+')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
Expand Down
File renamed without changes.
85 changes: 85 additions & 0 deletions www/examples/Ottoavoid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<toolbox>toolbox_arduino_all</toolbox>
<block type="base_setup_loop" id="BWvEuN{WKv0tFdhzVme;" x="199" y="115">
<statement name="DO">
<block type="otto9_configuration" id=",ab=pZHafjm.pP(4iJBQ">
<value name="PIN_YL">
<shadow type="analog_pin" id="_*mL?#),[ORm|VLdY41B">
<field name="NUM">2</field>
</shadow>
</value>
<value name="PIN_YR">
<shadow type="analog_pin" id="k=x#J.!G*r@^n#DrP}fs">
<field name="NUM">3</field>
</shadow>
</value>
<value name="PIN_RL">
<shadow type="analog_pin" id="t9^6rKp2Z;0s/H@cR/87">
<field name="NUM">4</field>
</shadow>
</value>
<value name="PIN_RR">
<shadow type="analog_pin" id="eppvhN)zV[F4b_]-0M{g">
<field name="NUM">5</field>
</shadow>
</value>
<value name="PIN_TRIG">
<shadow type="analog_pin" id="q#R,Jv.rLQUPPZ%1/;Gd">
<field name="NUM">8</field>
</shadow>
</value>
<value name="PIN_ECHO">
<shadow type="analog_pin" id="!PsB*}B:sXg%tG.td@(k">
<field name="NUM">9</field>
</shadow>
</value>
<value name="PIN_Buzzer">
<shadow type="analog_pin" id=")3zU$+i|y4fn6+dUTEpL">
<field name="NUM">13</field>
</shadow>
</value>
</block>
</statement>
<statement name="LOOP">
<block type="controls_if" id="Wi[Cre+^@gHq{d))9xGk">
<value name="IF0">
<block type="otto9_obstacle" id="~mUV#jI3gnS4M}{%A/OK">
<field name="obstacle">10</field>
</block>
</value>
<statement name="DO0">
<block type="otto_gesture" id="2mjJ_4oMsX:CN0:WAuOg">
<field name="otto_gesture">OttoConfused</field>
<next>
<block type="otto_move" id="?t==sY{EQ;u%fVW1$]AI">
<field name="otto_move_sens">BACKWARD</field>
<field name="otto_move_speed">1000</field>
<next>
<block type="controls_repeat_ext" id="/nM)%y[DvH8VYv[h4Y~P">
<value name="TIMES">
<block type="math_number" id="|9|.Stz4vmpP5Z6Gif(3">
<field name="NUM">3</field>
</block>
</value>
<statement name="DO">
<block type="otto_move" id="0LYD`^*xkK.%0)n6_O@D">
<field name="otto_move_sens">LEFT</field>
<field name="otto_move_speed">1000</field>
</block>
</statement>
</block>
</next>
</block>
</next>
</block>
</statement>
<next>
<block type="otto_move" id="6(-/Aspb^!A4a?pXHbpp">
<field name="otto_move_sens">FORWARD</field>
<field name="otto_move_speed">1000</field>
</block>
</next>
</block>
</statement>
</block>
</xml>
Loading

0 comments on commit 2c08343

Please sign in to comment.