From 3cd59c172f2fedcec8646175627fe5bab0bcbdcb Mon Sep 17 00:00:00 2001 From: JJ Lee Date: Sun, 18 Aug 2024 23:53:13 +0500 Subject: [PATCH] Refactor NeoSoco sample codes --- mu/resources/neopia/01-02_FutbolBot.py | 4 +++- mu/resources/neopia/01-06_Sehrli_ansanmbl.py | 1 + mu/resources/neopia/02-01-01_Barami.py | 1 + mu/resources/neopia/02-01-02_Barami.py | 2 ++ mu/resources/neopia/02-03_Neo_kliner.py | 1 + mu/resources/neopia/02-04-01_Aqlli_avtomobil.py | 1 + mu/resources/neopia/02-04-02_Aqlli_avtomobil.py | 1 + ...02-05-01_Chiziq_trekkeri.py => 02-05-01_Chiziq_trekeri.py} | 1 + ...02-05-02_Chiziq_trekkeri.py => 02-05-02_Chiziq_trekeri.py} | 1 + mu/resources/neopia/04-01_Fonar.py | 1 + mu/resources/neopia/04-03-01_Aqlli_avtomobil_2.py | 1 + mu/resources/neopia/04-03-02_Aqlli_avtomobil_2.py | 1 + mu/resources/neopia/04-04_Samosval_avtomobili.py | 2 ++ mu/resources/neopia/04-05_Robot_qol.py | 1 + mu/resources/neopia/04-06_Konveyer.py | 2 ++ 15 files changed, 20 insertions(+), 1 deletion(-) rename mu/resources/neopia/{02-05-01_Chiziq_trekkeri.py => 02-05-01_Chiziq_trekeri.py} (95%) rename mu/resources/neopia/{02-05-02_Chiziq_trekkeri.py => 02-05-02_Chiziq_trekeri.py} (96%) diff --git a/mu/resources/neopia/01-02_FutbolBot.py b/mu/resources/neopia/01-02_FutbolBot.py index c96b2a04e..4795b5556 100644 --- a/mu/resources/neopia/01-02_FutbolBot.py +++ b/mu/resources/neopia/01-02_FutbolBot.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + def on_press(key): if key == Keyboard.UP: n.motor_rotate('both', 'forward', '10') @@ -14,5 +15,6 @@ def on_press(key): n.motor_stop('both') elif key == Keyboard.ESC: return False - + +# Klaviaturning tugmachasini bosganda "on_press" funksiyasi chaqriladi Keyboard.read(on_press) \ No newline at end of file diff --git a/mu/resources/neopia/01-06_Sehrli_ansanmbl.py b/mu/resources/neopia/01-06_Sehrli_ansanmbl.py index 23da41b1d..1eab8edc4 100644 --- a/mu/resources/neopia/01-06_Sehrli_ansanmbl.py +++ b/mu/resources/neopia/01-06_Sehrli_ansanmbl.py @@ -3,6 +3,7 @@ from neopia import * n = Neosoco() + while True: n.buzzer_by_port('in1') wait(200) diff --git a/mu/resources/neopia/02-01-01_Barami.py b/mu/resources/neopia/02-01-01_Barami.py index 2b96d7800..6cd1b9d90 100644 --- a/mu/resources/neopia/02-01-01_Barami.py +++ b/mu/resources/neopia/02-01-01_Barami.py @@ -3,6 +3,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in3') < 30: n.motor_stop('right') diff --git a/mu/resources/neopia/02-01-02_Barami.py b/mu/resources/neopia/02-01-02_Barami.py index 66904e680..bfdea1065 100644 --- a/mu/resources/neopia/02-01-02_Barami.py +++ b/mu/resources/neopia/02-01-02_Barami.py @@ -3,6 +3,7 @@ from neopia import * n = Neosoco() + def on_press(key): if Keyboard.key_to_str(key) == '0': n.motor_stop('right') @@ -15,4 +16,5 @@ def on_press(key): elif key == Keyboard.ESC: return False +# Klaviaturning tugmachasini bosganda "on_press" funksiyasi chaqriladi Keyboard.read(on_press) \ No newline at end of file diff --git a/mu/resources/neopia/02-03_Neo_kliner.py b/mu/resources/neopia/02-03_Neo_kliner.py index 73138a151..433111118 100644 --- a/mu/resources/neopia/02-03_Neo_kliner.py +++ b/mu/resources/neopia/02-03_Neo_kliner.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in1') < 20: n.motor_rotate('both', 'forward', '50') diff --git a/mu/resources/neopia/02-04-01_Aqlli_avtomobil.py b/mu/resources/neopia/02-04-01_Aqlli_avtomobil.py index 22f48dc76..2b611ca82 100644 --- a/mu/resources/neopia/02-04-01_Aqlli_avtomobil.py +++ b/mu/resources/neopia/02-04-01_Aqlli_avtomobil.py @@ -3,6 +3,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in2') <= 7: n.motor_move('backward') diff --git a/mu/resources/neopia/02-04-02_Aqlli_avtomobil.py b/mu/resources/neopia/02-04-02_Aqlli_avtomobil.py index eed3bb390..5b94d9645 100644 --- a/mu/resources/neopia/02-04-02_Aqlli_avtomobil.py +++ b/mu/resources/neopia/02-04-02_Aqlli_avtomobil.py @@ -3,6 +3,7 @@ from neopia import * n = Neosoco() + while True: n.motor_rotate('both', 'forward', 'in2') n.buzzer_by_port('in2') \ No newline at end of file diff --git a/mu/resources/neopia/02-05-01_Chiziq_trekkeri.py b/mu/resources/neopia/02-05-01_Chiziq_trekeri.py similarity index 95% rename from mu/resources/neopia/02-05-01_Chiziq_trekkeri.py rename to mu/resources/neopia/02-05-01_Chiziq_trekeri.py index 60aeb65ac..7204373dd 100644 --- a/mu/resources/neopia/02-05-01_Chiziq_trekkeri.py +++ b/mu/resources/neopia/02-05-01_Chiziq_trekeri.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in1') and n.get_value('in2') > 40: n.motor_rotate('both', 'forward', '30') diff --git a/mu/resources/neopia/02-05-02_Chiziq_trekkeri.py b/mu/resources/neopia/02-05-02_Chiziq_trekeri.py similarity index 96% rename from mu/resources/neopia/02-05-02_Chiziq_trekkeri.py rename to mu/resources/neopia/02-05-02_Chiziq_trekeri.py index afb41b8c9..311b7ec11 100644 --- a/mu/resources/neopia/02-05-02_Chiziq_trekkeri.py +++ b/mu/resources/neopia/02-05-02_Chiziq_trekeri.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in1') and n.get_value('in2') > 40: n.motor_rotate('both', 'forward', '30') diff --git a/mu/resources/neopia/04-01_Fonar.py b/mu/resources/neopia/04-01_Fonar.py index f9f389d81..fb50a0440 100644 --- a/mu/resources/neopia/04-01_Fonar.py +++ b/mu/resources/neopia/04-01_Fonar.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in1') == 255: n.led_on('out1', '100') diff --git a/mu/resources/neopia/04-03-01_Aqlli_avtomobil_2.py b/mu/resources/neopia/04-03-01_Aqlli_avtomobil_2.py index 9ebd3483c..7e43f0873 100644 --- a/mu/resources/neopia/04-03-01_Aqlli_avtomobil_2.py +++ b/mu/resources/neopia/04-03-01_Aqlli_avtomobil_2.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in2') <= 10: n.motor_stop('both') diff --git a/mu/resources/neopia/04-03-02_Aqlli_avtomobil_2.py b/mu/resources/neopia/04-03-02_Aqlli_avtomobil_2.py index 989b00fcd..d41ded5f1 100644 --- a/mu/resources/neopia/04-03-02_Aqlli_avtomobil_2.py +++ b/mu/resources/neopia/04-03-02_Aqlli_avtomobil_2.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + # Masofa sensor orqali to‘siqni tekshirish uchun funksiya yaratish def servo_motor(): n.motor_stop('both') diff --git a/mu/resources/neopia/04-04_Samosval_avtomobili.py b/mu/resources/neopia/04-04_Samosval_avtomobili.py index 5bcc214a2..35205f5e3 100644 --- a/mu/resources/neopia/04-04_Samosval_avtomobili.py +++ b/mu/resources/neopia/04-04_Samosval_avtomobili.py @@ -2,6 +2,7 @@ n = Neosoco() n.servo_reset_degree('out1') + def on_press(key): if Keyboard.key_to_str(key) == '4': n.servo_rotate_by_degree('out1', 'forward', '20', '60') @@ -10,4 +11,5 @@ def on_press(key): elif key == Keyboard.ESC: return False +# Klaviaturning tugmachasini bosganda "on_press" funksiyasi chaqriladi Keyboard.read(on_press) \ No newline at end of file diff --git a/mu/resources/neopia/04-05_Robot_qol.py b/mu/resources/neopia/04-05_Robot_qol.py index 5feb78199..f647298a3 100644 --- a/mu/resources/neopia/04-05_Robot_qol.py +++ b/mu/resources/neopia/04-05_Robot_qol.py @@ -1,6 +1,7 @@ from neopia import * n = Neosoco() + while True: if n.get_value('in1') < 80 and n.get_value('in2') < 80: n.servo_stop('out1') diff --git a/mu/resources/neopia/04-06_Konveyer.py b/mu/resources/neopia/04-06_Konveyer.py index c9aa1ae3b..2341b9233 100644 --- a/mu/resources/neopia/04-06_Konveyer.py +++ b/mu/resources/neopia/04-06_Konveyer.py @@ -1,8 +1,10 @@ from neopia import * n = Neosoco() + n.servo_reset_degree('out1') n.motor_rotate('both', 'forward', '40') + while True: if n.get_value('in1') > 20 and n.get_value('in2') > 20: n.servo_rotate_by_degree('out1', 'forward', '50', '20')