User Tools

Site Tools


servoclass-py

This is an old revision of the document!



Warning: Declaration of syntax_plugin_wrap_div::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/div.php on line 43

Warning: Declaration of syntax_plugin_wrap_div::render($mode, Doku_Renderer &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/div.php on line 81

Warning: Declaration of syntax_plugin_wrap_closesection::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/closesection.php on line 23

Warning: Declaration of syntax_plugin_wrap_closesection::render($mode, Doku_Renderer &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/closesection.php on line 29

Warning: Declaration of syntax_plugin_wrap_span::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/span.php on line 43

Warning: Declaration of syntax_plugin_wrap_span::render($mode, Doku_Renderer &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/wrap/syntax/span.php on line 63

Warning: Declaration of syntax_plugin_gallery::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/gallery/syntax.php on line 51

Warning: Declaration of syntax_plugin_gallery::render($mode, &$R, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/gallery/syntax.php on line 147

Warning: Declaration of syntax_plugin_vshare::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/kucjica/emperors-wiki/lib/plugins/vshare/syntax.php on line 47

Warning: Declaration of syntax_plugin_vshare::render($mode, &$R, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/kucjica/emperors-wiki/lib/plugins/vshare/syntax.php on line 107

Warning: preg_match(): Compilation failed: invalid range in character class at offset 3444 in /var/www/kucjica/emperors-wiki/inc/parser/lexer.php on line 118
A PCRE internal error occured. This might be caused by a faulty plugin

====== servoclass.py ====== external functions for different LED behaviours <code python> #!/usr/bin/env python """servoclass.py: connects to usbport and defines the movement of servo motors""" import serial, glob ### assign arduino's serial port try: portmotor = glob.glob("/dev/arduino-motors")[0] # as assigned in udev rules /etc/udev/rules.d ; http://hackaday.com/2009/09/18/how-to-write-udev-rules/ except IndexError: portmotor = glob.glob("/dev/ttyUSB0")[0] # fall back to a default USB address # portled = glob.glob("/dev/tty*")[0] print "portmotor:", portmotor ### set up serial baud rate sermotor = serial.Serial(portmotor, 9600, timeout=1) class Servo: def __init__(self, servoID): self.servoID = servoID self.stop() # when initiated, stop! def move(self, speed): self.speed = speed if 0 <= self.speed <= 180: sermotor.write(chr(255)) sermotor.write(chr(self.servoID)) sermotor.write(chr(self.speed)) else: print "Servo position must be an integer between 0 and 180.\n" def stop(self): self.move(90) #print "stop (90)" def down_slow(self): self.move(100) #print "down_slow (100)" def down_medium(self): self.move(110) #print "down_medium (110)" def down_fast(self): self.move(120) #print "down_fast (120)" def up(self): self.move(80) #print "up (80)" </code>

servoclass-py.1430383340.txt.gz · Last modified: 2015/04/30 08:42 by zoza