-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrobotGenerator.js
161 lines (129 loc) · 6.04 KB
/
robotGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
goog.provide('Blockly.Arduino.Robotdulab');
goog.require('Blockly.Arduino');
var setup_robotdulab = "robotDuLAB.begin();\n";
var define_robotdulab = '#include <Servo.h>\n'+
'#include <Adafruit_NeoPixel.h>\n'+
'#include <RobotDuLAB.h>\n'+
'#define TRIGGER_PIN 2 // broche trig du capteur US HC-SR04\n'+
'#define ECHO_PIN 4 // broche echo du capteur US HC-SR04\n'+
'#define ROUE_DROITE_PIN 5\n'+
'#define ROUE_GAUCHE_PIN 3\n'+
'#define ANNEAU_LED_PIN 6\n\n'+
'RobotDuLAB robotDuLAB(TRIGGER_PIN, ECHO_PIN, ROUE_DROITE_PIN, ROUE_GAUCHE_PIN, ANNEAU_LED_PIN);\n';
Blockly.Arduino ['Avancer'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var code ="robotDuLAB.Avancer();\n";
return code;
};
Blockly.Arduino ['Reculer'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var code ="robotDuLAB.Reculer();\n";
return code;
};
Blockly.Arduino ['Arreter'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var code ="robotDuLAB.Arreter();\n";
return code;
};
Blockly.Arduino ['TournerAGauche'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var code ="robotDuLAB.TournerAGauche();\n";
return code;
};
Blockly.Arduino ['TournerADroite'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var code ="robotDuLAB.TournerADroite();\n";
return code;
};
Blockly.Arduino ['Attendre'] = function (block) {
var time = Blockly.Arduino.valueToCode(block, 'DELAY_TIME', Blockly.Arduino.ORDER_ATOMIC);
var code ="delay("+time+");\n";
return code;
};
Blockly.Arduino ['AnimerAnneauLed'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var couleur = Blockly.Arduino.valueToCode(block, 'Couleur', Blockly.Arduino.ORDER_ATOMIC)||'VERT';
var animation = Blockly.Arduino.valueToCode(block, 'Animation', Blockly.Arduino.ORDER_ATOMIC)||'COULEUR';
var code ="robotDuLAB.AnimerAnneauLed("+animation+","+couleur+");\n";
return code;
};
Blockly.Arduino ['Distance'] = function (block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var code ="robotDuLAB.getDistanceObstacle();";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['Animation'] = function (block) {
var dropdown_option = block.getFieldValue('Animation');
var value_option = Blockly.Arduino.valueToCode(block, 'Animation', Blockly.Arduino.ORDER_ATOMIC);
var code = dropdown_option;
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['VERT'] = function (block) {
var code ="VERT";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['ROUGE'] = function (block) {
var code ="ROUGE";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['MAGENTA'] = function (block) {
var code ="MAGENTA";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['BLEU'] = function (block) {
var code ="BLEU";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['TURQUOISE'] = function (block) {
var code ="TURQUOISE";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['VIOLET'] = function (block) {
var code ="VIOLET";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['JAUNE'] = function (block) {
var code ="JAUNE";
return [ code, Blockly.Arduino.ORDER_ATOMIC ];
};
Blockly.Arduino['loop_dist_inf'] = function(block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var value_while = Blockly.Arduino.valueToCode(block, 'Distance', Blockly.Arduino.ORDER_ATOMIC);
var statements_do = Blockly.Arduino.statementToCode(block, 'Faire');
var code = 'while (robotDuLAB.getDistanceObstacle() < ' + value_while +')\n{\n'+ statements_do +'}\n';
return code;
};
Blockly.Arduino['loop_dist_sup'] = function(block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var value_while = Blockly.Arduino.valueToCode(block, 'Distance', Blockly.Arduino.ORDER_ATOMIC);
var statements_do = Blockly.Arduino.statementToCode(block, 'Faire');
var code = 'while (robotDuLAB.getDistanceObstacle() > ' + value_while +')\n{\n'+ statements_do +'}\n';
return code;
};
Blockly.Arduino['if_inf'] = function(block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var value_distance = Blockly.Arduino.valueToCode(block, 'Distance', Blockly.Arduino.ORDER_ATOMIC) || '20';
var statements_faire = Blockly.Arduino.statementToCode(block, 'Faire');
var code = 'if (robotDuLAB.getDistanceObstacle() < ' + value_distance + ')\n{\n' +
statements_faire + '} \n';
return code;
};
Blockly.Arduino['if_sup'] = function(block) {
Blockly.Arduino.setups_["setup_robotdulab"] = setup_robotdulab;
Blockly.Arduino.definitions_["define_robotdulab"] = define_robotdulab;
var value_distance = Blockly.Arduino.valueToCode(block, 'Distance', Blockly.Arduino.ORDER_ATOMIC) || '20';
var statements_faire = Blockly.Arduino.statementToCode(block, 'Faire');
var code = 'if (robotDuLAB.getDistanceObstacle() > ' + value_distance + ')\n{\n' +
statements_faire + '} \n';
return code;
};