本文整理汇总了Python中nanpy.Arduino类的典型用法代码示例。如果您正苦于以下问题:Python Arduino类的具体用法?Python Arduino怎么用?Python Arduino使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arduino类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop
def stop():
print "EXECUTING STOP"
Arduino.analogWrite(SPEED_B_PIN, 0)
Arduino.analogWrite(SPEED_A_PIN, 0)
Arduino.analogWrite(LED_PIN_R, 200)
Arduino.analogWrite(LED_PIN_G, 0)
Arduino.analogWrite(LED_PIN_B, 0)
示例2: pirSense
def pirSense(self):
for key in self.unit['pir']:
pin = self.unit['pir'][key]['pin']
Arduino.pinMode(pin, Arduino.INPUT)
self.unit['pir'][key].update(state=Arduino.digitalRead(pin))
示例3: forward
def forward(dist, vel):
"""
Move forward for dist (time) at vel (motor speed)
"""
Arduino.digitalWrite(dirA, Arduino.HIGH)
Arduino.digitalWrite(dirB, Arduino.HIGH)
Arduino.analogWrite(speedA, vel)
Arduino.analogWrite(speedB, vel)
Arduino.delay(dist)
示例4: lights
def lights():
status = request.json['status']
if status == 'on':
Arduino.digitalWrite(boardconfig.lights_pin, 1)
elif status == 'off':
Arduino.digitalWrite(boardconfig.lights_pin, 0)
else:
return jsonify({ 'error' : 'use status on or off' }), 400
return jsonify({ 'status' : 'success' }), 200
示例5: arduinoPinwriteoutInd
def arduinoPinwriteoutInd(outpin, PWM_Levelout):
global targetpin
targetpin = outpin
global writeVAR
writeVAR = PWM_Levelout
if USE_FIRMATA:
outpin.write(writeVAR / 255.0)
elif USE_NANPY:
Arduino.analogWrite(targetpin, writeVAR)
示例6: go_forward
def go_forward():
print "executing go_forward"
speed = 255
direction = 0
Arduino.digitalWrite(DIR_B_PIN, direction)
Arduino.analogWrite(SPEED_B_PIN, speed)
Arduino.digitalWrite(DIR_A_PIN, direction)
Arduino.analogWrite(SPEED_A_PIN, speed)
Arduino.analogWrite(LED_PIN_G, 155)
示例7: turn_left
def turn_left(angle, vel):
"""
Turns to the left according to angle (delay)
"""
Arduino.digitalWrite(dirA, Arduino.HIGH)
Arduino.digitalWrite(dirB, Arduino.LOW)
Arduino.analogWrite(speedA, vel)
Arduino.analogWrite(speedB, Arduino.LOW)
Arduino.delay(angle)
示例8: reverse
def reverse(dist, vel):
"""
Move backwards for dist (time) at vel (motor speed)
"""
Arduino.digitalWrite(dirA, Arduino.LOW)
Arduino.digitalWrite(dirB, Arduino.LOW)
Arduino.analogWrite(speedA, vel)
Arduino.analogWrite(speedB, vel)
Arduino.delay(dist)
示例9: read_sensors
def read_sensors():
"""
Reads each of the Sharp sensors are returns a list of analog readings
in order: front, right, left, rear
"""
reading = []
for i in [FrontBump, RightBump, LeftBump, RearBump]:
reading.append(Arduino.analogRead(i))
Arduino.delay(1)
return reading
示例10: rot_ccw
def rot_ccw(angle, vel):
"""
Spins to the left according to angle (delay),
then stops the motors
"""
Arduino.digitalWrite(dirA, Arduino.HIGH)
Arduino.digitalWrite(dirB, Arduino.LOW)
Arduino.analogWrite(speedA, vel)
Arduino.analogWrite(speedB, vel)
Arduino.delay(angle)
示例11: __fetchAddress
def __fetchAddress(self):
ds_address = self.__ds.search()
if ds_address == "1":
return False
self.__ds.reset()
self.__ds.select(ds_address)
self.__ds.write(0x44, 1)
Arduino.delay(700)
present = self.__ds.reset()
self.__ds.select(ds_address)
self.__ds.write(0xBE)
return True
示例12: go
def go(vel):
"""
Start the motors and keep them running until told otherwise
"""
Arduino.digitalWrite(dirA, Arduino.HIGH)
Arduino.digitalWrite(dirB, Arduino.HIGH)
Arduino.analogWrite(speedA, vel)
Arduino.analogWrite(speedB, vel)
示例13: close_pins
def close_pins():
"""
Close all motor pins to quit cleanly upon end or exception
"""
Arduino.analogWrite(speedA, Arduino.LOW)
Arduino.analogWrite(speedB, Arduino.LOW)
Arduino.digitalWrite(dirA, Arduino.LOW)
Arduino.digitalWrite(dirB, Arduino.LOW)
示例14: get_pots
def get_pots():
"""
Grab a reading from each of the pot pins and
send it to a tuple to be read by the colour mixer
"""
r = Arduino.analogRead(pot_r_Pin) / 4
Arduino.delay(1)
g = Arduino.analogRead(pot_g_Pin) / 4
Arduino.delay(1)
b = Arduino.analogRead(pot_b_Pin) / 4
Arduino.delay(1)
return r, g, b
示例15: main
def main():
while True:
try:
locked = Arduino.digitalRead(lock)
if locked == 0:
debug()
else:
### Actual Avoider coder starts below ###
if not front_bump():
if not left_bump() and not right_bump():
print "No bump detected - on we go!"
go(200)
if left_bump() and not right_bump():
print "Left bump detected... Turning right"
rot_cw(100, 200)
elif right_bump() and not left_bump():
print "Right bump detected... Turning left"
rot_ccw(100, 200)
elif left_bump() and right_bump():
print "Both left & right bumps detected... Turning round!"
rot_cw(500, 200)
else:
print "Front bump detected... Turning round!"
rot_cw(500, 200)
# avoider code ends above
except KeyboardInterrupt:
close_pins()
print "\nExiting"
quit()