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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.ballx = o.width / 2
  28. self.bally = o.height / 2
  29. self.ball_speed = .5
  30. self.ball_x_dir = 1
  31. self.ball_y_dir = 1
  32. o.header_text = "Clock"
  33. o.pub.register("beat", self)
  34. if o.keyState[16] > 0 or o.keyState[17] > 0:
  35. pass
  36. else:
  37. pass
  38. super(Clock, self).Enter()
  39. def Execute(self):
  40. o = self.FSM.owner
  41. m.menu1_actions(self, o)
  42. if o.keyState[16] == 1:
  43. m.draw_menu1(o)
  44. o.update_display(0)
  45. if o.keyState[16] > 0 or o.keyState[17] > 0:
  46. pass
  47. else:
  48. current_time = time.strftime("%-I:%M:%S")
  49. s = int(time.strftime("%S"))
  50. if s % 2 == 0:
  51. current_time = time.strftime("%-I:%M.%S")
  52. if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex):
  53. self.ball_x_dir *= -1
  54. if (self.bally > o.height - self.ball_sizey - 20) or (self.bally < 0 + self.ball_sizey):
  55. self.ball_y_dir *= -1
  56. x1 = self.ballx - self.ball_sizex
  57. x2 = self.ballx + self.ball_sizex
  58. y1 = self.bally - self.ball_sizey
  59. y2 = self.bally + self.ball_sizey
  60. self.ballx += self.ball_speed * self.ball_x_dir
  61. self.bally += self.ball_speed * self.ball_y_dir
  62. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  63. o.center_block(current_time, o.h3, [x1, y1, x2, y2], o.light_grey)
  64. today = date.today()
  65. current_date = today.strftime('%A')
  66. current_date += ', ' + today.strftime("%b %d, %Y")
  67. o.center_block(current_date, o.h2, [x1, y1 + 35, x2, y2 + 35], o.light_grey)
  68. o.update_display(0)
  69. def ReceiveMessage(self, message):
  70. o = self.FSM.owner
  71. u.play_seq(o, message)
  72. def Exit(self):
  73. self.FSM.owner.pub.unregister("beat", self)