Пример #1
0
 def motor_brake(self, motor):
     if motor == KMotor.MOTOR_1:
         pin8.write_digital(1)
         pin12.write_digital(1)
     else:
         pin0.write_digital(1)
         pin16.write_digital(1)
Пример #2
0
    def motor_on(self, motor, direction, speed=100):
        """
        Turn motor with the given direction and speed
        :param motor: KMotor.MOTOR1 or KMotor.Motor2
        :param direction: KMotor.FORWARD or KMOTOR.REVERSE
        :param speed: 0 - 100
        :return:
        """
        # make sure the speed is within range
        if not 0 <= speed <= 100:
            # not display a "NO" and return
            display.show(Image.NO)
            return

        # speed needs to be scaled from 0-100 to 0-1023
        speed = self._scale(speed)

        # Move Motor Forward
        if direction == KMotor.FORWARD:
            if motor == KMotor.MOTOR_1:
                pin8.write_analog(speed)
                pin12.write_digital(0)
            elif motor == KMotor.MOTOR_2:
                pin0.write_analog(speed)
                pin16.write_digital(0)

        # Move Motor In Reverse
        else:
            if motor == KMotor.MOTOR_1:
                pin12.write_analog(speed)
                pin8.write_digital(0)
            elif motor == KMotor.MOTOR_2:
                pin16.write_analog(speed)
                pin0.write_digital(0)
Пример #3
0
    def readADC(self):
        pin16.write_digital(0)  # set CS to low to start communication
        bytes_received = spi.read(2)  # read 2 bytes
        pin16.write_digital(1)  # set CS to high again to stop communication

        MSB_1 = bytes_received[1] >> 1
        # shift right 1 bit to remove B01 from the LSB mode
        MSB_0 = (bytes_received[0] & 0b00011111) << 7
        # first mask the two unknown bits & the null bit
        # then shift left 7 bits (i.e. the first 5 of 12 bits)
        return MSB_0 + MSB_1
Пример #4
0
 def motor_brake(self, motor):
     """
     Brake the selected motor.
     :param motor:
     :return:
     """
     if motor == KMotor.MOTOR_1:
         pin8.write_digital(1)
         pin12.write_digital(1)
     else:
         pin0.write_digital(1)
         pin16.write_digital(1)
Пример #5
0
 def motor_on(self, motor, direction, speed=100):
     if not 0 <= speed <= 100:
         display.show(Image.NO)
         return
     speed = self._scale(speed)
     if direction == KMotor.FORWARD:
         if motor == KMotor.MOTOR_1:
             pin8.write_analog(speed)
             pin12.write_digital(0)
         elif motor == KMotor.MOTOR_2:
             pin0.write_analog(speed)
             pin16.write_digital(0)
     else:
         if motor == KMotor.MOTOR_1:
             pin12.write_analog(speed)
             pin8.write_digital(0)
         elif motor == KMotor.MOTOR_2:
             pin16.write_analog(speed)
             pin0.write_digital(0)
Пример #6
0
 def __cmd(self, c):
     pin16.write_digital(0)
     spi.write(bytearray(c))
     pin16.write_digital(1)
Пример #7
0
 def __init__(self):
     spi.init()
     pin16.write_digital(1)  # setup CS and set to high
     pass