2424wiringpi .pinMode (PIN_BUTTON , wiringpi .GPIO .INPUT )
2525
2626# The length of a beat in seconds
27- a_beat = .15
27+ A_BEAT = .15
2828
29- delay_between_letters = 8 * a_beat
29+ DELAY_BETWEEN_LETTERS = 8 * A_BEAT
3030
3131
3232class PiBorgLight (Light ):
33+ """ Controls the illumination of PiBorg LED """
3334
3435 # Set the colour channel intensity (1 is fully on, 0 is off)
3536 red = 1
3637 green = 1
3738 blue = 1
3839
40+
3941 def on (self ):
40- # Turn the LedBorg on
42+ """ Turn the LedBorg on """
4143 wiringpi .digitalWrite (PIN_RED , self .red )
4244 wiringpi .digitalWrite (PIN_GREEN , self .green )
4345 wiringpi .digitalWrite (PIN_BLUE , self .blue )
4446
4547
4648 def off (self ):
47- # Turn the LedBorg off
49+ """ Turn the LedBorg off """
4850 wiringpi .digitalWrite (PIN_RED , 0 )
4951 wiringpi .digitalWrite (PIN_GREEN , 0 )
5052 wiringpi .digitalWrite (PIN_BLUE , 0 )
5153
5254
5355light = PiBorgLight ()
54- code_flasher = MorseCodeFlasher (a_beat , delay_between_letters , light )
56+ code_flasher = MorseCodeFlasher (A_BEAT , DELAY_BETWEEN_LETTERS , light )
5557
5658
5759def record_push ():
58- url = 'http://morse.pelmo.uk/ping/index.php'
60+ """ Makes a HTTP Request to record the event of a button push """
61+ url = 'http://morse.pelmo.uk/ping/index.php'
5962 headers = {
60- 'Content-Type' : 'multipart/form-data' ,
63+ 'Content-Type' : 'multipart/form-data' ,
6164 'User-Agent' : 'Morse code RaspberryPi'
6265 }
6366 try :
@@ -66,9 +69,10 @@ def record_push():
6669 data = { 'ping' : 1 },
6770 timeout = 3
6871 )
69- print ('Response code: ' + str (response .status_code ))
70- except :
71- print ('Post failed' )
72+ print ('Response code: ' + str (response .status_code ))
73+ except requests .exceptions .HTTPError as errh :
74+ print ("HTTP Error" )
75+ print (errh .args [0 ])
7276
7377
7478code_flasher .flash_code ('-.-' )
@@ -78,6 +82,6 @@ def record_push():
7882while True : # Run forever
7983 if wiringpi .digitalRead (PIN_BUTTON ):
8084 print ("Button was pushed!" )
81- time .sleep (2 * a_beat )
85+ time .sleep (2 * A_BEAT )
8286 send_todays_word (code_flasher )
8387 # record_push()
0 commit comments