1+ #!/usr/bin/env python
2+ #-----------------------------------------------------------------------------
3+ # A simple test to speed up and slow down both motors in opposite directions.
4+ #------------------------------------------------------------------------
5+ #
6+ # Written by Mark Lindemer
7+ # SparkFun Electronics, April 2020
8+ #
9+ # This python library supports the SparkFun Electroncis qwiic
10+ # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
11+ # board computers.
12+ #
13+ # More information on qwiic is at https://www.sparkfun.com/qwiic
14+ #
15+ # Do you like this library? Help support SparkFun. Buy a board!
16+ #
17+ #==================================================================================
18+ # Copyright (c) 2019 SparkFun Electronics
19+ #
20+ # Permission is hereby granted, free of charge, to any person obtaining a copy
21+ # of this software and associated documentation files (the "Software"), to deal
22+ # in the Software without restriction, including without limitation the rights
23+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24+ # copies of the Software, and to permit persons to whom the Software is
25+ # furnished to do so, subject to the following conditions:
26+ #
27+ # The above copyright notice and this permission notice shall be included in all
28+ # copies or substantial portions of the Software.
29+ #
30+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+ # SOFTWARE.
37+ #==================================================================================
38+ # Example 1
39+ #
40+
41+ from __future__ import print_function
42+ import time
43+ import sys
44+ import math
45+ import qwiic_scmd
46+
47+ myMotor = qwiic_scmd .QwiicScmd ()
48+
49+ def runExample ():
50+ print ("Motor Test." )
51+ R_MTR = 0
52+ L_MTR = 1
53+ FWD = 0
54+ BWD = 1
55+
56+ if myMotor .connected == False :
57+ print ("Motor Driver not connected. Check connections." , \
58+ file = sys .stderr )
59+ return
60+ myMotor .begin ()
61+ print ("Motor initialized." )
62+ time .sleep (.250 )
63+ myMotor .enable ()
64+ print ("Motor enabled" )
65+ time .sleep (.250 )
66+
67+
68+ while True :
69+ speed = 20
70+ for speed in range (20 ,255 ):
71+ print (speed )
72+ myMotor .set_drive (R_MTR ,FWD ,speed )
73+ myMotor .set_drive (L_MTR ,BWD ,speed )
74+ time .sleep (.05 )
75+ for speed in range (255 ,20 , - 1 ):
76+ print (speed )
77+ myMotor .set_drive (R_MTR ,FWD ,speed )
78+ myMotor .set_drive (L_MTR ,BWD ,speed )
79+ time .sleep (.05 )
80+
81+ if __name__ == '__main__' :
82+ try :
83+ runExample ()
84+ except (KeyboardInterrupt , SystemExit ) as exErr :
85+ print ("Ending example." )
86+ myMotor .disable ()
87+ sys .exit (0 )
0 commit comments