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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
within OpenModelicaArduino;
package ArduinoExamples
extends Modelica.Icons.ExamplesPackage;
package Led
extends Modelica.Icons.ExamplesPackage;
model ex1_led_blue
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanConstant booleanConstant1(k = true) annotation(
Placement(visible = true, transformation(origin = {-60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {61, -21}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
equation
connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{20, -20}, {60, -20}, {60, -20}, {62, -20}}));
connect(booleanConstant1.y, digitalOutput1.u) annotation(
Line(points = {{-38, -20}, {-20, -20}, {-20, -20}, {-20, -20}}, color = {255, 0, 255}));
end ex1_led_blue;
model ex2_led_blue_delay
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1(enableRealTimeScaling = false) annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanPulse booleanPulse1(period = 20, startTime = 5, width = 10) annotation(
Placement(visible = true, transformation(origin = {-60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(booleanPulse1.y, digitalOutput1.u) annotation(
Line(points = {{-38, -20}, {-20, -20}, {-20, -20}, {-20, -20}}, color = {255, 0, 255}));
connect(digitalOutput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, -20}, {60, -20}, {60, -20}, {60, -20}}));
end ex2_led_blue_delay;
model ex3_led_blue_red
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput2(Pin = 11) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanPulse booleanPulse1(period = 20, startTime = 5, width = 25) annotation(
Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanPulse booleanPulse2(period = 20, startTime = 5, width = 40) annotation(
Placement(visible = true, transformation(origin = {-60, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{20, 0}, {60, 0}, {60, -20}, {60, -20}}));
connect(digitalOutput2.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{20, -60}, {60, -60}, {60, -20}, {60, -20}}));
connect(booleanPulse2.y, digitalOutput2.u) annotation(
Line(points = {{-38, -60}, {-20, -60}, {-20, -60}, {-20, -60}}, color = {255, 0, 255}));
connect(booleanPulse1.y, digitalOutput1.u) annotation(
Line(points = {{-38, 0}, {-20, 0}, {-20, 0}, {-20, 0}}, color = {255, 0, 255}));
end ex3_led_blue_red;
model ex4_led_blink
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {42, -6}, extent = {{-14, -14}, {14, 14}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 10) annotation(
Placement(visible = true, transformation(origin = {-9, -7}, extent = {{-13, -13}, {13, 13}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanPulse booleanPulse1(period = 2, startTime = 4, width = 50) annotation(
Placement(visible = true, transformation(origin = {-68, -12}, extent = {{-14, -14}, {14, 14}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-19, 51}, extent = {{-13, -13}, {13, 13}}, rotation = 0)));
equation
connect(booleanPulse1.y, digitalOutput1.u) annotation(
Line(points = {{-53, -12}, {-24, -12}, {-24, -7}, {-22, -7}}, color = {255, 0, 255}));
connect(digitalOutput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{4, -7}, {22, -7}, {22, -6}, {42, -6}}));
annotation(
uses(OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2"), Modelica_DeviceDrivers(version = "1.5.0")));
end ex4_led_blink;
end Led;
package Push_button
extends Modelica.Icons.ExamplesPackage;
model ex1_push_button_status
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalInput digitalInput1(Pin = 12) annotation(
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interaction.Show.BooleanValue booleanValue1 annotation(
Placement(visible = true, transformation(origin = {80, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(digitalInput1.y, booleanValue1.activePort) annotation(
Line(points = {{20, 0}, {54, 0}, {54, 0}, {58, 0}}, color = {255, 0, 255}));
connect(arduino1.boardConnector, digitalInput1.pinConnector) annotation(
Line(points = {{-60, 0}, {-20, 0}}));
Modelica.Utilities.Streams.print(String(booleanValue1.activePort));
end ex1_push_button_status;
model ex2_led_push_button
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-60, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalInput digitalInput1(Pin = 12) annotation(
Placement(visible = true, transformation(origin = {62, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(customBoard1.boardConnector, digitalInput1.pinConnector) annotation(
Line(points = {{0, 0}, {44, 0}, {44, 0}, {42, 0}}));
connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{-40, 0}, {0, 0}, {0, 0}, {0, 0}}));
connect(digitalInput1.y, digitalOutput1.u) annotation(
Line(points = {{82, 0}, {94, 0}, {94, -40}, {-92, -40}, {-92, 0}, {-80, 0}, {-80, 0}}, color = {255, 0, 255}));
end ex2_led_push_button;
end Push_button;
package Ldr
extends Modelica.Icons.ExamplesPackage;
model ex1_ldr_read
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-60, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1024, MinValue = 0, Pin = 23, adcResolution = 12) annotation(
Placement(visible = true, transformation(origin = {-4.44089e-16, 4.44089e-16}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation(
Placement(visible = true, transformation(origin = {60, -8.88178e-16}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(analogInput1.y, realValue1.numberPort) annotation(
Line(points = {{20, 0}, {37, 0}}, color = {0, 0, 127}));
connect(arduino1.boardConnector, analogInput1.pinConnector) annotation(
Line(points = {{-60, 0}, {-20, 0}, {-20, 0}, {-20, 0}}));
Modelica.Utilities.Streams.print(String(realValue1.numberPort));
annotation(
uses(Modelica(version = "3.2.2")));
end ex1_ldr_read;
model ex2_ldr_led
extends Modelica.Icons.Example;
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 19) annotation(
Placement(visible = true, transformation(origin = {60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-70, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = 300) annotation(
Placement(visible = true, transformation(origin = {60, -70}, extent = {{20, -20}, {-20, 20}}, rotation = 0)));
Modelica.Blocks.Logical.Less less1 annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{20, -20}, {-20, 20}}, rotation = 0)));
OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(customBoard1.boardConnector, analogInput1.pinConnector) annotation(
Line(points = {{0, 20}, {40, 20}, {40, 20}, {40, 20}}));
connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{-40, 20}, {0, 20}, {0, 20}, {0, 20}}));
connect(const.y, less1.u2) annotation(
Line(points = {{38, -70}, {32, -70}, {32, -56}, {24, -56}}, color = {0, 0, 127}));
connect(less1.y, digitalOutput1.u) annotation(
Line(points = {{-22, -40}, {-92, -40}, {-92, 20}, {-80, 20}}, color = {255, 0, 255}));
connect(analogInput1.y, less1.u1) annotation(
Line(points = {{80, 20}, {90, 20}, {90, -40}, {24, -40}}, color = {0, 0, 127}));
end ex2_ldr_led;
end Ldr;
package DC_motor
extends Modelica.Icons.ExamplesPackage;
model ex1_dcmotor_clock
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {60, 4.21885e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, MinValue = 0, Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogOutput analogOutput2(MaxValue = 255, MinValue = 0, Pin = 10) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = 0) annotation(
Placement(visible = true, transformation(origin = {-60, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Pulse pulse1(amplitude = 255, period = 20, startTime = 5, width = 15) annotation(
Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(analogOutput2.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, -40}, {60, -40}, {60, 0}, {60, 0}}));
connect(analogOutput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, 20}, {60, 20}, {60, 0}, {60, 0}, {60, 0}}));
connect(const.y, analogOutput2.u) annotation(
Line(points = {{-38, -40}, {-22, -40}, {-22, -40}, {-20, -40}}, color = {0, 0, 127}));
connect(pulse1.y, analogOutput1.u) annotation(
Line(points = {{-38, 20}, {-22, 20}, {-22, 20}, {-20, 20}}, color = {0, 0, 127}));
end ex1_dcmotor_clock;
model ex2_dcmotor_both
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {60, 4.21885e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, MinValue = 0, Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogOutput analogOutput2(MaxValue = 255, MinValue = 0, Pin = 10) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Pulse pulse1(amplitude = 255, period = 20, startTime = 5, width = 15) annotation(
Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Pulse pulse2(amplitude = 255, period = 20, startTime = 8, width = 10) annotation(
Placement(visible = true, transformation(origin = {-60, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(pulse2.y, analogOutput2.u) annotation(
Line(points = {{-38, -40}, {-20, -40}, {-20, -40}, {-20, -40}}, color = {0, 0, 127}));
connect(analogOutput2.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, -40}, {60, -40}, {60, 0}, {60, 0}}));
connect(analogOutput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, 20}, {60, 20}, {60, 0}, {60, 0}, {60, 0}}));
connect(pulse1.y, analogOutput1.u) annotation(
Line(points = {{-38, 20}, {-22, 20}, {-22, 20}, {-20, 20}}, color = {0, 0, 127}));
end ex2_dcmotor_both;
model ex3_dcmotor_loop
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {60, 4.21885e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, MinValue = 0, Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 18}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogOutput analogOutput2(MaxValue = 255, MinValue = 0, Pin = 10) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Pulse pulse1(amplitude = 255, period = 10, startTime = 5, width = 30) annotation(
Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Pulse pulse2(amplitude = 255, period = 10, startTime = 10, width = 20) annotation(
Placement(visible = true, transformation(origin = {-60, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(pulse1.y, analogOutput1.u) annotation(
Line(points = {{-38, 20}, {-20, 20}, {-20, 18}}, color = {0, 0, 127}));
connect(analogOutput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, 18}, {20, 39}, {60, 39}, {60, 0}}));
connect(pulse2.y, analogOutput2.u) annotation(
Line(points = {{-38, -40}, {-20, -40}, {-20, -40}, {-20, -40}}, color = {0, 0, 127}));
connect(analogOutput2.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, -40}, {60, -40}, {60, 0}, {60, 0}}));
end ex3_dcmotor_loop;
end DC_motor;
package Potentiometer
extends Modelica.Icons.ExamplesPackage;
model ex1_pot_threshold
extends Modelica.Icons.Example;
OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 16) annotation(
Placement(visible = true, transformation(origin = {28, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-50, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput2(Pin = 10) annotation(
Placement(visible = true, transformation(origin = {-50, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 0) annotation(
Placement(visible = true, transformation(origin = {70, 10}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold2(threshold = 320) annotation(
Placement(visible = true, transformation(origin = {70, -30}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold3(threshold = 900) annotation(
Placement(visible = true, transformation(origin = {70, -70}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.Xor xor1 annotation(
Placement(visible = true, transformation(origin = {30, -10}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.Xor xor2 annotation(
Placement(visible = true, transformation(origin = {30, -50}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput3(Pin = 11) annotation(
Placement(visible = true, transformation(origin = {-50, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-10, 50}, extent = {{-14, -14}, {14, 14}}, rotation = 0)));
equation
connect(analogInput1.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{18, 50}, {-10, 50}}));
connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{-40, 90}, {-10, 90}, {-10, 50}}));
connect(digitalOutput2.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{-40, 50}, {-10, 50}}));
connect(digitalOutput3.pinConnector, customBoard1.boardConnector) annotation(
Line(points = {{-40, 10}, {-10, 10}, {-10, 50}}));
connect(xor1.y, digitalOutput3.u) annotation(
Line(points = {{20, -10}, {-72, -10}, {-72, 10}, {-60, 10}, {-60, 10}}, color = {255, 0, 255}));
connect(xor2.y, digitalOutput2.u) annotation(
Line(points = {{20, -50}, {-80, -50}, {-80, 50}, {-60, 50}, {-60, 50}}, color = {255, 0, 255}));
connect(greaterEqualThreshold3.y, digitalOutput1.u) annotation(
Line(points = {{60, -70}, {-90, -70}, {-90, 90}, {-60, 90}, {-60, 90}}, color = {255, 0, 255}));
connect(greaterEqualThreshold3.y, xor2.u2) annotation(
Line(points = {{60, -70}, {52, -70}, {52, -58}, {42, -58}, {42, -58}, {42, -58}}, color = {255, 0, 255}));
connect(greaterEqualThreshold2.y, xor2.u1) annotation(
Line(points = {{60, -30}, {52, -30}, {52, -50}, {42, -50}, {42, -50}}, color = {255, 0, 255}));
connect(greaterEqualThreshold2.y, xor1.u2) annotation(
Line(points = {{60, -30}, {52, -30}, {52, -18}, {42, -18}, {42, -18}}, color = {255, 0, 255}));
connect(greaterEqualThreshold1.y, xor1.u1) annotation(
Line(points = {{60, 10}, {50, 10}, {50, -10}, {42, -10}, {42, -10}}, color = {255, 0, 255}));
connect(analogInput1.y, greaterEqualThreshold1.u) annotation(
Line(points = {{38, 50}, {94, 50}, {94, 10}, {82, 10}, {82, 10}}, color = {0, 0, 127}));
connect(analogInput1.y, greaterEqualThreshold2.u) annotation(
Line(points = {{38, 50}, {94, 50}, {94, -30}, {82, -30}, {82, -30}, {82, -30}}, color = {0, 0, 127}));
connect(analogInput1.y, greaterEqualThreshold3.u) annotation(
Line(points = {{38, 50}, {94, 50}, {94, -70}, {82, -70}, {82, -70}}, color = {0, 0, 127}));
annotation(
uses(OpenModelicaArduino(version = "1.2")));
end ex1_pot_threshold;
end Potentiometer;
package Thermistor
extends Modelica.Icons.ExamplesPackage;
model ex1_therm_read
extends Modelica.Icons.Example;
OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 18) annotation(
Placement(visible = true, transformation(origin = {-4.44089e-16, 4.44089e-16}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-59, -1}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
equation
connect(customBoard1.boardConnector, analogInput1.pinConnector) annotation(
Line(points = {{-58, 0}, {-20, 0}, {-20, 0}, {-20, 0}}));
Modelica.Utilities.Streams.print(String(analogInput1.y));
end ex1_therm_read;
model ex2_therm_buzzer
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 3) annotation(
Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 18) annotation(
Placement(visible = true, transformation(origin = {60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-70, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = 500) annotation(
Placement(visible = true, transformation(origin = {60, -70}, extent = {{20, -20}, {-20, 20}}, rotation = 0)));
Modelica.Blocks.Logical.Greater greater1 annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{20, -20}, {-20, 20}}, rotation = 0)));
Modelica.Blocks.Interaction.Show.RealValue realValue1 annotation(
Placement(visible = true, transformation(origin = {40, 60}, extent = {{20, -20}, {-20, 20}}, rotation = 0)));
equation
connect(analogInput1.y, realValue1.numberPort) annotation(
Line(points = {{80, 20}, {90, 20}, {90, 60}, {64, 60}, {64, 60}}, color = {0, 0, 127}));
connect(greater1.y, digitalOutput1.u) annotation(
Line(points = {{-22, -40}, {-94, -40}, {-94, 20}, {-80, 20}, {-80, 20}}, color = {255, 0, 255}));
connect(analogInput1.y, greater1.u1) annotation(
Line(points = {{80, 20}, {92, 20}, {92, -40}, {24, -40}, {24, -40}}, color = {0, 0, 127}));
connect(greater1.u2, const.y) annotation(
Line(points = {{24, -56}, {32, -56}, {32, -70}, {38, -70}, {38, -70}}, color = {0, 0, 127}));
connect(arduino1.boardConnector, analogInput1.pinConnector) annotation(
Line(points = {{0, 20}, {40, 20}}));
connect(digitalOutput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{-40, 20}, {0, 20}}));
Modelica.Utilities.Streams.print(String(realValue1.numberPort));
annotation(
uses(Modelica(version = "3.2.2")));
end ex2_therm_buzzer;
end Thermistor;
package Servo_motor
extends Modelica.Icons.ExamplesPackage;
model ex1_servo_init
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {78, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 23) annotation(
Placement(visible = true, transformation(origin = {20, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = 0.1667) annotation(
Placement(visible = true, transformation(origin = {-40, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(const.y, servo1.u) annotation(
Line(points = {{-18, 20}, {-4, 20}, {-4, 20}, {0, 20}}, color = {0, 0, 127}));
connect(servo1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{40, 20}, {76, 20}, {76, 18}, {78, 18}, {78, 20}}));
annotation(
uses(Modelica_DeviceDrivers(version = "1.5.0"), OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2")));
end ex1_servo_init;
model ex2_servo_reverse
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {78, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 3) annotation(
Placement(visible = true, transformation(origin = {20, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Pulse pulse2(amplitude = 0.5, offset = 0.5, period = 2, startTime = 6, width = 50) annotation(
Placement(visible = true, transformation(origin = {-80, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Math.Product product1 annotation(
Placement(visible = true, transformation(origin = {-40, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = 0.5) annotation(
Placement(visible = true, transformation(origin = {-80, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(const.y, product1.u1) annotation(
Line(points = {{-58, 60}, {-36, 60}, {-36, 24}, {-80, 24}, {-80, 10}, {-64, 10}, {-64, 12}}, color = {0, 0, 127}));
connect(pulse2.y, product1.u2) annotation(
Line(points = {{-58, -60}, {-48, -60}, {-48, -24}, {-80, -24}, {-80, -12}, {-64, -12}, {-64, -12}}, color = {0, 0, 127}));
connect(product1.y, servo1.u) annotation(
Line(points = {{-18, 0}, {0, 0}, {0, 0}, {0, 0}}, color = {0, 0, 127}));
connect(servo1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{40, 0}, {78, 0}}));
annotation(
uses(Modelica_DeviceDrivers(version = "1.5.0"), OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2")));
end ex2_servo_reverse;
model ex3_servo_loop
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {78, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 23) annotation(
Placement(visible = true, transformation(origin = {20, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Sources.Ramp ramp1(duration = 10, height = 10, startTime = 5) annotation(
Placement(visible = true, transformation(origin = {-90, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.RealToInteger realToInteger1 annotation(
Placement(visible = true, transformation(origin = {-50, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = 0.11) annotation(
Placement(visible = true, transformation(origin = {-70, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.Product product1 annotation(
Placement(visible = true, transformation(origin = {-28, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.IntegerToReal integerToReal1 annotation(
Placement(visible = true, transformation(origin = {-10, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(integerToReal1.y, product1.u2) annotation(
Line(points = {{2, -70}, {14, -70}, {14, -36}, {-56, -36}, {-56, -6}, {-40, -6}, {-40, -6}}, color = {0, 0, 127}));
connect(realToInteger1.y, integerToReal1.u) annotation(
Line(points = {{-38, -70}, {-22, -70}, {-22, -70}, {-22, -70}}, color = {255, 127, 0}));
connect(ramp1.y, realToInteger1.u) annotation(
Line(points = {{-78, -70}, {-62, -70}}, color = {0, 0, 127}));
connect(const.y, product1.u1) annotation(
Line(points = {{-58, 68}, {-52, 68}, {-52, 6}, {-40, 6}, {-40, 6}}, color = {0, 0, 127}));
connect(product1.y, servo1.u) annotation(
Line(points = {{-16, 0}, {0, 0}, {0, 0}, {0, 0}}, color = {0, 0, 127}));
connect(servo1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{40, 0}, {78, 0}}));
annotation(
uses(Modelica_DeviceDrivers(version = "1.5.0"), OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2")));
end ex3_servo_loop;
model ex4_servo_pot
extends Modelica.Icons.Example;
OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation(
Placement(visible = true, transformation(origin = {60, 3.10862e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 9) annotation(
Placement(visible = true, transformation(origin = {-3.55271e-15, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1, MinValue = 0, Pin = 16) annotation(
Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation(
Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
connect(analogInput1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{-80, 0}, {-92, 0}, {-92, -52}, {60, -52}, {60, 0}, {60, 0}}));
connect(servo1.pinConnector, arduino1.boardConnector) annotation(
Line(points = {{20, 0}, {62, 0}, {62, 0}, {60, 0}, {60, 0}}));
connect(analogInput1.y, servo1.u) annotation(
Line(points = {{-40, 0}, {-16, 0}, {-16, 0}, {-20, 0}}, color = {0, 0, 127}));
annotation(
uses(OpenModelicaArduino(version = "1.2"), Modelica_DeviceDrivers(version = "1.5.0")));
end ex4_servo_pot;
end Servo_motor;
end ArduinoExamples;
|