Exemplo n.º 1
0
def keep_alive_test(pin_number):
    """
    This program will set a digital output pin to high.
    It is assumed that an LED is connected to this pin.
    After 2 seconds the program exits, and in approximately
    one second the LED should extinguish.

    If keep_alive is working, the LED should extinguish.

    :param pin_number: A pin with an LED connected to it
    """

    board = pymata4EX.Pymata4EX()

    # set the as a digital output
    board.set_pin_mode_digital_output(pin_number)

    # set the pin high
    board.digital_write(pin_number, 1)

    # turn on keep_alives
    board.keep_alive()

    print('Sleeping for 2 seconds...')
    time.sleep(2)
    print('Exiting. In about 1 second, the LED should extinguish.')
    sys.exit(0)
Exemplo n.º 2
0
    def __init__(self, analog_pin=2, poll_time=5, differential=5):
        """

        :param analog_pin: arduino analog input pin number

        :param poll_time: polling interval in seconds

        :param differential: difference between current value and
                             previous value to consider the change
                             in value a change event
        """
        self.analog_pin = analog_pin
        self.poll_time = poll_time
        self.differential = differential

        # Callback data indices
        self.CB_PIN_MODE = 0  # pin mode (see pin modes in private_constants.py)
        self.CB_PIN = 1  # pin number
        self.CB_VALUE = 2  # reported value
        self.CB_TIME = 3  # raw time stamp

        # instantiate pymata4EX
        self.board = pymata4EX.Pymata4EX()

        # set the pin mode for analog input
        self.board.set_pin_mode_analog_input(self.analog_pin,
                                             self.the_callback,
                                             self.differential)

        # start polling
        self.keep_polling()
Exemplo n.º 3
0
 General Public License for more details.

 You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
"""

import sys
import time
from pymata4EX import pymata4EX
"""
This is a demonstration of the tone methods
"""

# instantiate pymata4EX
board = pymata4EX.Pymata4EX()
TONE_PIN = 3
try:
    # set a pin's mode for tone operations
    board.set_pin_mode_tone(TONE_PIN)

    # specify pin, frequency and duration and play tone
    board.play_tone(TONE_PIN, 1000, 500)
    time.sleep(2)

    # specify pin and frequency and play continuously
    board.play_tone_continuously(TONE_PIN, 2000)
    time.sleep(2)

    # specify pin to turn pin off
    board.play_tone_off(TONE_PIN)
Exemplo n.º 4
0
        high_nibble: int = value & 0xf0
        low_nibble: int = (value << 4) & 0xf0
        self.write_4_bits(high_nibble | mode)
        self.write_4_bits(low_nibble | mode)

    def write_4_bits(self, value: int) -> None:
        self.expander_write(value)
        self.pulse_enable(value)

    def expander_write(self, data: int) -> None:
        self.board.i2c_write(self.address, [data, self._backlight_value])

    def pulse_enable(self, data: int) -> None:
        self.expander_write(data | self.ENABLE_BIT)
        sleep(0.000001)

        self.expander_write(data & ~self.ENABLE_BIT)
        sleep(0.00005)

    def print(self, string: AnyStr) -> None:
        for character in string:
            self.write(ord(character))
            sleep(0.000001)
        else:
            sleep(0.00005)


Board = pymata4EX.Pymata4EX("/dev/ttyACM0")
LCD = LiquidCrystal_I2C(0x27, 0, 1, Board)
LCD.enable_backlight()
LCD.print("Hello, Worlds!")
Exemplo n.º 5
0
def blink(my_board, pin):
    """
    This function will to toggle a digital pin.

    :param my_board: an PymataExpress instance
    :param pin: pin to be controlled
    """

    # set the pin mode
    my_board.set_pin_mode_digital_output(pin)
    my_board.digital_write(pin, 1)

    # toggle the pin 4 times and exit
    for x in range(4):
        print('ON')
        my_board.digital_write(pin, 1)
        time.sleep(1)
        print('OFF')
        my_board.digital_write(pin, 0)
        time.sleep(1)

    my_board.shutdown()


board = pymata4EX.Pymata4EX(ip_address=IP_ADDRESS, ip_port=IP_PORT)
try:
    blink(board, DIGITAL_PIN)
except KeyboardInterrupt:
    board.shutdown()
    sys.exit(0)