Skip to content

Instantly share code, notes, and snippets.

@tjvr
Forked from hyperobject/s2.py
Last active August 29, 2015 13:56
Show Gist options
  • Save tjvr/8866227 to your computer and use it in GitHub Desktop.
Save tjvr/8866227 to your computer and use it in GitHub Desktop.
from __future__ import division
from myro import *
import blockext
from blockext import *
@command("stop both motors")
def stop_motors():
bot.stop()
@command("set speed %n")
def drive_straight(speed=100):
bot.translate(speed / 100)
@command("set speed left: %n right: %n")
def drive_left_right(ls=100, rs=100):
bot.motors(ls, rs)
@command("play tone %n for %n seconds")
def play_tone(tone=500, time=1):
bot.beep(time, tone)
@command("set S2 name to %s")
def set_name(name):
bot.setName(name)
menu("ledPos", ["right", "left"])
menu("onOff", ["on", "off"])
@command("turn %m.ledPos led %m.onOff")
def set_led(ledpos="right", onoff="on"):
bot.setLED(ledpos, onoff)
if onoff == "off":
bot.setLED(ledpos,"off")
@reporter("get line sensor %n value")
def get_line(n=1):
return bot.getLine(n - 1)
@reporter("get IR sensor %n value")
def get_IR(n=1):
return bot.getIR(n - 1)
menu('lightSensor', ['left', 'center', 'right'])
@reporter("get light sensor %m.lightSensor value")
def get_light(lightsensor='center'):
positions = {'left': 0, 'center': 1, 'right': 2}
return bot.getLight(positions[lightsensor])
@reporter("get S2 name")
def get_name():
return bot.getName()
@reset
def reset_s2():
bot.stop()
bot = Scribbler()
blockext.run("Parallax S2 robot", "s2", 3610)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment