special version from alarm node with serial
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 Jul 2023 09:23:26 +0000 (11:23 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 Jul 2023 09:23:26 +0000 (11:23 +0200)
1/gumb.py

index d7785cb..36beb82 100755 (executable)
--- a/1/gumb.py
+++ b/1/gumb.py
@@ -3,6 +3,19 @@
 import time
 import RPi.GPIO as GPIO
 import pygame
+#import os
+import serial
+ser = serial.Serial(
+       port='/dev/ttyAMA0',
+       baudrate=9600,
+       parity=serial.PARITY_NONE,
+       stopbits=serial.STOPBITS_ONE,
+       bytesize=serial.EIGHTBITS,
+       timeout=0.1
+)
+
+ser.open()
+ser.isOpen()
 
 def main():
 
@@ -12,7 +25,8 @@ def main():
     GPIO.setup(26,GPIO.IN, pull_up_down=GPIO.PUD_UP)
     pygame.mixer.init()
     pygame.mixer.music.load("/media/usb0/muzika.mp3")
-    odplayao = False
+    dobar = False
+    trenutni=1
     # setup pin 25 as an output
 
 #    GPIO.setup(24,GPIO.OUT)
@@ -28,21 +42,41 @@ def main():
                         #             GPIO.output(24,True)
                         #             GPIO.output(25,False)
              print "button false"
-             if odplayao == False:
-                               odplayao = True
-                               pygame.mixer.music.play()
-                               while pygame.mixer.music.get_busy() == True:
-                                       continue                         
+             if trenutni==2:
+                               dobar = False
+                               trenutni=1
+             while dobar!=True:
+                               print "poslao na matricu"                        
+#                              time.sleep(1)                           
+                               ON = "\x14\x82\x80\x81"
+                               ser.write(ON)
+#                              dobar=True
+#                              time.sleep(0.01)
+                               inp = ser.read(size=4)
+                               print inp.encode("hex")                         
+                               if inp.encode("hex") == "54828081":
+                                       dobar=True                              
+             pygame.mixer.music.play()
+             while pygame.mixer.music.get_busy() == True:
+                 continue                       
         else:
-                               odplayao = False                        
- #            print "button true"
-             # the button isn't being pressed, so turn off the green LED
-             # and turn on the red LED
- #            GPIO.output(24,False)
- #            GPIO.output(25,True)
- #            print "button false"
-
-        time.sleep(0.1)
+             print "button true"               
+             if trenutni==1:
+                               dobar = False
+                               trenutni=2
+             while dobar!=True:
+                               print "poslao na matricu"                        
+                               ON = "\x14\x81\x80\x81"
+                               time.sleep(1)
+                               ser.write(ON)
+#                              time.sleep(0.01)
+                               inp = ser.read(size=4)
+                               print inp.encode("hex")                         
+                               if inp.encode("hex") == "54818081":
+                                       dobar=True
+
+
+        time.sleep(0.2)
 
     print "button pushed"