Example #1
0
class Motor(object):
    
    def __init__(self, pin1, pin2):
        self.pin1 = pin1
        self.pin2 = pin2
        io.setmode(io.BCM)
        io.setup(pin1, io.OUT)
        io.setup(pin2, io.OUT)

        self.Pin1 = Pin(pin1)
        self.Pin2 = Pin(pin2)

    def drive_forward(self):
        io.output(self.pin1, io.HIGH)
        io.output(self.pin2, io.LOW)

    def drive_back(self):
        io.output(self.pin1, io.LOW)
        io.output(self.pin2, io.HIGH)

    def stop(self):
        io.output(self.pin1, io.LOW)
        io.output(self.pin2, io.LOW)

    def drive(self, speed=0.0):
        if speed >= 0.0:
            self.Pin1.output(speed)
            self.Pin2.output(0)
        else:
            self.Pin1.output(0)
            self.Pin2.output(abs(speed))
Example #2
0
 def test_output_one(self):
     p24 = Pin(24)
     p24.output(1)
     self.assertEqual(p24.value, 1.0)
     self.assertTrue(p24._stopped)
Example #3
0
 def test_output_zero(self):
     p24 = Pin(24)
     p24.output(0)
     self.assertEqual(p24.value, 0.0)
     self.assertTrue(p24._stopped)
Example #4
0
 def test_thread_running(self):
     p24 = Pin(24)
     p24.output(.5)
     self.assertTrue(p24._thread.is_alive())
Example #5
0
 def test_output(self):
     p24 = Pin(24)
     p24.output(.5)
     self.assertEqual(p24.value, 0.5)
Example #6
0
 def test_output_one(self):
     p24 = Pin(24)
     p24.output(1)
     self.assertEqual(p24.value, 1.0)
     self.assertTrue(p24._stopped)
Example #7
0
 def test_output_zero(self):
     p24 = Pin(24)
     p24.output(0)
     self.assertEqual(p24.value, 0.0)
     self.assertTrue(p24._stopped)
Example #8
0
 def test_thread_running(self):
     p24 = Pin(24)
     p24.output(.5)
     self.assertTrue(p24._thread.is_alive())
Example #9
0
 def test_output(self):
     p24 = Pin(24)
     p24.output(.5)
     self.assertEqual(p24.value, 0.5)