def __init__(): root = Tk() arduino_due = Arduino() root.bind('w', event_w) root.bind('a', event_a) root.bind('d', event_d) root.mainloop()
def test_analogin_get(): a = Arduino("Test Arduino") pin = AnalogIn(a, "Test Pin", "Test api", 0) pin.value = 500 assert pin.get() == 500
def __init__(self): self.board = Board() self.game_over = False self.opencv = OpenCV() self.turn = random.randint(player_piece, AI_piece) self.minmaxPlayer = MiniMaxPlayer() self.arduino = Arduino()
def __init__(self, *args): ManagedThread.__init__(self, *args) self.rotation = 0.0 self.arduino = Arduino() # config read from ~/.robovision/pymata.conf self.rotation, self.x, self.y = 0, 0, 0.2 self.state = None self.prev = None
def test_str(capsys): a = Arduino("Test Arduino") bar = Bargraph("Test Bargraph", "Test api", {"type": "green"}) bar.attach(a, 0) bar.set(24, 24) print str(bar) out, err = capsys.readouterr() assert out == "[GGGGGGGGGGGGGGGGGGGGGGGG]\n" bar.set(12, 24) print str(bar) out, err = capsys.readouterr() assert out == "[GGGGGGGGGGGG ]\n" bar.set(6, 24) print str(bar) out, err = capsys.readouterr() assert out == "[GGGGGG ]\n" bar.set(0, 24) print str(bar) out, err = capsys.readouterr() assert out == "[ ]\n" bar.set(0, 0) print str(bar) out, err = capsys.readouterr() assert out == "[ ]\n"
def __init__(self): wx.Frame.__init__(self, None, title=self.title, size=(650, 570)) if platform.system() == 'Windows': arduino_port = 'COM4' else: arduino_port = '/dev/ttyACM0' # Try Arduino try: self.arduino = Arduino(arduino_port, 115200) except: msg = wx.MessageDialog( self, 'Unable to connect to arduino. Check port or connection.', 'Error', wx.OK | wx.ICON_ERROR) msg.ShowModal() == wx.ID_YES msg.Destroy() self.create_main_panel() self.recording = False self.output_file = '' time.sleep(1) # Timer self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.on_timer, self.timer) self.rate = 500 self.timer.Start(self.rate)
def test_analogout_init(): a = Arduino("Test Arduino") pin = AnalogOut(a, "Test Pin", "Test api", 0) assert pin.name == "Test Pin" assert pin.api == "Test api" assert pin.arduino.name == "Test Arduino"
def test_digitalout_init(): a = Arduino("Test Arduino") pin = DigitalOut(a, "Test Pin", "Test api", 0) assert pin.name == "Test Pin" assert pin.api == "Test api" assert pin.arduino.name == "Test Arduino"
def __init__(self, *args, **kwargs): ManagedThread.__init__(self, *args) self.arduino = Arduino() # config read from ~/.robovision/pymata.conf self.state = Patrol(self) self.recognition = None self.closest_edges = [] self.safe_distance_to_goals = 1.4 self.config = config
def discover(self): print("Louis has started. Running cell discovery ...") arduino = Arduino() num_cells = arduino.discover() print(num_cells) cells = [Cell(i) for i in range(1, num_cells + 1)] print("Cell discovery completed. " + str(num_cells) + " cells found.") return arduino, cells
def test_set(): a = Arduino("Test Arduino") bar = Bargraph("Test Bargraph", "Test api") bar.attach(a, 0) bar.set(100, 100) assert bar.value == 100 assert bar.max == 100
def test_init(): a = Arduino("Test Arduino") mod = Mod(a, "Test Mod", "Test api", 0xA9, 0xAB, 0xAA) assert mod.name == "Test Mod" assert mod.api == "Test api" assert mod.mod.arduino.name == "Test Arduino" assert mod.indicator.arduino.name == "Test Arduino" assert mod.button.arduino.name == "Test Arduino"
def test_init(): a = Arduino("Test Arduino") sev = SevenSegment("Test SevenSegment", "Test api") assert sev.name == "Test SevenSegment" assert sev.api == "Test api" assert sev.arduino is None sev.attach(a, 0) assert sev.arduino is not None assert sev.arduino.name == "Test Arduino"
def test_init(): a = Arduino("Test Arduino") bar = Bargraph("Test Bargraph", "Test api") assert bar.name == "Test Bargraph" assert bar.api == "Test api" assert bar.arduino is None bar.attach(a, 0) assert bar.arduino is not None assert bar.arduino.name == "Test Arduino"
class StdOutListener(tweepy.StreamListener): a = Arduino(conf.arduini) def on_data(self, data): d = json.loads(data) #print d['user']['screen_name'] + " - " + d['text'] self.a.decode(d['text']) return True def on_error(self, status): print status
def getArduino(temperatura, presenca, luminosidade): a1 = Arduino() # Criação do objeto arduino a1.temperatura = temperatura a1.presenca = presenca a1.luminosidade = luminosidade dao = ArduinoDAO() dao.create(a1) output = "Temperatura: " + str(a1.temperatura) + ", " + "Presença: " + str(a1.presenca) + ", " + "Luminosidade: " + str(a1.luminosidade) return output
def __init__(self, arduino_device_path, pump_configs, flow_rate): self._arduino = Arduino(arduino_device_path) self._pump_configs = pump_configs self._flow_rate = flow_rate output_pins = [] for config in self._pump_configs: output_pins.append(config.get_enable_pin_number()) output_pins.append(config.get_forward_pin_number()) output_pins.append(config.get_reverse_pin_number()) self._arduino.output(output_pins)
def __init__(self, datapath): self.logger = getLogger('thinkleg') self.datapath = datapath self.change_event = Event() self.arduino = Arduino(path=self.datapath, fname='arduino') self.arduino.start() super().__init__() self.title('ThinkLegTaskApp') self.first = FirstFrame(self) self.first.grid(row=0, column=0) self.time_manager = TimeManager(self) self.logger.debug('ThinkLegApp is initialized.')
def init_arduino(): # Arduino process parent_pipe, child_pipe = Pipe() # Starts the process proc = Arduino(child_pipe) proc.start() queue = Queue() # Creates a new thread that will be listening the pipe nbpl = NBPL(parent_pipe, queue) nbpl.setDaemon(True) nbpl.start() return parent_pipe, queue
def __init__(self, com=None): """ :param com: 设备管理器中的com号。 """ self.board = Arduino(com) self.K1 = 22 self.K2 = 26 self.K3 = 30 self.K4 = 34 self.K_demo = 38 self.keys = [self.K1, self.K2, self.K3, self.K4, self.K_demo] self.board.output(self.keys) for key in self.keys: self.board.setLow(key) self.delay_time = 0.1 self.config = TimeConfig()
def __init__(self): threading.Thread.__init__(self) #self.pc = PC(tcp_ip="192.168.1.1") self.android = Android() self.arduino = Arduino() #self.pc.connect() self.android.connect() self.arduino.connect() time.sleep(1) self.interface = Interface(arduino=self.arduino, fakeRun=False, android=self.android)
def __init__(self, waypointFile=None): """Constructor for the boat object""" self.arduino = Arduino() self.gps = Gps() self.xbee = Xbee() self._waypointN = 0 self._waypointE = 0 self._waypointNumber = 0 self._waypointDist = 0 self._waypointHeading = 0 self._targetHeading = 0 self._targetDistance = 0 self.s = 0 self.c = 0 self.r = 250
def main(): from arduino import Arduino from tools import breakpoint a = Arduino("Test") j0 = Joy(a, "J0", "", 0xA0, 0xA1, 0xA2, 0xA3) j1 = Joy(a, "J0", "", 0xA4, 0xA5, 0xA6, 0xA7) import time while True: j0.update() j1.update() print str(j0) + "," + str(j1) time.sleep(1) breakpoint()
def __init__(self): wx.Frame.__init__(self, None, title=self.title, size=(650, 600)) # Try Arduino try: self.arduino = Arduino(115200) except: print 'unable to connect to arduino' self.create_main_panel() self.recording = False time.sleep(1) # Timer self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.on_timer, self.timer) self.rate = 500 self.timer.Start(self.rate)
def run(self): # Conectando com Arduino self.__controller = Arduino() if not self.__controller.is_open(): debug('Falha ao conectar com Arduino! Conecte Arduino ao computador.') else: debug('Arduino detectado') webinterface.inject_functions(self.change_key, self.change_and_measure_key, self.blow_drops, self.init_measures, self.save_measures) debug('Interface carregada') ips = webinterface.getServerIPs() print("IP disponível:") for ip in ips: print('\t{}'.format(ip)) webinterface.runserver() self.quit_program()
def main(): ard = Arduino() lowv = LowVoltage(max_voltage) lowv.turnChannelOn() lowv.setCurrent(0.1, 0.1) temp = TemperatureControl(ard, lowv, logger) temp.setTemperature(temp1, temp2) temp.controlThread.start() try: sleep(2) os.environ["GNUPLOT_FILE"] = log_fn subprocess.call(["gnuplot", "plot.gnu"]) except KeyboardInterrupt: pass finally: temp.stopControl()
def init(): global ARDUINO # Get likely arduino connection seq = re.compile(r'/dev/ttyACM[0-9]') ports = list(serial.tools.list_ports.comports()) if ports == []: PY_LOGGER.warning("No ports found") return False # exit if no connection for portString in ports: # If uno is found in string if 'ACM' in str(portString): # Find out com port and connect port = seq.match(str(portString)).group() ARDUINO = Arduino("nomad", port) PY_LOGGER.info("Connected to Arduino") print_info() return True PY_LOGGER.info("No Arduino found!") return False
def __init__(self, fname, nrepeat=10, ard_port='/dev/ttyACM0', pump_port='/dev/ttyUSB0'): self.__observers = [] # define an observer self.step = -1 # before execution self.conf_label = 'R' + 'CUCI' * nrepeat print(self.conf_label) self.n_session = 1 + nrepeat * 4 self.sessions = len(self.conf_label) # the number of steps self.__construct__() self.time_flag = pd.Series(np.zeros(self.n_session), index=list(self.conf_label)) ard_reset(ard_port) self.ard = Arduino(ard_port) self.ard.output([pin_LED, pin_Servo]) self.ard.setLow(pin_LED) # Initial self.fname = fname self.pump_init(pump_port)
def OnChangeSerialPort(self, event): # wxGlade: MainWindow.<event_handler> self.windowPrintLn('') self.windowPrintLn("Searching for available serial ports...") #scan for available ports. return a list of tuples (num, name) available = [] for i in range(256): try: s = serial.Serial(i) available.append((i, s.portstr)) s.close() # explicit close because of delayed GC in java except serial.SerialException: pass self.windowPrintLn("Found the following avilable ports:") for nu, na in available: self.windowPrintLn(na) dlg = wx.SingleChoiceDialog(self, "Select the correct serial port", 'Serial Port Selection', [na for nu, na in available], wx.CHOICEDLG_STYLE) if dlg.ShowModal() == wx.ID_OK: self.serialPort = dlg.GetStringSelection() self.windowPrintLn('Selected ' + self.serialPort) self.windowPrintLn("Attempting to connect to arduino over " + self.serialPort + ".....") try: self.arduino = Arduino(self.serialPort) self.arduino.output(self.arduinoPinMap) self.arduino.turnOff() self.windowPrintLn(str(self.arduino)) except serial.serialutil.SerialException: self.windowPrintLn("Failed to connect to port " + self.serialPort + "!") self.arduino = None except TimeoutException: self.windowPrintLn( "5 second timeout: Failed to communicate with arduino over " + self.serialPort) self.windowPrintLn( "Reset arduino and try again, or try different port.") self.arduino = None
def __init__(self): # Arduino setup self.arduino = Arduino() # Snake setup pygame.init() self.white = (255, 255, 255) self.yellow = (255, 255, 102) self.black = (0, 0, 0) self.red = (213, 50, 80) self.green = (0, 255, 0) self.blue = (50, 153, 213) self.screen_width = 600 self.screen_height = 400 self.screen = pygame.display.set_mode((self.screen_width, self.screen_height)) pygame.display.set_caption('Snake Game') self.clock = pygame.time.Clock() self.snake_block = 10 self.snake_speed = 10 self.direction = "UP" # UP, DOWN, RIGHT, LEFT self.current_action = "RIGHT" #RIGHT,LEFT currently happening self.actions = ["RIGHT", "LEFT"] #when blowing it turns right initially (left if opposite) #☺where self.game_over = False self.in_settings = False self.in_update_controls = False self.in_update_speed = False self.in_endgame_menu = False self.font = pygame.font.SysFont("bahnschrift", 25) self.score_font = pygame.font.SysFont("comicsansms", 35) # Settings self.button1 = Button("Speed: "+str(self.snake_speed), self.font, x=self.screen_width/2.2, y=self.screen_height/2, bg="navy") self.button2 = Button("Blow setting: Turn "+self.actions[0]+" (opposite for "+self.actions[1]+")", self.font, x=self.screen_width/1.85, y=self.screen_height/2, bg="navy")