Example #1
0
 def __init__(self,
              green_leds=[6, 13, 19, 26],
              red_leds=[12, 16, 20, 21],
              indicator=22):
     # Init leds
     # self.green_leds = LEDBarGraph(6, 13, 19, 26, pwm=True)
     self.green_leds = LEDBarGraph(*green_leds, pwm=True)
     # self.red_leds = LEDBarGraph(12, 16, 20, 21, pwm=True)
     self.red_leds = LEDBarGraph(*red_leds, pwm=True)
     self.indicator = PWMLED(indicator)
     self.vote_getter = VoteGetter()
     self.curr_votes = Votes(100, 1)
     self.leds_from_votes(self.curr_votes)
Example #2
0
    def __init__(self, wavefile, Low_sound, High_sound):

        self.wavefile = wavefile
        #LEDの設定
        #self.graph = LEDBarGraph(21,20,16,5,6,13,19,26,pwm=True)
        self.graph = LEDBarGraph(26,19,13,6,5,16,20,21,pwm=True)
        #SOUNDの設定
        self.chunk = 2048
        self.Low_sound_level= Low_sound
        self.High_sound_level= High_sound
        self.out = alsa.PCM(alsa.PCM_PLAYBACK, alsa.PCM_NORMAL,'hw:1,0')
        self.out.setrate(44100)
        self.out.setformat(alsa.PCM_FORMAT_S16_LE)
        self.out.setchannels(2)
        self.out.setperiodsize(320)
        self.stream = wave.open(self.wavefile,"r")
Example #3
0
    def monitorTreeWtr(self):
        self.log("Tree water level monitor running...")
        self.wtrLevel = LEDBarGraph(self.GPIO_led_R1,
                                    self.GPIO_led_Y1,
                                    self.GPIO_led_G1,
                                    pwm=True)
        level = 0
        lastLevel = -1

        while True:
            # This is terrible, horrible, very bad code!
            if self.treeWtrLevel13.value:
                level = 13
            elif self.treeWtrLevel12.value:
                level = 12
            elif self.treeWtrLevel11.value:
                level = 11
            elif self.treeWtrLevel10.value:
                level = 10
            elif self.treeWtrLevel09.value:
                level = 9
            elif self.treeWtrLevel08.value:
                level = 8
            elif self.treeWtrLevel07.value:
                level = 7
            elif self.treeWtrLevel06.value:
                level = 6
            elif self.treeWtrLevel05.value:
                level = 5
            elif self.treeWtrLevel04.value:
                level = 4
            elif self.treeWtrLevel03.value:
                level = 3
            elif self.treeWtrLevel02.value:
                level = 2
            elif self.treeWtrLevel01.value:
                level = 1
            else:
                level = 0

            if lastLevel != level:
                self.log("Tree water level now at level " + str(level), "INFO")
                lastLevel = level

            level = level / 13
            self.wtrLevel.value = level
            sleep(1)
Example #4
0
def parent():
    tree = treeWater()

    # We should spawn these children in a better manner with IPC
    manualRun = os.fork()
    if manualRun == 0:
        tree.manualRun()
        os._exit()

    monitorWtrPump = os.fork()
    if monitorWtrPump == 0:
        tree.monitorWtrPump()
        os._exit()

    monitorTreeWtr = os.fork()
    if monitorTreeWtr == 0:
        tree.monitorTreeWtr()
        os._exit()

#        autoFill = os.fork()
#        if autoFill == 0:
#                tree.autoFill()
#                os._exit()

    print("Waiting for children to start...")
    sleep(5)

    while True:
        sleep(1)
        # This works great for command line, but kills it when it's daemonized


#                reply = input("\nq for quit\n")
#                if reply == 'q':
#                        break

    os.kill(manualRun, signal.SIGKILL)
    os.kill(monitorWtrPump, signal.SIGKILL)
    os.kill(monitorTreeWtr, signal.SIGKILL)
    #        os.kill(autoFill, signal.SIGKILL)
    tree.Shutdown()
    wtrLevel = LEDBarGraph(tree.GPIO_led_R1,
                           tree.GPIO_led_Y1,
                           tree.GPIO_led_G1,
                           pwm=True)
    wtrLevel = 0.0
Example #5
0
#!/usr/bin/python3

from gpiozero import LEDBarGraph, CPUTemperature
from signal import pause

cpu = CPUTemperature(min_temp=40, max_temp=90)
leds = LEDBarGraph(4, 17, 22, 5, 6, 13, 19, 26,  pwm=True)

leds.source = cpu

pause()
Example #6
0
from gpiozero import MCP3008, LEDBarGraph
from time import sleep

def convert_temp(gen):
    for value in gen:
        yield (value * 3.3 - 0.5) * 100

adc = MCP3008(channel=7)
graph = LEDBarGraph (26, 19, 13, 6, 5, pwm=True)

for temp in convert_temp(adc.values):
    bars = temp / 35
    graph.value = bars
    sleep(1)


Example #7
0
from __future__ import division
from gpiozero import LEDBarGraph, CPUTemperature
from signal import pause

cpu = CPUTemperature(min_temp=50, max_temp=90)
leds = LEDBarGraph(17, 4, pwm=True)

leds.source = cpu

pause()
from gpiozero import LEDBarGraph
from time import sleep
import requests


# Connect 30mA LEDs with 47 ohm resistors
# Connect anodes to all of the GPIOs listed below
leds = LEDBarGraph(17, 18, 27, 22, 23, 24, 10, 25, 9, 11)
url = "http://api.open-notify.org/astros.json"

while True:
    r = requests.get(url)
    data = r.json()
    people = data['number']
    print(people)
    leds.value = people/10
    sleep(1)


Example #9
0
from gpiozero import LEDBarGraph, LoadAverage
import random
from time import sleep
from signal import pause

bar = LEDBarGraph(26, 19, 13, 6, 5, pwm=True)
la = LoadAverage(minutes=1, max_load_average=5)

bar.source = la

pause()
Example #10
0
from gpiozero import LEDBarGraph, MCP3008
from signal import pause

graph = LEDBarGraph(5, 6, 13, 19, 26, pwm=True)
pot = MCP3008(channel=0)

graph.source = pot

pause()
Example #11
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(17, 27, 22, 5, 6, pwm=True)
while (True):
    graph.value = 0
    sleep(.1)
    graph.value = 2 / 10  # (0.5, 0, 0, 0, 0)
    sleep(.1)
    graph.value = 4 / 10  # (1, 0.5, 0, 0, 0)
    sleep(.1)
    graph.value = 6 / 10  # (0, 0, 0, 0.5, 1)
    sleep(.1)
    graph.value = 8 / 10  # (1, 1, 1, 1, 0.5)
    sleep(.1)
    graph.value = 1  # (1, 1, 1, 1, 0.75)
    sleep(.1)
Example #12
0
from gpiozero import LEDBarGraph
from time import sleep
from __future__ import division  # required for python 2

graph = LEDBarGraph(5, 6, 13, 19, 26, pwm=True)

graph.value = 1/10  # (0.5, 0, 0, 0, 0)
sleep(1)
graph.value = 3/10  # (1, 0.5, 0, 0, 0)
sleep(1)
graph.value = -3/10  # (0, 0, 0, 0.5, 1)
sleep(1)
graph.value = 9/10  # (1, 1, 1, 1, 0.5)
sleep(1)
graph.value = 95/100  # (1, 1, 1, 1, 0.75)
sleep(1)
from gpiozero import LEDBarGraph, CPUTemperature
from signal import pause

cpu = CPUTemperature(min_temp=50, max_temp=90)
leds = LEDBarGraph(2, 3, 4, 5, 6, 7, 8, pwm=True)

leds.source = cpu.values

pause()
Example #14
0
from gpiozero import LEDBoard, LEDBarGraph
from datetime import datetime
from threading import Thread
from time import sleep

coms = LEDBoard(14, 15, 18, 2)
segs = LEDBoard(16, 21, 19, 6, 5, 20, 26, 13)
bargraph = LEDBarGraph(3, 4, 17, 27, 22, 10, 9, 11, 7, 12)
chars_map = {
    ' ': '00000000',
    '0': '11111100',
    '1': '01100000',
    '2': '11011010',
    '3': '11110010',
    '4': '01100110',
    '5': '10110110',
    '6': '10111110',
    '7': '11100000',
    '8': '11111110',
    '9': '11110110',
    'A': '11101110',
    'B': '11111110',
    'C': '10011100',
    'D': '11111100',
    'E': '10011110',
    'F': '10001110',
    'G': '10111100',
    'H': '01101110',
    'I': '01100000',
    'J': '01111000',
    'K': '01101110',
Example #15
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(5, 6, 13, 19, 26, 20)
''' in LEDBarGraph, we can give values like 1/2 and half the LEDs glow.
That is not possible in LED board. In LED Board, we need to give individual values'''

while True:
    graph.value = 1  #(1,1,1,1,1,1)
    sleep(1)
    graph.value = 1 / 2  #(1,1,1,0,0,0)
    sleep(1)
    graph.value = -1 / 2  #(0,0,0,1,1,1)
    sleep(1)
    graph.value = 1 / 4  #(1,0,0,0,0,0)
    sleep(1)
    graph.value = -1 / 4  #(0,0,0,0,0,1)
    sleep(1)
    graph.value = -1  #(1,1,1,1,1,1)
    sleep(1)
    graph.value = 0  #(0,0,0,0,0,0,0)
    sleep(1)
Example #16
0
#!/usr/bin/python3

from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(4, 17, 22, 5, 13, 26)

graph.value = 1
sleep(1)
graph.value = 1 / 2
sleep(1)
graph.value = -1 / 2
sleep(1)
graph.value = 1 / 4
sleep(1)
graph.value = -1
sleep(1)
Example #17
0
from gpiozero import LEDBarGraph, MCP3008
from signal import pause

graph = LEDBarGraph(5, 6, 13, 19, 26, pwm=True)
pot = MCP3008(channel=0)
graph.source = pot.values
pause()
Example #18
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(10, 17, 27, 22, 18, pwm=True)

graph.value = 1 / 10  # (0.5, 0, 0, 0, 0)
sleep(1)
graph.value = 3 / 10  # (1, 0.5, 0, 0, 0)
sleep(1)
graph.value = -3 / 10  # (0, 0, 0, 0.5, 1)
sleep(1)
graph.value = 9 / 10  # (1, 1, 1, 1, 0.5)
sleep(1)
graph.value = 95 / 100  # (1, 1, 1, 1, 0.75)
sleep(1)
    def _handler(self, message):
        # Signal new message
        self._beep()

        if isinstance(message, dict) and self.verbose:
            print(message.get('event', 'error'))

        if isinstance(message, list):
            code, info = message
            if isinstance(info, list):
                last_price = info[6]
                self._update_graph(last_price)
                if self.verbose:
                    print('Last price: {}, last points: {}'.format(
                        last_price, self.last_points))

    def start(self, verbose=True):
        """
		verbose - if set to True then channel information is printed out
		"""
        self.verbose = verbose
        client = WssClient()
        client.subscribe_to_ticker(symbol=self.pair, callback=self._handler)
        client.start()


graph = LEDBarGraph(25, 24, 23, 21, 16, 12, pin_factory=factory)
obsrv = CoinObserver('BTCUSD', graph)

obsrv.start()
from gpiozero import DiskUsage, LEDBarGraph
from signal import pause

disk = DiskUsage()
graph = LEDBarGraph(2, 3, 4, 5, 6, 7, 8)

graph.source = disk

pause()
Example #21
0
# SolarEdge inverter identifier/API key

SE_SITE = 'nnnnnn'
SE_AKEY = 'ALPHANUMERIC0123456789ABCEDFGHIJ'

SE_SITE = os.environ.get('SE_SITE')
# SE_AKEY = os.environ['SE_AKEY']
SE_AKEY = os.environ.get('SE_AKEY')

if SE_SITE == None or SE_AKEY == None:
    print('Set SE_SITE and SE_AKEY variables')
    sys.exit()

# array/tuple pin layout
graph = LEDBarGraph(26, 19, 13, 6, 5, 7, 8, 11, 25, 10, pwm=True)

#@retry(wait=wait_combine(wait_fixed(10), wait_jitter(30)),
# stop=stop_after_attempt(5))
r = requests.session()

# URL to SolarEdge API
u = 'https://monitoringapi.solaredge.com/site/' + SE_SITE
u += '/currentPowerFlow?api_key=' + SE_AKEY

while 1:
    try:
        j = r.get(u, timeout=10)
        while 'STORAGE' not in j.text:
            print(j.text)
            print('no data')
Example #22
0
#!/usr/bin/python3

from gpiozero import LEDBarGraph, CPUTemperature
from time import sleep
from signal import pause

#graph = LEDBarGraph(4, 17, 22, 10)
cpu = CPUTemperature(min_temp=50, max_temp=80)
leds = LEDBarGraph(4, 17, 22, 10, pwm=True)

leds.source = cpu

pause()

#graph.value = 1
#sleep(1)
#graph.value = 1/2
#sleep(1)
#graph.value = -1/2
#sleep(1)
#graph.value = 1/4
#sleep(1)
#graph.value = -1
#sleep(1)
Example #23
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(18, 23, 24, pwm=True)

graph.value = 1 / 10  # (0.5, 0, 0)
sleep(1)
graph.value = 3 / 10  # (1, 0.5, 0)
sleep(1)
# 음수 뒤에서 해석
graph.value = -3 / 10  # (0, 0, 0)
sleep(1)
graph.value = 9 / 10  # (1, 1, 1)
sleep(1)
graph.value = 95 / 100  # (1, 1, 1)
sleep(1)
Example #24
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(10, 17, 27, 22, 18, 23)

while True:
    graph.value = 1  # (1, 1, 1, 1, 1, 1)
    sleep(1)
    graph.value = 1 / 2  # (1, 1, 1, 0, 0, 0)
    sleep(1)
    graph.value = -1 / 2  # (0, 0, 0, 1, 1, 1)
    sleep(1)
    graph.value = 1 / 4  # (1, 0, 0, 0, 0, 0)
    sleep(1)
    graph.value = -1  # (1, 1, 1, 1, 1, 1)
    sleep(1)
Example #25
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(26, 19, 13, 6, 5, pwm=True)

graph.value = 1 / 10
sleep(1)
graph.value = 3 / 10
sleep(1)
graph.value = -3 / 10
sleep(1)
graph.value = 9 / 10
sleep(1)
graph.value = 95 / 100
sleep(1)
graph.value = 0
Example #26
0
from gpiozero import LEDBarGraph
from time import sleep

graph = LEDBarGraph(16, 20, 21, 25, 24, pwm=True)

graph.value = 1 / 10
sleep(1)
graph.value = 3 / 10
sleep(1)
graph.value = -3 / 10
sleep(1)
graph.value = 9 / 10
sleep(1)
graph.value = 95 / 100
sleep(1)
Example #27
0
from gpiozero import LEDBarGraph
from time import sleep
from __future__ import division  # required for python 2

graph = LEDBarGraph(5, 6, 13, 19, 26, pwm=True)

graph.value = 1 / 10  # (0.5, 0, 0, 0, 0)
sleep(1)
graph.value = 3 / 10  # (1, 0.5, 0, 0, 0)
sleep(1)
graph.value = -3 / 10  # (0, 0, 0, 0.5, 1)
sleep(1)
graph.value = 9 / 10  # (1, 1, 1, 1, 0.5)
sleep(1)
graph.value = 95 / 100  # (1, 1, 1, 1, 0.75)
sleep(1)
Example #28
0
from gpiozero import LEDBarGraph, LoadAverage
from signal import pause

la = LoadAverage(min_load_average=0, max_load_average=2)
graph = LEDBarGraph(4, 17, 27, 22, pwm=True)

graph.source = la

pause()
Example #29
0
# This import needs to be first
from __future__ import division  # required for python 2 import
from gpiozero import LEDBarGraph
from time import sleep

# Create a graph object
graph = LEDBarGraph(5, 6, 13, 19, 26, 21)
# graph = LEDBarGraph(5, 6, 13, 19, 26, 21, pwm=True)
# Allows for more precise values for LED's
graph.value = 1  # (1, 1, 1, 1, 1, 1) all are ones or on
sleep(1)
graph.value = 1 / 2  # (1, 1, 1, 0, 0, 0)
sleep(1)
graph.value = -1 / 2  # ( 0, 0, 0, 1, 1, 1)
sleep(1)
graph.value = 1 / 4  # (1, 0, 0, 0, 0, 0)
sleep(1)
graph.value = -1  # (1, 1, 1, 1, 1, 1) all are ones or LEDs are on
Example #30
0
#!/usr/bin/python3

#import gpiozero
from gpiozero import LEDBarGraph, LED, Button
from time import sleep

GPIO_led_R = 14
GPIO_led_Y = 15
GPIO_led_G = 4
GPIO_led_B = 17
GPIO_btn_B = 18

graph = LEDBarGraph(GPIO_led_R, GPIO_led_Y, GPIO_led_G, pwm=True)

mtrSts = LED(GPIO_led_B)

mtrSts.on()

graph.value = 0
print("Graph off.  Waiting 5 seconds...")
sleep(5)
print("Graphing")

for i in range(0, 100, 5):
    graph.value = i / 100
    print("i=", i)
    mtrSts.toggle()
    sleep(1)
Example #31
0
def send_sms(dest, body):
    timestamp = datetime.datetime.now()
    requests.post("https://api.twilio.com/2010-04-01/Accounts/" +
                  os.environ['TWILIO_ACCT'] + "/Messages.json",
                  auth=HTTPBasicAuth(os.environ['TWILIO_USER'],
                                     os.environ['TWILIO_PASS']),
                  data={
                      'To': dest,
                      'From': os.environ['TWILIO_NUM'],
                      'Body': "[" + str(timestamp) + "] " + body
                  })
    print("[" + str(timestamp) + "] sent \"" + body + "\" to " + dest)


did = DigitalInputDevice(18)
graph = LEDBarGraph(27, 26, 25, 24, 23, pwm=True)

off_threshold = 0.75
on_threshold = 0.95

old = 1
nv = 1
st = 1
tau = 10.0
delta = 0.0

print("Startup: [" + str(datetime.datetime.now()) + "] UTC")

while True:

    val = did.value
Example #32
0
class VotesToLeds:
    def __init__(self,
                 green_leds=[6, 13, 19, 26],
                 red_leds=[12, 16, 20, 21],
                 indicator=22):
        # Init leds
        # self.green_leds = LEDBarGraph(6, 13, 19, 26, pwm=True)
        self.green_leds = LEDBarGraph(*green_leds, pwm=True)
        # self.red_leds = LEDBarGraph(12, 16, 20, 21, pwm=True)
        self.red_leds = LEDBarGraph(*red_leds, pwm=True)
        self.indicator = PWMLED(indicator)
        self.vote_getter = VoteGetter()
        self.curr_votes = Votes(100, 1)
        self.leds_from_votes(self.curr_votes)

    def leds_from_votes(self, votes: Votes):

        self._leds_from_ratio(*self._get_vote_ratios(votes))

    def _get_vote_ratios(self, votes: Votes):
        total_votes = sum(votes)
        green_ratio = votes.green / total_votes
        red_ratio = 1 - green_ratio

        return green_ratio, red_ratio

    def _leds_from_ratio(self, green_ratio, red_ratio):

        # Set leds
        self.green_leds.value = green_ratio
        self.red_leds.value = red_ratio

    def fade_to_poll(self, new_votes: Votes):

        print(f'Fading from poll {self.curr_votes} to poll {new_votes}...')

        fade_states = 50
        old_green_r, old_red_r = self._get_vote_ratios(self.curr_votes)
        green_r, red_r = self._get_vote_ratios(new_votes)

        def ratio_set_gen(old, new):
            return numpy.linspace(old, new, fade_states).tolist()
            # return [e for e in range(old, new,
            #                          abs(old - new) / fade_states)]

        ratio_set = list(
            zip(ratio_set_gen(old_green_r, green_r),
                ratio_set_gen(old_red_r, red_r)))
        print(f'Got {len(ratio_set)} vote ratios({ratio_set[1:2]}...)')

        # votes_set = []
        # for a in range(1, fade_states + 1):
        #     # print(self.curr_votes.green +((temp_curr_votes - temp_new_votes)*(a/fade_states)))
        #     votegen = lambda temp_new_votes, temp_curr_votes: temp_curr_votes + (
        #             (temp_new_votes - temp_curr_votes) * (a / fade_states))
        #     #
        #     votes_set.append(
        #         Votes(
        #             votegen(new_votes.green, self.curr_votes.green),
        #             votegen(new_votes.red, self.curr_votes.red))
        #     )

        # print(votes_set)
        async def hi_man():
            while True:
                print("hiIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIii")
                await asyncio.sleep(2)

        def hi_man_sync():
            # while True:
            # print("hiIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIii")
            # sleep(1)
            # print("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP")
            self.indicator.pulse(0.8, 0.8, 1, False)

        def hi_man_sync_two():
            print("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP")
            self.indicator.pulse()
            # pause()

        async def trans_lights(votes_set):
            for transition_votes in votes_set:
                self.leds_from_votes(transition_votes)

                await asyncio.sleep(0.1)

        def trans_lights_sync(votes_set):
            for transition_votes in votes_set:
                self.leds_from_votes(transition_votes)
                sleep(0.1)

        def trans_lights_ratio(ratios_set):
            for trans_ratios in ratios_set:
                self._leds_from_ratio(*trans_ratios)
                sleep(0.1)

        pool = futures.ThreadPoolExecutor()

        # fade_future = pool.submit(trans_lights_sync, votes_set)
        # hi_future = pool.submit(hi_man_sync_two)
        # futures.wait([fade_future, hi_future], return_when=futures.FIRST_COMPLETED)
        # pool.shutdown(wait=False, cancel_futures=True)

        # This works
        # fade_future = pool.submit(trans_lights_sync, votes_set)
        fade_future = pool.submit(trans_lights_ratio, ratio_set)
        # print(fade_future.running())
        while fade_future.running():
            hi_man_sync()

        # Optimal, but hi_man's while loop is not cancellable.
        # futures.wait([fade_future], return_when=futures.FIRST_COMPLETED)
        # hi_future = pool.submit(hi_man_sync)
        # futures.wait([fade_future, hi_future], return_when=futures.FIRST_COMPLETED)
        # pool.shutdown(wait=False)
        ##

        # fade_future = pool.submit(asyncio.run, trans_lights(votes_set))
        # hi_future = pool.submit(asyncio.run, hi_man())
        #
        # # while fade_future.running():
        # #     hi_man_sync()
        #
        # # pool.shutdown(wait=True)
        # futures.wait([fade_future, hi_future], return_when=futures.FIRST_COMPLETED)
        # print("first complete")
        # # pool.shutdown(wait=False)
        # hi_future.cancel()

        self.curr_votes = new_votes

        print("all done!")

    def toggle_lights(self, on: bool):
        if on:
            self.green_leds.on()
            self.red_leds.on()
        else:
            self.green_leds.off()
            self.red_leds.off()

    def testman(self):
        # Test votes
        # votes_set = [Votes(60, 40), Votes(50, 50), Votes(40, 60),]
        votes_set = [Votes(100 - a, 0 + a) for a in range(0, 100, 2)]

        for temp_votes in itertools.cycle(votes_set):
            self.leds_from_votes(temp_votes)
            sleep(0.2)
            # self.green_leds.off()
            # self.red_leds.off()
            # sleep(0.2)

    def poll_to_led(self, poll_id):
        votes: Votes = self.vote_getter.get_votes_from_poll(poll_id)
        self.leds_from_votes(votes)