Advertisement
Guest User

Untitled

a guest
Nov 10th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import time
  2. import math
  3.  
  4. from bell.avr.mqtt.client import MQTTModule
  5. from bell.avr.mqtt.payloads import AvrPcmSetBaseColorPayload, AvrPcmSetServoAbsPayload, AvrAutonomousEnablePayload
  6. from loguru import logger
  7.  
  8. class Sandbox(MQTTModule):
  9. def __init__(self) -> None:
  10. super().__init__()
  11. logger.debug("Class initialized")
  12. self.enabled = False
  13. self.topic_map = {"avr/autonomous": self.on_autonomous_message}
  14. self.autonomous_code()
  15.  
  16. def on_autonomous_message(self, payload: AvrAutonomousEnablePayload) -> None:
  17. self.enabled = payload["enable"]
  18.  
  19. def autonomous_code(self) -> None:
  20. while True:
  21. if self.enabled:
  22. box.send_message("avr/pcm/set_base_color", {"wrgb": [100, 0, 255, 0]})
  23. print("Setting Color To White")
  24. time.sleep(1)
  25.  
  26. if __name__ == "__main__":
  27. box = Sandbox()
  28. box.run_non_blocking()
  29. box.send_message("avr/pcm/set_base_color", {"wrgb": [100, 255, 0, 0]})
  30. # placeholder = 0
  31. # intensity = 0.1
  32. # while True:
  33. # placeholder += 0.08
  34. # saturationW = (50 + (math.sin(placeholder) * 50)) * intensity
  35. # saturationR = (50 + (math.sin(placeholder + 1.57) * 50)) * intensity
  36. # saturationG = (50 + (math.sin(placeholder + 3.14) * 50)) * intensity
  37. # saturationB = (50 + (math.sin(placeholder + 4.71) * 50)) * intensity
  38. # box.send_message("avr/pcm/set_base_color", {"wrgb": [int(saturationW), int(saturationR), int(saturationG), int(saturationB)]})
  39. # #box.send_message("avr/pcm/set_servo_abs", {"servo": 3, "absolute": int(700 + saturationR * 7.5 * (1/intensity))})
  40. # logger.debug(saturationR)
  41. # time.sleep(0.0166)
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement