raspberry pi zero based drum machine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sClock.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. from datetime import date
  5. import time
  6. #====================================
  7. State = type("State", (object,), {})
  8. #====================================
  9. class State(object):
  10. def __init__(self, FSM):
  11. self.FSM = FSM
  12. def Enter(self):
  13. pass
  14. def Execute(self):
  15. pass
  16. def Exit(self):
  17. pass
  18. class Clock(State):
  19. def __init__(self,FSM):
  20. super(Clock, self).__init__(FSM)
  21. def Enter(self):
  22. o = self.FSM.owner
  23. current_time = time.strftime("%-I:%M:%S")
  24. self.ball_sizex, self.ball_sizey = o.h3.getsize("18:88:88")
  25. self.ball_sizex /= 2
  26. self.ball_sizey /= 2
  27. #self.ball_sizey += 10
  28. self.ballx = o.width / 2
  29. self.bally = o.height / 2
  30. self.ball_speed = .5
  31. self.ball_x_dir = 1
  32. self.ball_y_dir = 1
  33. o.header_text = "Clock"
  34. o.pub.register("beat", self)
  35. if o.keyState[16] > 0 or o.keyState[17] > 0:
  36. pass
  37. else:
  38. pass
  39. super(Clock, self).Enter()
  40. def Execute(self):
  41. o = self.FSM.owner
  42. m.menu1_actions(self, o)
  43. if o.keyState[16] == 1:
  44. m.draw_menu1(o)
  45. o.update_display(0)
  46. if o.keyState[16] > 0 or o.keyState[17] > 0:
  47. pass
  48. else:
  49. current_time = time.strftime("%-I:%M:%S")
  50. s = int(time.strftime("%S"))
  51. if s % 2 == 0:
  52. current_time = time.strftime("%-I:%M.%S")
  53. if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex):
  54. self.ball_x_dir *= -1
  55. if (self.bally > o.height - self.ball_sizey - 20) or (self.bally < 0 + self.ball_sizey):
  56. self.ball_y_dir *= -1
  57. x1 = self.ballx - self.ball_sizex
  58. x2 = self.ballx + self.ball_sizex
  59. y1 = self.bally - self.ball_sizey
  60. y2 = self.bally + self.ball_sizey
  61. self.ballx += self.ball_speed * self.ball_x_dir
  62. self.bally += self.ball_speed * self.ball_y_dir
  63. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  64. #o.draw.rectangle((x1, y1, x2, y2), outline=0, fill=o.dark_grey)
  65. #o.draw.text((self.ballx - self.ball_sizex, self.bally - self.ball_sizey), current_time, align='center', font=o.h3, fill=o.light_grey)
  66. o.center_block(current_time, o.h3, [x1, y1, x2, y2], o.light_grey)
  67. today = date.today()
  68. current_date = today.strftime('%A')
  69. current_date += ', ' + today.strftime("%b %d, %Y")
  70. #o.draw.text((self.ballx - self.ball_sizex, (self.bally + 45) - self.ball_sizey), current_date, align='center', font=o.h2, fill=o.light_grey)
  71. o.center_block(current_date, o.h2, [x1, y1 + 35, x2, y2 + 35], o.light_grey)
  72. o.update_display(0)
  73. def ReceiveMessage(self, message):
  74. o = self.FSM.owner
  75. u.play_seq(o, message)
  76. def Exit(self):
  77. self.FSM.owner.pub.unregister("beat", self)