Skip to content

Commit

Permalink
Neopia examples (#4)
Browse files Browse the repository at this point in the history
Add neopia examples
  • Loading branch information
BCKM authored Jul 31, 2024
1 parent 8f775c6 commit 2df6015
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 1 deletion.
30 changes: 29 additions & 1 deletion mu/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@
"flappybird.py",
"flappybird_neosoco.py",
]
EXAMPLE_NEOPIA = [
"01-01_KobiBot.py",
"01-02_FutbolBot.py",
"01-06_Sehrli_ansanmbl.py",
"02-01-01_Barami.py",
"02-01-02_Barami.py",
"02-02_Neo_Bigl.py",
"02-03_Neo_kliner.py",
"02-04-01_Aqlli_avtomobil.py",
"02-04-02_Aqlli_avtomobil.py",
"02-05-01_Chiziq_trekkeri.py",
"02-05-02_Chiziq_trekkeri.py",
"04-01_Fonar.py",
"04-03-01_Aqlli_avtomobil_2.py",
"04-03-02_Aqlli_avtomobil_2.py",
"04-04_Samosval_avtomobili.py",
"04-05_Robot_qol.py",
"04-06_Konveyer.py"
]

MOTD = [ # Candidate phrases for the message of the day (MOTD).
_("Hello, World!"),
Expand Down Expand Up @@ -906,6 +925,7 @@ def setup(self, modes):
examples_path = os.path.join(wd, "examples")
example_entry_b_path = os.path.join(wd, "examples/entry_basic/")
example_pgz_path = os.path.join(wd, "examples/pygame_zero/")
example_neopia_path = os.path.join(wd, "examples/neopia/")
if not os.path.exists(images_path):
logger.debug("Creating directory: {}".format(images_path))
os.makedirs(images_path)
Expand Down Expand Up @@ -984,7 +1004,15 @@ def setup(self, modes):
for sfx in EXAMPLE_PGZ_IMAGES:
shutil.copy(
path(sfx, "pygamezero/"), os.path.join(example_pgz_path + 'images', sfx)
)
)
# Neopia examples
if not os.path.exists(example_neopia_path):
logger.debug("Creating directory: {}".format(example_neopia_path))
os.makedirs(example_neopia_path)
for sfx in EXAMPLE_NEOPIA:
shutil.copy(
path(sfx, "neopia/"), os.path.join(example_neopia_path, sfx)
)
# Ensure Web based assets are copied over.
template_path = os.path.join(wd, "templates")
static_path = os.path.join(wd, "static")
Expand Down
15 changes: 15 additions & 0 deletions mu/resources/neopia/01-01_KobiBot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from neopia import *

n = Neosoco()

# LEDni yoqib 1 soniyadan keyin o'chirish
n.led_on('out1','100')
wait(1000) # milisekund orqali hisoblanadi


# Takrorlab miltiratish
while True:
n.led_on('out1','100')
wait(1000)
n.led_off('out1')
wait(1000)
15 changes: 15 additions & 0 deletions mu/resources/neopia/01-02_FutbolBot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from neopia import *

n = Neosoco()
while True:
key = Keyboard.read()
if key == Keyboard.UP:
n.motor_rotate('both', 'forward', '10')
elif key == Keyboard.DOWN:
n.motor_rotate('both', 'backward', '10')
elif key == Keyboard.LEFT:
n.motor_rotate('both', 'left', '10')
elif key == Keyboard.RIGHT:
n.motor_rotate('both', 'right', '10')
elif key == ' ':
n.motor_stop('both')
9 changes: 9 additions & 0 deletions mu/resources/neopia/01-06_Sehrli_ansanmbl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ichki buzzer orqali yangrash

from neopia import *

n = Neosoco()
while True:
n.buzzer_by_port('in1')
wait(200)
n.buzzer_stop()
11 changes: 11 additions & 0 deletions mu/resources/neopia/02-01-01_Barami.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ovoz sensor orqali Baramining tezligini boshqarish

from neopia import *

n = Neosoco()
while True:
if n.get_value('in3') < 30:
n.motor_stop('right')
else:
n.motor_rotate('right', 'forward', 'in3')

15 changes: 15 additions & 0 deletions mu/resources/neopia/02-01-02_Barami.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Klaviatura orqali Baramining tezligini boshqarish

from neopia import *

n = Neosoco()
while True:
key = Keyboard.read()
if key == '0':
n.motor_stop('right')
elif key == '1':
n.motor_rotate('right', 'forward', '10')
elif key == '2':
n.motor_rotate('right', 'forward', '50')
elif key == '3':
n.motor_rotate('right', 'forward', '100')
13 changes: 13 additions & 0 deletions mu/resources/neopia/02-02_Neo_Bigl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from neopia import *

n = Neosoco()

while True:
while n.get_value('in3') > 50:
continue
while n.get_value('in3') <= 50:
continue

n.motor_rotate('both', 'left', '50')
wait(3000)
n.motor_stop('both')
8 changes: 8 additions & 0 deletions mu/resources/neopia/02-03_Neo_kliner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from neopia import *

n = Neosoco()
while True:
if n.get_value('in1') < 20:
n.motor_rotate('both', 'forward', '50')
else:
n.motor_stop('both')
16 changes: 16 additions & 0 deletions mu/resources/neopia/02-04-01_Aqlli_avtomobil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Masofa sensor orqali to’siqdan qochish dasturi

from neopia import *

n = Neosoco()
while True:
if n.get_value('in2') <= 7:
n.motor_move('backward')
wait(500)
n.motor_stop('both')
n.motor_move('left')
wait(1000)
n.motor_stop('both')
else:
n.motor_rotate('both', 'forward', '50')

8 changes: 8 additions & 0 deletions mu/resources/neopia/02-04-02_Aqlli_avtomobil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Acc Kontrol dasturalsh

from neopia import *

n = Neosoco()
while True:
n.motor_rotate('both', 'forward', 'in2')
n.buzzer_by_port('in2')
11 changes: 11 additions & 0 deletions mu/resources/neopia/02-05-01_Chiziq_trekkeri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from neopia import *

n = Neosoco()
while True:
if n.get_value('in1') and n.get_value('in2') > 40:
n.motor_rotate('both', 'forward', '30')
else:
if n.get_value('in1') <= 40:
n.motor_stop('left')
if n.get_value('in2') <= 40:
n.motor_stop('right')
15 changes: 15 additions & 0 deletions mu/resources/neopia/02-05-02_Chiziq_trekkeri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from neopia import *

n = Neosoco()
while True:
if n.get_value('in1') and n.get_value('in2') > 40:
n.motor_rotate('both', 'forward', '30')
else:
if n.get_value('in1') <= 40:
n.motor_stop('left')
if n.get_value('in2') <= 40:
n.motor_stop('right')
if n.get_value('in1') and n.get_value('in2') <= 40:
n.motor_move('left')
wait(500)
n.motor_stop('both')
8 changes: 8 additions & 0 deletions mu/resources/neopia/04-01_Fonar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from neopia import *

n = Neosoco()
while True:
if n.get_value('in1') == 255:
n.led_on('out1', '100')
else:
n.led_off('out1')
24 changes: 24 additions & 0 deletions mu/resources/neopia/04-03-01_Aqlli_avtomobil_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from neopia import *

n = Neosoco()
while True:
if n.get_value('in2') <= 10:
n.motor_stop('both')
n.servo_reset_degree('out3')
wait(100)
n.servo_rotate_by_degree('out3', 'forward', '100', '90')
wait(1000)
chap_m = n.get_value('in2')
n.servo_rotate_by_degree('out3', 'backward', '100', '90')
wait(1000)
ong_m = n.get_value('in2')
n.servo_rotate_by_degree('out3', 'forward', '100', '0')
wait(1000)
if chap_m > ong_m:
n.motor_rotate('both', 'left', '50')
wait(1000)
else:
n.motor_rotate('both', 'right', '50')
wait(1000)
else:
n.motor_rotate('both', 'forward', '50')
31 changes: 31 additions & 0 deletions mu/resources/neopia/04-03-02_Aqlli_avtomobil_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from neopia import *

n = Neosoco()
# Masofa sensor orqali to‘siqni tekshirish uchun funksiya yaratish
def servo_motor():
n.motor_stop('both')
n.servo_reset_degree('out3')
wait(100)
n.servo_rotate_by_degree('out3', 'forward', '100', '90')
wait(1000)
global chap_m
chap_m = n.get_value('in2')
n.servo_rotate_by_degree('out3', 'backward', '100', '90')
wait(1000)
global ong_m
ong_m = n.get_value('in2')
n.servo_rotate_by_degree('out3', 'forward', '100', '0')
wait(1000)

# Funksiyadan foydalanib dastur tuzish
while True:
if n.get_value('in2') <= 10:
servo_motor()
if chap_m > ong_m:
n.motor_rotate('both', 'right', '50')
wait(1000)
else:
n.motor_rotate('both', 'left', '50')
wait(1000)
else:
n.motor_rotate('both', 'forward', '50')
10 changes: 10 additions & 0 deletions mu/resources/neopia/04-04_Samosval_avtomobili.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from neopia import *

n = Neosoco()
n.servo_reset_degree('out1')
while True:
key = Keyboard.read()
if key == '4':
n.servo_rotate_by_degree('out1', 'forward', '20', '60')
if key == '1':
n.servo_rotate_by_degree('out1', 'forward', '20', '0')
16 changes: 16 additions & 0 deletions mu/resources/neopia/04-05_Robot_qol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from neopia import *

n = Neosoco()
while True:
if n.get_value('in1') < 80 and n.get_value('in2') < 80:
n.servo_stop('out1')
n.motor_stop('both')
elif n.get_value('in1') > 80 and n.get_value('in2') > 80:
n.servo_stop('out1')
n.motor_rotate('both', 'backward', '40')
elif n.get_value('in1') > 80 and n.get_value('in2') < 80:
n.servo_rotate('out1', 'forward', '10')
n.motor_rotate('both', 'forward', '30')
elif n.get_value('in1') < 80 and n.get_value('in2') > 80:
n.servo_rotate('out1', 'backward', '10')
n.motor_rotate('both', 'forward', '30')
13 changes: 13 additions & 0 deletions mu/resources/neopia/04-06_Konveyer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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')
wait(500)
if n.get_value('in1') <= 20 and n.get_value('in2') <= 20:
if n.get_value('in2') > 0:
n.servo_rotate_by_degree('out1', 'backward', '50', '20')
wait(500)

0 comments on commit 2df6015

Please sign in to comment.