summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSudhakarKuma2021-05-03 19:01:27 +0530
committerSudhakarKuma2021-05-03 19:01:27 +0530
commit01c8d8fcf307ae5a84862ac89b70102dbdc006eb (patch)
tree41c3abf923cb07876e24a2b8e92d61ac7241fb02
parenta5719314bcd2a0f41ce6299700fa30adeb087834 (diff)
downloadFLOSS-Arduino-Book-01c8d8fcf307ae5a84862ac89b70102dbdc006eb.tar.gz
FLOSS-Arduino-Book-01c8d8fcf307ae5a84862ac89b70102dbdc006eb.tar.bz2
FLOSS-Arduino-Book-01c8d8fcf307ae5a84862ac89b70102dbdc006eb.zip
Maintain consistency in LDR codes
-rw-r--r--tools/openmodelica/windows/Arduino.mo18
-rw-r--r--user-code/ldr/OpenModelica/ldr-led.mo28
-rw-r--r--user-code/ldr/OpenModelica/ldr-read.mo18
-rw-r--r--user-code/ldr/arduino/ldr-led/ldr-led.ino5
-rw-r--r--user-code/ldr/arduino/ldr-read/ldr-read.ino2
-rw-r--r--user-code/ldr/julia/ldr-led.jl12
-rw-r--r--user-code/ldr/julia/ldr-read.jl3
-rw-r--r--user-code/ldr/python/ldr-led.py4
-rw-r--r--user-code/ldr/python/ldr-read.py2
-rw-r--r--user-code/ldr/scilab/ldr-led-xcos.zcosbin5666 -> 0 bytes
-rw-r--r--user-code/ldr/scilab/ldr-led.sce5
-rw-r--r--user-code/ldr/scilab/ldr-led.zcosbin0 -> 5769 bytes
-rw-r--r--user-code/ldr/scilab/ldr-read-xcos.zcosbin4604 -> 0 bytes
-rw-r--r--user-code/ldr/scilab/ldr-read.sce4
-rw-r--r--user-code/ldr/scilab/ldr-read.zcosbin0 -> 4596 bytes
15 files changed, 53 insertions, 48 deletions
diff --git a/tools/openmodelica/windows/Arduino.mo b/tools/openmodelica/windows/Arduino.mo
index b15bb3b..47954f5 100644
--- a/tools/openmodelica/windows/Arduino.mo
+++ b/tools/openmodelica/windows/Arduino.mo
@@ -640,7 +640,7 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa);
import sComm = Arduino.SerialCommunication.Functions;
import strm = Modelica.Utilities.Streams;
Integer ok(fixed = false);
- Integer analog_in(fixed = false);
+ Integer val(fixed = false);
Integer digital_out(fixed = false);
Integer c_ok(fixed = false);
algorithm
@@ -651,12 +651,12 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa);
if ok <> 0 then
strm.print("Unable to open serial port, please check");
else
- analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
- strm.print("LDR Readings: " + String(analog_in));
- if analog_in < 300 then
- digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED";
+ val := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
+ strm.print("LDR Readings: " + String(val));
+ if val < 300 then
+ digital_out := sComm.cmd_digital_out(1, 11, 1) "Turn ON LED";
else
- digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED";
+ digital_out := sComm.cmd_digital_out(1, 11, 0) "Turn OFF LED";
end if;
sComm.delay(500);
end if;
@@ -674,7 +674,7 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa);
import sComm = Arduino.SerialCommunication.Functions;
import strm = Modelica.Utilities.Streams;
Integer ok(fixed = false);
- Integer analog_in(fixed = false);
+ Integer val(fixed = false);
Integer c_ok(fixed = false);
algorithm
when initial() then
@@ -684,8 +684,8 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa);
if ok <> 0 then
strm.print("Unable to open serial port, please check");
else
- analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
- strm.print("LDR Readings: " + String(analog_in));
+ val := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
+ strm.print("LDR Readings: " + String(val));
sComm.delay(500);
end if;
when time >= 10 then
diff --git a/user-code/ldr/OpenModelica/ldr-led.mo b/user-code/ldr/OpenModelica/ldr-led.mo
index d6a1727..4cac30f 100644
--- a/user-code/ldr/OpenModelica/ldr-led.mo
+++ b/user-code/ldr/OpenModelica/ldr-led.mo
@@ -10,24 +10,24 @@ algorithm
when initial() then
ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
sComm.delay(2000);
- end when;
+ end when;
if ok <> 0 then
- strm.print("Unable to open serial port, please check");
+ strm.print("Unable to open serial port, please check");
else
- val := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
- strm.print("LDR Readings: " + String(val));
- if val < 300 then
- digital_out := sComm.cmd_digital_out(1, 11, 1) "Turn ON LED";
- else
- digital_out := sComm.cmd_digital_out(1, 11, 0) "Turn OFF LED";
- end if;
- sComm.delay(500);
+ val := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
+ strm.print("LDR Readings: " + String(val));
+ if val < 300 then
+ digital_out := sComm.cmd_digital_out(1, 11, 1) "Turn ON LED";
+ else
+ digital_out := sComm.cmd_digital_out(1, 11, 0) "Turn OFF LED";
+ end if;
+ sComm.delay(500);
end if;
- //strm.print(String(time));
+//strm.print(String(time));
when time >= 10 then
c_ok := sComm.close_serial(1) "To close the connection safely";
end when;
- //Run for 500 iterations
- //Setting Threshold value of 300
- annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.2));
+//Setting Threshold value of 300
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.2));
end ldr_led;
diff --git a/user-code/ldr/OpenModelica/ldr-read.mo b/user-code/ldr/OpenModelica/ldr-read.mo
index 2debeb4..d648d0b 100644
--- a/user-code/ldr/OpenModelica/ldr-read.mo
+++ b/user-code/ldr/OpenModelica/ldr-read.mo
@@ -9,17 +9,17 @@ algorithm
when initial() then
ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
sComm.delay(2000);
- if ok <> 0 then
- strm.print("Unable to open serial port, please check");
- else
- val := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
- strm.print("LDR Readings: " + String(val));
- sComm.delay(500);
- end if;
end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ val := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
+ strm.print("LDR Readings: " + String(val));
+ sComm.delay(500);
+ end if;
when time >= 10 then
c_ok := sComm.close_serial(1) "To close the connection safely";
end when;
- //Run for 10 iterations
- annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1));
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1));
end ldr_read;
diff --git a/user-code/ldr/arduino/ldr-led/ldr-led.ino b/user-code/ldr/arduino/ldr-led/ldr-led.ino
index 964401c..c7b521e 100644
--- a/user-code/ldr/arduino/ldr-led/ldr-led.ino
+++ b/user-code/ldr/arduino/ldr-led/ldr-led.ino
@@ -3,9 +3,9 @@ int i = 1;
void setup() {
pinMode(11, OUTPUT); // LED Pin
Serial.begin(115200);
-for(i = 1; i <= 2000; i++){
+for(i = 1; i <= 50; i++){
val = analogRead(A5); // Value of LDR
- // Serial.println(val);
+ Serial.println(val);
if(val < 300){ // Threshold
digitalWrite(11, HIGH);
}
@@ -13,6 +13,7 @@ for(i = 1; i <= 2000; i++){
{
digitalWrite(11, LOW);
}
+ delay(500);
}
}
void loop() {
diff --git a/user-code/ldr/arduino/ldr-read/ldr-read.ino b/user-code/ldr/arduino/ldr-read/ldr-read.ino
index 7573fa6..d92c204 100644
--- a/user-code/ldr/arduino/ldr-read/ldr-read.ino
+++ b/user-code/ldr/arduino/ldr-read/ldr-read.ino
@@ -2,7 +2,7 @@ int val; // for LDR
int i = 1;
void setup() {
Serial.begin(115200);
-for(i = 1; i <= 20; i++){
+for(i = 1; i <= 50; i++){
val = analogRead(A5); // value of LDR
Serial.println(val); // for display
delay(500);
diff --git a/user-code/ldr/julia/ldr-led.jl b/user-code/ldr/julia/ldr-led.jl
index 1abe642..501d4a6 100644
--- a/user-code/ldr/julia/ldr-led.jl
+++ b/user-code/ldr/julia/ldr-led.jl
@@ -3,10 +3,14 @@ include("ArduinoTools.jl")
ser = ArduinoTools.connectBoard(115200)
ArduinoTools.pinMode(ser, 11, "OUTPUT")
-for i = 1:500
+for i = 1:50
val = ArduinoTools.analogRead(ser, 5)
- # println(val)
- if val > 300 ArduinoTools.digiWrite(ser, 11, 0)
- else ArduinoTools.digiWrite(ser, 11, 1) end
+ println(val)
+ if val > 300
+ ArduinoTools.digiWrite(ser, 11, 0)
+ else
+ ArduinoTools.digiWrite(ser, 11, 1)
+ end
+ sleep(0.5)
end
close(ser)
diff --git a/user-code/ldr/julia/ldr-read.jl b/user-code/ldr/julia/ldr-read.jl
index 19554c1..ce3abf3 100644
--- a/user-code/ldr/julia/ldr-read.jl
+++ b/user-code/ldr/julia/ldr-read.jl
@@ -2,10 +2,9 @@ using SerialPorts
include("ArduinoTools.jl")
ser = ArduinoTools.connectBoard(115200)
-for i = 1:20
+for i = 1:50
val = ArduinoTools.analogRead(ser, 5)
println(val)
sleep(0.5)
end
-
close(ser)
diff --git a/user-code/ldr/python/ldr-led.py b/user-code/ldr/python/ldr-led.py
index 554e4f6..46de4bf 100644
--- a/user-code/ldr/python/ldr-led.py
+++ b/user-code/ldr/python/ldr-led.py
@@ -24,9 +24,9 @@ class LDR:
self.blue = 9
self.green = 10
self.red = 11
- for i in range(100):
+ for i in range(50):
val = self.obj_arduino.cmd_analog_in(1, self.ldr)
- # print (val)
+ print (val)
if int(val) < 300:
self.obj_arduino.cmd_digital_out(1, self.red, 1)
else:
diff --git a/user-code/ldr/python/ldr-read.py b/user-code/ldr/python/ldr-read.py
index 0e9f585..495cedf 100644
--- a/user-code/ldr/python/ldr-read.py
+++ b/user-code/ldr/python/ldr-read.py
@@ -21,7 +21,7 @@ class LDR:
def run(self):
self.ldr = 5
- for i in range(20):
+ for i in range(50):
val = self.obj_arduino.cmd_analog_in(1, self.ldr)
print(val)
sleep(0.5)
diff --git a/user-code/ldr/scilab/ldr-led-xcos.zcos b/user-code/ldr/scilab/ldr-led-xcos.zcos
deleted file mode 100644
index df2770e..0000000
--- a/user-code/ldr/scilab/ldr-led-xcos.zcos
+++ /dev/null
Binary files differ
diff --git a/user-code/ldr/scilab/ldr-led.sce b/user-code/ldr/scilab/ldr-led.sce
index 02444cb..b37ff4a 100644
--- a/user-code/ldr/scilab/ldr-led.sce
+++ b/user-code/ldr/scilab/ldr-led.sce
@@ -1,12 +1,13 @@
ok = open_serial(1, 2, 115200); // port 2, baudrate 115200
if ok ~= 0 then error('Unable to open serial port, please check'); end
-for i = 1:500 //Run for 500 iterations
+for i = 1:50 //Run for 50 iterations
val = cmd_analog_in(1, 5) // read analog pin 5 (ldr)
- // disp(val);
+ disp(val);
if(val < 300) // Setting Threshold value of 300
cmd_digital_out(1, 11, 1) // Turn ON LED
else
cmd_digital_out(1, 11, 0) // Turn OFF LED
end
+ sleep(500)
end
close_serial(1);
diff --git a/user-code/ldr/scilab/ldr-led.zcos b/user-code/ldr/scilab/ldr-led.zcos
new file mode 100644
index 0000000..68b28db
--- /dev/null
+++ b/user-code/ldr/scilab/ldr-led.zcos
Binary files differ
diff --git a/user-code/ldr/scilab/ldr-read-xcos.zcos b/user-code/ldr/scilab/ldr-read-xcos.zcos
deleted file mode 100644
index bcd347e..0000000
--- a/user-code/ldr/scilab/ldr-read-xcos.zcos
+++ /dev/null
Binary files differ
diff --git a/user-code/ldr/scilab/ldr-read.sce b/user-code/ldr/scilab/ldr-read.sce
index 343b44d..7bef0da 100644
--- a/user-code/ldr/scilab/ldr-read.sce
+++ b/user-code/ldr/scilab/ldr-read.sce
@@ -1,6 +1,6 @@
ok = open_serial(1, 2, 115200); // Port 2 with baudrate 115200
-if ok ~= 0 then error('Unable to open serial port. Please check') end
-for i = 1:20 // Run for 20 iterations
+if ok ~= 0 then error('Unable to open serial port. Please check'); end
+for i = 1:50 // Run for 50 iterations
val = cmd_analog_in(1, 5); // read analog pin 5 (ldr)
disp(val);
sleep(500) // Delay of 500 milliseconds
diff --git a/user-code/ldr/scilab/ldr-read.zcos b/user-code/ldr/scilab/ldr-read.zcos
new file mode 100644
index 0000000..1d49e52
--- /dev/null
+++ b/user-code/ldr/scilab/ldr-read.zcos
Binary files differ