コード例 #1
0
 def motor_off(self, motor):
     if motor == KMotor.MOTOR_1:
         pin8.write_analog(0)
         pin12.write_analog(0)
     else:
         pin0.write_analog(0)
         pin16.write_analog(0)
コード例 #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 motor_off(self, motor):
     """
     Place motor in coast mode
     :param motor: KMotor.MOTOR1 or KMotor.Motor2
     :return:
     """
     if motor == KMotor.MOTOR_1:
         pin8.write_analog(0)
         pin12.write_analog(0)
     else:
         pin0.write_analog(0)
         pin16.write_analog(0)
コード例 #4
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)