本文整理匯總了Python中pyb.UART.writechar方法的典型用法代碼示例。如果您正苦於以下問題:Python UART.writechar方法的具體用法?Python UART.writechar怎麽用?Python UART.writechar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyb.UART
的用法示例。
在下文中一共展示了UART.writechar方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: uart_hash
# 需要導入模塊: from pyb import UART [as 別名]
# 或者: from pyb.UART import writechar [as 別名]
def uart_hash():
# initialize UART(6) to output TX on Pin Y1
uart = UART(6)
while True:
uart.init(9600, bits=8, parity = 0, stop = 2)
uart.writechar(ord('#')) # letter '#'
pyb.delay(5) # delay by 5ms
示例2: uart_hashtag
# 需要導入模塊: from pyb import UART [as 別名]
# 或者: from pyb.UART import writechar [as 別名]
def uart_hashtag():
the_word = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
# initialize X5 as trigger output
uart = UART(6)
uart.init(9600, bits=8, parity = None, stop = 2)
while True:
# initialize UART(6) to output TX on Pin Y1
for i in range(36):
uart.writechar(ord(the_word[i]))
uart.writechar(13)
uart.writechar(10)
pyb.delay(1000)
示例3: JYMCU
# 需要導入模塊: from pyb import UART [as 別名]
# 或者: from pyb.UART import writechar [as 別名]
class JYMCU(object):
"""JY-MCU Bluetooth serial device driver. This is simply a light UART wrapper
with addition AT command methods to customize the device."""
def __init__( self, uart, baudrate ):
""" uart = uart #1-6, baudrate must match what is set on the JY-MCU.
Needs to be a #1-C. """
self._uart = UART(uart, baudrate)
def __del__( self ) : self._uart.deinit()
def any( self ) : return self._uart.any()
def write( self, astring ) : return self._uart.write(astring)
def writechar( self, achar ) : self._uart.writechar(achar)
def read( self, num = None ) : return self._uart.read(num)
def readline( self ) : return self._uart.readline()
def readchar( self ) : return self._uart.readchar()
def readall( self ) : return self._uart.readall()
def readinto( self, buf, count = None ) : return self._uart.readinto(buf, count)
def _cmd( self, cmd ) :
""" Send AT command, wait a bit then return result string. """
self._uart.write("AT+" + cmd)
udelay(500)
return self.readline()
def baudrate( self, rate ) :
""" Set the baud rate. Needs to be #1-C. """
return self._cmd("BAUD" + str(rate))
def name( self, name ) :
""" Set the name to show up on the connecting device. """
return self._cmd("NAME" + name)
def pin( self, pin ) :
""" Set the given 4 digit numeric pin. """
return self._cmd("PIN" + str(pin))
def version( self ) : return self._cmd("VERSION")
def setrepl( self ) : repl_uart(self._uart)
示例4: ord
# 需要導入模塊: from pyb import UART [as 別名]
# 或者: from pyb.UART import writechar [as 別名]
elif command[2] == ord('6'): # DOWN PRESSED
print('Decreasing speed...')
(speedL,speedR) = speed(mode='dec',speedL=speedL,speedR=speedR)
print(speedL,speedR,vardirection)
if isRecording == True:
record(['speedDown',speedL,speedR])
elif command[2] == ord('7'): #LEFT PRESSED
print('Turning left...')
(speedL,speedR) = turn(turnDirection='l',speedL=speedL,speedR=speedR)
print(speedL,speedR,vardirection)
if isRecording == True:
record(['turnL',speedL,speedR])
elif command[2] == ord('8'): # RIGHT PRESSED
print('Turning right...')
(speedL,speedR) = turn(turnDirection='r',speedL=speedL,speedR=speedR)
print(speedL,speedR,vardirection)
if isRecording == True:
record(['turnR',speedL,speedR])
else: # writing to the robot with UART
message = 'command not understood'
print(message)
print(command)
for i in range(22):
uart.writechar(ord(message[i]))
uart.writechar(13)
uart.writechar(10)
示例5: UART
# 需要導入模塊: from pyb import UART [as 別名]
# 或者: from pyb.UART import writechar [as 別名]
from pyb import UART
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, parity=None, stop=1)
print(uart)
uart.init(2400)
print(uart)
print(uart.any())
print(uart.write('123'))
print(uart.write(b'abcd'))
print(uart.writechar(1))
# make sure this method exists
uart.sendbreak()
示例6: UART
# 需要導入模塊: from pyb import UART [as 別名]
# 或者: from pyb.UART import writechar [as 別名]
#_________________________________________________
# Task 6: Function to generate UART sequence for '#' on Y1
# initialize UART(6) to output TX on Pin Y1
import pyb
from pyb import Pin, Timer, UART
print('Task 6: Using UART to send "#"')
uart = UART(6)
while True:
uart.init(9600, bits=8, parity = 0, stop = 2)
uart.writechar(ord('#'))
pyb.delay(5)