Skip to content

Commit 9a1fe0c

Browse files
committed
Del warnings on python codes
1 parent 534b649 commit 9a1fe0c

File tree

3 files changed

+207
-209
lines changed

3 files changed

+207
-209
lines changed

buzzerPi.py

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@
1919
########################################
2020

2121
#Disable warnings (optional)
22-
GPIO.setwarnings(False);
22+
GPIO.setwarnings(False)
2323

2424
#Select GPIO mode
25-
GPIO.setmode(GPIO.BCM);
25+
GPIO.setmode(GPIO.BCM)
2626

2727
#Set BUZZER - pin 23 as output (as many as notes)
28-
BUZZER =23;
29-
GPIO.setup(BUZZER,GPIO.OUT);
28+
BUZZER =23
29+
GPIO.setup(BUZZER,GPIO.OUT)
3030
#end Initialize buzzer.
3131

3232
########################################
3333
# Global variables #
3434
########################################
3535

3636
# Song to be played.
37-
song = [];
37+
song = []
3838
#end Global variables.
3939

4040
########################################
4141
# Music notes available #
4242
########################################
4343

4444
# Frecuency of each note.
45-
do = 261.63;
46-
re = 293.66;
47-
mi = 329.63;
48-
fa = 349.23;
49-
sol = 392.00;
50-
la = 440.00;
51-
si = 493.88;
52-
do2 = 523.25;
45+
do = 261.63
46+
re = 293.66
47+
mi = 329.63
48+
fa = 349.23
49+
sol = 392.00
50+
la = 440.00
51+
si = 493.88
52+
do2 = 523.25
5353

5454
# Each note with each frecuency.
5555
music_notes = {
@@ -61,25 +61,25 @@
6161
"la":la,
6262
"si":si,
6363
"do2":do2
64-
};
64+
}
6565

6666
########################################
6767
# Tempo notes defines #
6868
########################################
6969

7070
# Values of each type of note.
7171
dobleredonda = 3.2
72-
redonda = 1.6;
73-
blancaplus = 1.2;
74-
blancasemi = 1;
75-
blanca = 0.8;
76-
negraplus = 0.6;
77-
negrasemi = 0.5;
78-
negra = 0.4;
79-
corchea = 0.2;
80-
semicorchea = 0.1;
81-
ssemicorchea = 0.05;
82-
sssemicorchea = 0.025;
72+
redonda = 1.6
73+
blancaplus = 1.2
74+
blancasemi = 1
75+
blanca = 0.8
76+
negraplus = 0.6
77+
negrasemi = 0.5
78+
negra = 0.4
79+
corchea = 0.2
80+
semicorchea = 0.1
81+
ssemicorchea = 0.05
82+
sssemicorchea = 0.025
8383

8484
# Each tempo with each value.
8585
tempo_notes = {
@@ -95,70 +95,70 @@
9595
"sc":semicorchea,
9696
"ssc":ssemicorchea,
9797
"sssc":sssemicorchea
98-
};
98+
}
9999
#end Note tempo defines.
100100

101101
########################################
102102
# usage function #
103103
########################################
104104
def usage(program_name):
105-
print("Usage:\n\tpython3 "+program_name+" partitures/partiture.txt\nor:\n\t./"+program_name+" partitures/partiture.txt");
105+
print("Usage:\n\tpython3 "+program_name+" partitures/partiture.txt\nor:\n\t./"+program_name+" partitures/partiture.txt")
106106
#end usage function.
107107

108108
########################################
109109
# play_note function #
110110
########################################
111111
def play_note(the_note):
112-
halveWaveTime = 1 / (the_note[0] * 2 );
113-
waves = int(the_note[1] * the_note[0]);
112+
halveWaveTime = 1 / (the_note[0] * 2 )
113+
waves = int(the_note[1] * the_note[0])
114114
for i in range(waves):
115-
GPIO.output(BUZZER, True);
116-
time.sleep(halveWaveTime);
117-
GPIO.output(BUZZER, False);
118-
time.sleep(halveWaveTime);
119-
time.sleep(the_note[1] *0.1);
115+
GPIO.output(BUZZER, True)
116+
time.sleep(halveWaveTime)
117+
GPIO.output(BUZZER, False)
118+
time.sleep(halveWaveTime)
119+
time.sleep(the_note[1] *0.1)
120120
#end play_note function.
121121

122122
########################################
123123
# get_partitures function #
124124
########################################
125125
def get_partiture(partiture):
126126
try:
127-
song_file = open(partiture,"r");
127+
song_file = open(partiture,"r")
128128
except:
129-
print("No partiture called partitures/"+str(partiture)+" found.");
130-
sys.exit(1);
131-
song_content = song_file.read().split("\n");
129+
print("No partiture called partitures/"+str(partiture)+" found.")
130+
sys.exit(1)
131+
song_content = song_file.read().split("\n")
132132
for note in song_content:
133133
try:
134-
values = note.split(",");
135-
tupla = (music_notes[values[0]],tempo_notes[values[1]]);
136-
song.append(tupla);
134+
values = note.split(",")
135+
tupla = (music_notes[values[0]],tempo_notes[values[1]])
136+
song.append(tupla)
137137
except:
138-
continue;
138+
continue
139139
#end get_partitures function.
140140

141141
#########################################
142142
# Read arguments and get partitures #
143143
#########################################
144144

145145
# Get program name.
146-
program_name = sys.argv[0].replace("./","");
146+
program_name = sys.argv[0].replace("./","")
147147

148148
# Get number of arguments.
149-
num_args = len(sys.argv);
149+
num_args = len(sys.argv)
150150

151151
# Exit program if no partiture are selected.
152152
if num_args <= 1:
153-
print("No partiture selected");
154-
usage(program_name);
155-
sys.exit(1);
153+
print("No partiture selected")
154+
usage(program_name)
155+
sys.exit(1)
156156

157157
# Get partiture name.
158-
partiture = sys.argv[1];
158+
partiture = sys.argv[1]
159159

160160
# Get the partiture.
161-
get_partiture(partiture);
161+
get_partiture(partiture)
162162
#end Read arguments and get partitures.
163163

164164
#########################################
@@ -167,14 +167,12 @@ def get_partiture(partiture):
167167
print('Playing piano, press Ctrl-C to quit...')
168168
try:
169169
while True:
170-
reset();
171170
for note in song:
172-
play_note(note);
173-
print("The song has ended, playing again...");
171+
play_note(note)
172+
print("The song has ended, playing again...")
174173
except KeyboardInterrupt:
175-
reset();
176-
print("Turning off the piano.");
177-
sys.exit(1);
174+
print("Turning off the piano.")
175+
sys.exit(1)
178176
#end Play Song.
179177

180178
#end Program.

0 commit comments

Comments
 (0)