comment out button pressed state output (normal)
[veternica] / 1 / gumb.py
1 #!/usr/bin/env python
2
3 import time
4 import RPi.GPIO as GPIO
5 import pygame
6 #import os
7 import serial
8 ser = serial.Serial(
9     port='/dev/ttyAMA0',
10     baudrate=9600,
11     parity=serial.PARITY_NONE,
12     stopbits=serial.STOPBITS_ONE,
13     bytesize=serial.EIGHTBITS,
14     timeout=0.1
15 )
16
17 ser.open()
18 ser.isOpen()
19
20 def main():
21
22     # tell the GPIO module that we want to use the 
23     # chip's pin numbering scheme
24     GPIO.setmode(GPIO.BCM)
25     GPIO.setup(26,GPIO.IN, pull_up_down=GPIO.PUD_UP)
26     pygame.mixer.init()
27     pygame.mixer.music.load("/media/usb0/muzika.mp3")
28     dobar = False
29     trenutni=1
30     # setup pin 25 as an output
31
32 #    GPIO.setup(24,GPIO.OUT)
33 #    GPIO.setup(25,GPIO.OUT)
34
35
36 #    GPIO.output(25,True)
37
38     while True:
39         if GPIO.input(26):
40              # the button is being pressed, so turn on the green LED
41              # and turn off the red LED
42              #             GPIO.output(24,True)
43              #             GPIO.output(25,False)
44              print "button false"
45              if trenutni==2:
46                 dobar = False
47                 trenutni=1
48              while dobar!=True:
49                 print "poslao na matricu"             
50 #                time.sleep(1)                
51                 ON = "\x14\x82\x80\x81"
52                 ser.write(ON)
53 #                dobar=True
54 #                time.sleep(0.01)
55                 inp = ser.read(size=4)
56                 print inp.encode("hex")                
57                 if inp.encode("hex") == "54828081":
58                     dobar=True                
59
60              print("play", "dobar=", dobar, "trenutni=",trenutni)
61              pygame.mixer.music.play()
62              while pygame.mixer.music.get_busy() == True:
63                  continue             
64         else:
65              #print "button true"
66              if trenutni==1:
67                 dobar = False
68                 trenutni=2
69              while dobar!=True:
70                 print "poslao na matricu"             
71                 ON = "\x14\x81\x80\x81"
72                 time.sleep(1)
73                 ser.write(ON)
74 #                time.sleep(0.01)
75                 inp = ser.read(size=4)
76                 print inp.encode("hex")                
77                 if inp.encode("hex") == "54818081":
78                     dobar=True
79
80
81         time.sleep(0.2)
82
83     print "button pushed"
84
85     GPIO.cleanup()
86
87
88
89 if __name__=="__main__":
90     main()