forked from nonolith/pixelpulse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsine.py
48 lines (40 loc) · 1.24 KB
/
sine.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python2
# Example driver for Pixelpulse
# Distributed under the terms of the BSD License
# (C) 2011 Kevin Mehall (Nonolith Labs) <[email protected]>
import math, time
import pixelpulse
import webbrowser
class SineDevice(pixelpulse.Device):
def __init__(self):
# Define the channels
self.cos = pixelpulse.AnalogChannel(
name='Cosine',
unit='V',
min=-1.0,
max=1.0,
# Graph is initially shown. If False, the channel will be on the bottom bar
showGraph=True,
)
self.sin = pixelpulse.AnalogChannel(
name='Sine',
unit='A',
min=-1.0,
max=1.0,
showGraph=True,
)
# pixelpulse reads this property to determine which channels to show
self.channels = [self.sin, self.cos]
def start(self, server):
""" This method is called by Pixelpulse once the server is started """
server.poll(self.update) # ask the server to poll our update() method at its default sample rate
def update(self):
""" Polled to update the data as configured in start(). Returns a list of (channel. value) pairs """
return [
(self.cos, math.cos(time.time())),
(self.sin, math.sin(time.time())),
]
if __name__ == '__main__':
dev = SineDevice()
server = pixelpulse.DataServer(dev)
server.start(openWebBrowser=True)