Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pynxc/tutorial_samples/10_semaphore.py
diff options
context:
space:
mode:
Diffstat (limited to 'pynxc/tutorial_samples/10_semaphore.py')
-rw-r--r--pynxc/tutorial_samples/10_semaphore.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/pynxc/tutorial_samples/10_semaphore.py b/pynxc/tutorial_samples/10_semaphore.py
new file mode 100644
index 0000000..3b6a765
--- /dev/null
+++ b/pynxc/tutorial_samples/10_semaphore.py
@@ -0,0 +1,41 @@
+sem=0 # make sure this one is global
+
+def task_move_square():
+ while True:
+ while (sem == 1):
+ pass
+ sem = 1
+ OnFwd(OUT_AC, 75)
+ sem = 0
+ Wait(1000)
+
+ while sem==1:
+ pass
+
+ sem = 1
+
+
+ OnRev(OUT_C, 75)
+ sem = 0
+ Wait(850)
+
+def task_submain():
+
+ SetSensor(IN_1, SENSOR_TOUCH)
+ while True:
+
+ if SENSOR_1 == 1:
+ while (sem == 1):
+ pass
+ sem = 1
+ OnRev(OUT_AC, 75); Wait(500)
+ OnFwd(OUT_A, 75); Wait(850)
+ sem = 0
+
+def main():
+
+ sem = 0
+ Precedes(task_move_square, task_submain)
+
+
+