예제 #1
0
    def set_pin(self, pin_number, pin_input, pin_analogue):
        """
        For a given pin, set the direction and type for the microbit pin.

        :param pin_number: Pin number of the microbit
        :param pin_input: False for output, True for input
        :param pin_analogue: False for digital, True for analogue
        :return:
        """
        pin_bit = tools.int_to_uint32(2**pin_number)
        current_io_setting = self._pin_config
        current_ad_setting = self._pin_ad_config
        if pin_input:
            new_setting = tools.bitwise_or_2lists(pin_bit, current_io_setting)
            self._pin_config = new_setting
        else:
            pin_mask = tools.bitwise_xor_2lists(pin_bit,
                                                [0xff, 0xff, 0xff, 0xff])
            new_setting = tools.bitwise_and_2lists(pin_mask,
                                                   current_io_setting)
            self._pin_config = new_setting
        if pin_analogue:
            new_setting = tools.bitwise_or_2lists(pin_bit, current_ad_setting)
            self._pin_ad_config = new_setting
        else:
            pin_mask = tools.bitwise_xor_2lists(pin_bit,
                                                [0xff, 0xff, 0xff, 0xff])
            new_setting = tools.bitwise_and_2lists(pin_mask,
                                                   current_ad_setting)
            self._pin_ad_config = new_setting
예제 #2
0
    def set_pin(self, pin_number, pin_input, pin_analogue):
        """
        For a given pin, set the direction and type for the microbit pin.

        :param pin_number: Pin number of the microbit
        :param pin_input: False for output, True for input
        :param pin_analogue: False for digital, True for analogue
        :return:
        """
        pin_bit = tools.int_to_uint32(2 ** pin_number)
        current_io_setting = self._pin_config
        current_ad_setting = self._pin_ad_config
        if pin_input:
            new_setting = tools.bitwise_or_2lists(pin_bit, current_io_setting)
            self._pin_config = new_setting
        else:
            pin_mask = tools.bitwise_xor_2lists(pin_bit,
                                                [0xff, 0xff, 0xff, 0xff])
            new_setting = tools.bitwise_and_2lists(pin_mask,
                                                   current_io_setting)
            self._pin_config = new_setting
        if pin_analogue:
            new_setting = tools.bitwise_or_2lists(pin_bit,
                                                  current_ad_setting)
            self._pin_ad_config = new_setting
        else:
            pin_mask = tools.bitwise_xor_2lists(pin_bit,
                                                [0xff, 0xff, 0xff, 0xff])
            new_setting = tools.bitwise_and_2lists(pin_mask,
                                                   current_ad_setting)
            self._pin_ad_config = new_setting