forked from topher200/led_taillight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
29 lines (21 loc) · 754 Bytes
/
controller.py
File metadata and controls
29 lines (21 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''Control for the taillight with LEDs in it
Usage:
import led_taillight.controller as taillight
taillight.set_leds(taillight.FAST_FLASH)
'''
import socket
TAILLIGHT_IP = '192.168.95.44'
TAILLIGHT_PORT = 50001
# LED numbers and Modes for parameters:
OFF, ON, SLOW_FLASH, NORMAL_FLASH, FAST_FLASH, PULSE = range(6)
def set_leds(mode):
'''Sets all LEDs to the given mode
mode: One of the mode constants provided by this file. Example: PULSE.
'''
message = '%s%s%s%s' % (mode, mode, mode, mode)
_send_message(message)
def _send_message(message):
client_socket = socket.socket()
client_socket.connect((TAILLIGHT_IP, TAILLIGHT_PORT))
client_socket.send(message.encode('utf-8'))
client_socket.close()