tabs to spaces
[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              pygame.mixer.music.play()
60              while pygame.mixer.music.get_busy() == True:
61                  continue             
62         else:
63              print "button true"        
64              if trenutni==1:
65                 dobar = False
66                 trenutni=2
67              while dobar!=True:
68                 print "poslao na matricu"             
69                 ON = "\x14\x81\x80\x81"
70                 time.sleep(1)
71                 ser.write(ON)
72 #                time.sleep(0.01)
73                 inp = ser.read(size=4)
74                 print inp.encode("hex")                
75                 if inp.encode("hex") == "54818081":
76                     dobar=True
77
78
79         time.sleep(0.2)
80
81     print "button pushed"
82
83     GPIO.cleanup()
84
85
86
87 if __name__=="__main__":
88     main()