def lights_off():
    global lights_are_on, playlist_playing
    initialize_interface()
    if playlist_playing:
        stop_playlist()
    turn_off_lights()
    lights_are_on = False
def main():
    """
    Play a message

    Play a recorded message for the people and go through the lights
    one channel at a time in order, then back down to the first
    """

    # initialize your hardware for use
    hc.initialize()

    # start with all the lights off
    hc.turn_off_lights()

    # Before we start the lights we should start playing the audio
    # we have installed mpg123 to make this easy
    # if you do not have mpg123 installed then use this command to install it
    # sudo apt-get install mpg123
    # now all you have to do is use the below command to play an mp3 file
    message_file = "/home/pi/lightshowpi/py/examples/message.mp3"
    message = subprocess.Popen(["mpg123", "-q", message_file])

    # subprocess.Popen will open mpg123 player and play an audio file for you
    # and give you a few options that will come in real handy
    # you can stop mpg123 before the audio has finished using the instance
    # variable we just created by calling message.kill()
    # or at any point in the script you can make everything wait for the audio
    # to finish playing with message.wait() that could be usefull if you
    # ran a short seuqence like in the default preshow and your audio as longer
    # then your sequence and you wanted the audio to finish before continuing
    # and if you use message.poll() or message.returncode you could find out
    # if it has finished, then you might start something else or end everything
    # and shutdown your pi.

    # working loop
    while True:
        # try except block to catch keyboardinterrupt by user to stop
        try:
            hc.turn_on_lights()

        except KeyboardInterrupt:
            print "\nstopped"
            break

        # if audio playback has finished break out of the loop
        if message.poll() != None:
            break

    # This ends and cleans up everything
    hc.clean_up()
def main():
    """
    Play a message

    Play a recorded message for the people and go through the lights
    one channel at a time in order, then back down to the first
    """

    # initialize your hardware for use
    hc.initialize()

    # start with all the lights off
    hc.turn_off_lights()

    # Before we start the lights we should start playing the audio
    # we have installed mpg123 to make this easy
    # if you do not have mpg123 installed then use this command to install it
    # sudo apt-get install mpg123
    # now all you have to do is use the below command to play an mp3 file
    message_file = "/home/pi/lightshowpi/py/examples/message.mp3"
    message = subprocess.Popen(["mpg123", "-q", message_file])

    # subprocess.Popen will open mpg123 player and play an audio file for you
    # and give you a few options that will come in real handy
    # you can stop mpg123 before the audio has finished using the instance
    # variable we just created by calling message.kill()
    # or at any point in the script you can make everything wait for the audio
    # to finish playing with message.wait() that could be usefull if you
    # ran a short seuqence like in the default preshow and your audio as longer
    # then your sequence and you wanted the audio to finish before continuing
    # and if you use message.poll() or message.returncode you could find out
    # if it has finished, then you might start something else or end everything
    # and shutdown your pi.

    # working loop
    while True:
        # try except block to catch keyboardinterrupt by user to stop
        try:
            hc.turn_on_lights()

        except KeyboardInterrupt:
            print "\nstopped"
            break

        # if audio playback has finished break out of the loop
        if message.poll() != None:
            break

    # This ends and cleans up everything
    hc.clean_up()
def execute_preshow(config):
    '''Execute the "Preshow" for the given preshow configuration'''
    for transition in config['transitions']:
        start = time.time()
        if transition['type'].lower() == 'on':
            hc.turn_on_lights(True)
        else:
            hc.turn_off_lights(True)
        logging.debug('Transition to ' + transition['type'] + ' for '
            + str(transition['duration']) + ' seconds')
        while transition['duration'] > (time.time() - start):
            cm.load_state()  # Force a refresh of state from file
            play_now = int(cm.get_state('play_now', 0))
            if play_now:
                return  # Skip out on the rest of the preshow

            # Check once every ~ .1 seconds to break out
            time.sleep(0.1)
def execute_preshow(config):
    '''Execute the "Preshow" for the given preshow configuration'''
    for transition in config['transitions']:
        start = time.time()
        if transition['type'].lower() == 'on':
            hc.turn_on_lights(True)
        else:
            hc.turn_off_lights(True)
        logging.debug('Transition to ' + transition['type'] + ' for ' +
                      str(transition['duration']) + ' seconds')
        while transition['duration'] > (time.time() - start):
            cm.load_state()  # Force a refresh of state from file
            play_now = int(cm.get_state('play_now', 0))
            if play_now:
                return  # Skip out on the rest of the preshow

            # Check once every ~ .1 seconds to break out
            time.sleep(0.1)
def main():
    """
    Test pattern2

    Unlights one channel at a time in order
    """
    # this is a list of all the channels you have access to
    lights = hc._GPIO_PINS

    # initialize your hardware for use
    hc.initialize()

    # start with all the lights off
    hc.turn_off_lights()

    # pause for 1 second
    time.sleep(2)

    # working loop
    for _ in range(50):
        # try except block to catch keyboardinterrupt by user to stop
        try:
            # here we just loop over the gpio pins and do something with them
            for light in lights:
                # turn on all the lights
                hc.turn_on_lights()

                # then turn off one
                hc.turn_off_light(light)

                # wait a little bit before the for loop
                # starts again and turns off the next light
                time.sleep(.4)

        # if the user pressed <CTRL> + C to exit early break out of the loop
        except KeyboardInterrupt:
            print "\nstopped"
            break

    # This ends and cleans up everything
    hc.clean_up()
Beispiel #7
0
def main():
    """
    PWM example

    Start at each end and walk to the other using pwm
    """
    # this is a list of all the channels you have access to
    lights = hc._GPIO_PINS

    # the gpio pins in reversed order
    lights2 = lights[::-1]

    # get _PWM_MAX from the hc module
    # this is the max value for the pwm channels
    pwm_max = hc._PWM_MAX
    # initialize your hardware for use
    hc.initialize()

    # start with all the lights off
    hc.turn_off_lights()

    # pause for 1 second
    time.sleep(1)

    # working loop, we will do this sequence 10 times then end
    for _ in range(10):
        # here we just loop over the gpio pins and turn then on and off
        # with the pwm feature of lightshowpi
        for light in range(int(len(lights) / 2)):
            if hc.is_pin_pwm(lights[light]) and hc.is_pin_pwm(lights2[light]):
                for brightness in range(0, pwm_max):
                    # fade in
                    hc.turn_on_light(lights[light], 0,
                                     float(brightness) / pwm_max)

                    hc.turn_on_light(lights2[light], 0,
                                     float(brightness) / pwm_max)

                    time.sleep(.05 / pwm_max)

                for brightness in range(pwm_max - 1, -1, -1):
                    # fade out
                    hc.turn_on_light(lights[light], 0,
                                     float(brightness) / pwm_max)

                    hc.turn_on_light(lights2[light], 0,
                                     float(brightness) / pwm_max)

                    time.sleep(.05 / pwm_max)

        for light in range(int(len(lights) / 2) - 1, -1, -1):
            if hc.is_pin_pwm(lights[light]) and hc.is_pin_pwm(lights2[light]):
                for brightness in range(0, pwm_max):
                    # fade in
                    hc.turn_on_light(lights[light], 0,
                                     float(brightness) / pwm_max)

                    hc.turn_on_light(lights2[light], 0,
                                     float(brightness) / pwm_max)

                    time.sleep(.05 / pwm_max)

                for brightness in range(pwm_max - 1, -1, -1):
                    # fade out
                    hc.turn_on_light(lights[light], 0,
                                     float(brightness) / pwm_max)

                    hc.turn_on_light(lights2[light], 0,
                                     float(brightness) / pwm_max)

                    time.sleep(.05 / pwm_max)

    # This ends and cleans up everything
    hc.clean_up()
Beispiel #8
0
def main():
    """
    ladder

    Lights one channel at a time in order
    Then backs down to the first
    Then repeat everything 20 times
    """
    # this is a list of all the channels you have access to
    lights = hc._GPIO_PINS

    # initialize your hardware for use
    hc.initialize()

    # start with all the lights off
    hc.turn_off_lights()

    # pause for 1 second
    time.sleep(1)

    # working loop
    for _ in range(20):
        # try except block to catch keyboardinterrupt by user to stop
        try:
            # here we just loop over the gpio pins and do something with them
            # except the last one
            for light in range(len(lights) - 1):
                # turn off all the lights
                hc.turn_off_lights()

                # then turn on one
                hc.turn_on_light(lights[light])

                # wait a little bit
                time.sleep(.04)

            # to make the transition back smoother we handle the last pin here
            hc.turn_off_lights()
            hc.turn_on_light(lights[light + 1])

            # this loop walks it back the other way
            for light in range(len(lights) - 1, 0, -1):
                # turn off all the lights
                hc.turn_off_lights()

                # then turn on one
                hc.turn_on_light(lights[light])

                # wait a little bit
                time.sleep(.04)

            # again to make it smoother handle the first pin like the last pin
            hc.turn_off_lights()
            hc.turn_on_light(lights[light - 1])

        # if the user pressed <CTRL> + C to exit early break out of the loop
        except KeyboardInterrupt:
            print "\nstopped"
            break

    # This ends and cleans up everything
    hc.clean_up()
Beispiel #9
0
    def execute(self):
        """
        Execute the pre/post show as defined by the current config

        Returns the exit status of the show, either done if the
        show played to completion, or play_now_interrupt if the
        show was interrupted by a play now command.
        """
        # Is there a show to launch?
        if self.config == None:
            return PrePostShow.done

        # Is the config a script or a transition based show
        # launch the script if it is
        if not isinstance(self.config, dict) and os.path.exists(self.config):
            logging.debug("Launching external script " + self.config + " as " \
                + self.show)
            return self.start_script()

        # start the audio if there is any
        self.start_audio()

        if 'transitions' in self.config:
            try:
                # display transition based show
                for transition in self.config['transitions']:
                    start = time.time()
                    if transition['type'].lower() == 'on':
                        hc.turn_on_lights(True)
                    else:
                        hc.turn_off_lights(True)
                    logging.debug('Transition to ' + transition['type'] + ' for ' \
                        + str(transition['duration']) + ' seconds')

                    if 'channel_control' in transition:
                        channel_control = transition['channel_control']
                        for key in channel_control.keys():
                            mode = key
                            channels = channel_control[key]
                            for channel in channels:
                                if mode == 'on':
                                    hc.turn_on_light(int(channel) - 1, 1)
                                elif mode == 'off':
                                    hc.turn_off_light(int(channel) - 1, 1)
                                else:
                                    logging.error("Unrecognized channel_control mode "
                                                "defined in preshow_configuration " \
                                                    + str(mode))
                    # hold transition for specified time
                    while transition['duration'] > (time.time() - start):
                        # check for play now
                        if check_state():
                            # kill the audio playback if playing
                            if self.audio:
                                os.killpg(self.audio.pid, signal.SIGTERM)
                                self.audio = None
                            return PrePostShow.play_now_interrupt
                        time.sleep(0.1)
            except:
                pass

        # hold show until audio has finished if we have audio
        # or audio is not finished
        return_value = self.hold_for_audio()

        return return_value
Beispiel #10
0
    def execute(self):
        """
        Execute the pre/post show as defined by the current config

        Returns the exit status of the show, either done if the
        show played to completion, or play_now_interrupt if the
        show was interrupted by a play now command.
        """
        # Is there a show to launch?
        if self.config == None:
            return PrePostShow.done

        # Is the config a script or a transition based show
        # launch the script if it is
        if not isinstance(self.config, dict) and os.path.exists(self.config):
            logging.debug("Launching external script " + self.config + " as " + self.show)
            return self.start_script()

        # start the audio if there is any
        self.start_audio()

        if "transitions" in self.config:
            try:
                # display transition based show
                for transition in self.config["transitions"]:
                    start = time.time()
                    if transition["type"].lower() == "on":
                        hc.turn_on_lights(True)
                    else:
                        hc.turn_off_lights(True)
                    logging.debug(
                        "Transition to " + transition["type"] + " for " + str(transition["duration"]) + " seconds"
                    )

                    if "channel_control" in transition:
                        channel_control = transition["channel_control"]
                        for key in channel_control.keys():
                            mode = key
                            channels = channel_control[key]
                            for channel in channels:
                                if mode == "on":
                                    hc.turn_on_light(int(channel) - 1, 1)
                                elif mode == "off":
                                    hc.turn_off_light(int(channel) - 1, 1)
                                else:
                                    logging.error(
                                        "Unrecognized channel_control mode "
                                        "defined in preshow_configuration " + str(mode)
                                    )
                    # hold transition for specified time
                    while transition["duration"] > (time.time() - start):
                        # check for play now
                        if check_state():
                            # kill the audio playback if playing
                            if self.audio:
                                os.killpg(self.audio.pid, signal.SIGTERM)
                                self.audio = None
                            return PrePostShow.play_now_interrupt
                        time.sleep(0.1)
            except:
                pass

        # hold show until audio has finished if we have audio
        # or audio is not finished
        return_value = self.hold_for_audio()

        return return_value
Beispiel #11
0
def main():
    """
    ladder

    Lights one channel at a time in order
    Then backs down to the first
    Then repeat everything 20 times
    """
    # this is a list of all the channels you have access to
    lights = hc._GPIO_PINS

    # initialize your hardware for use
    hc.initialize()

    # start with all the lights off
    hc.turn_off_lights()

    # pause for 1 second
    time.sleep(1)

    # working loop
    for _ in range(20):
        # try except block to catch keyboardinterrupt by user to stop
        try:
            # here we just loop over the gpio pins and do something with them
            # except the last one
            for light in range(len(lights)-1):
                # turn off all the lights
                hc.turn_off_lights()

                # then turn on one
                hc.turn_on_light(lights[light])

                # wait a little bit
                time.sleep(.04)

            # to make the transition back smoother we handle the last pin here
            hc.turn_off_lights()
            hc.turn_on_light(lights[light + 1])

            # this loop walks it back the other way
            for light in range(len(lights)-1, 0, -1):
                # turn off all the lights
                hc.turn_off_lights()

                # then turn on one
                hc.turn_on_light(lights[light])

                # wait a little bit
                time.sleep(.04)

            # again to make it smoother handle the first pin like the last pin
            hc.turn_off_lights()
            hc.turn_on_light(lights[light - 1])

        # if the user pressed <CTRL> + C to exit early break out of the loop
        except KeyboardInterrupt:
            print "\nstopped"
            break

    # This ends and cleans up everything
    hc.clean_up()