Stephen Covrig
/
Motor Control via PyQt
KL46Z code to use in conjunction with a PyQt GUI over a serial communication.
Here is the Python code for the PyQt Gui...
from PyQt4.QtGui import * from PyQt4.QtCore import * import sys import serial def printNumber(number): print number ser = serial.Serial('COM5',9600) #state which port the KL46Z is connected to and the baud rate ser.write(unichr(number).encode()) #encode number from slider and send the encoded character to KL46Z if __name__=="__main__": app=QApplication(sys.argv) slider=QSlider(Qt.Horizontal) slider.setRange(1,127) slider.setFixedWidth(400) slider.setSliderPosition(64) #create a QApplication and QSlider QObject.connect(slider,SIGNAL("valueChanged(int)"),printNumber) #call the printNumber funciton each time the value on the slider changes slider.show() #start the loop sys.exit(app.exec_())
mbed.bld@0:f2c6afc8e527, 2016-12-09 (annotated)
- Committer:
- covrigs
- Date:
- Fri Dec 09 19:58:50 2016 +0000
- Revision:
- 0:f2c6afc8e527
For ECE 111, Lab 4. KL46Z receives serial data from a python GUI and controls a motor via an L293D.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
covrigs | 0:f2c6afc8e527 | 1 | http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0 |