summaryrefslogtreecommitdiff
path: root/Origin/user-code/dcmotor/python/dcmotor-loop.py
blob: ee2f9cc98f62cb8979d4482486f0c775b611ec87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import sys
import os 
import sys
cwd = os.getcwd()
(setpath, Examples) = os.path.split(cwd)
sys.path.append(setpath)

from Arduino.Arduino import Arduino
from time import sleep

class DCMOTOR_ROTATION:
	def __init__(self,baudrate):
		self.baudrate = baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino = Arduino()
		self.port = self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1, self.port, self.baudrate)

	def run(self):
		self.pin1 = 9
		self.pin2 = 10
		for i in range(4):
			self.obj_arduino.cmd_dcmotor_setup(1, 3, 1, self.pin1, self.pin2)
			self.obj_arduino.cmd_dcmotor_run(1, 1, 100)
			sleep(3)
			self.obj_arduino.cmd_dcmotor_run(1,1,0)
			sleep(2)
			self.obj_arduino.cmd_dcmotor_run(1,1,-100)
			sleep(2)
		self.obj_arduino.cmd_dcmotor_release(1,1)
		
	def exit(self):
		self.obj_arduino.close_serial()

def main():
	obj_dcmotor = DCMOTOR_ROTATION(115200)

if __name__== '__main__':
	main()