base gumb.py from other nodes
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 Jul 2023 09:22:37 +0000 (11:22 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 Jul 2023 09:22:37 +0000 (11:22 +0200)
1/gumb.py [new file with mode: 0755]

diff --git a/1/gumb.py b/1/gumb.py
new file mode 100755 (executable)
index 0000000..d7785cb
--- /dev/null
+++ b/1/gumb.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import time
+import RPi.GPIO as GPIO
+import pygame
+
+def main():
+
+    # tell the GPIO module that we want to use the 
+    # chip's pin numbering scheme
+    GPIO.setmode(GPIO.BCM)
+    GPIO.setup(26,GPIO.IN, pull_up_down=GPIO.PUD_UP)
+    pygame.mixer.init()
+    pygame.mixer.music.load("/media/usb0/muzika.mp3")
+    odplayao = False
+    # setup pin 25 as an output
+
+#    GPIO.setup(24,GPIO.OUT)
+#    GPIO.setup(25,GPIO.OUT)
+
+
+#    GPIO.output(25,True)
+
+    while True:
+        if GPIO.input(26):
+             # the button is being pressed, so turn on the green LED
+             # and turn off the red LED
+                        #             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                         
+        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 pushed"
+
+    GPIO.cleanup()
+
+
+
+if __name__=="__main__":
+    main()