Skip to content

Instantly share code, notes, and snippets.

View thekitchenscientist's full-sized avatar

thekitchenscientist

View GitHub Profile
@thekitchenscientist
thekitchenscientist / EV3CycleLEDs.py
Created August 20, 2015 19:14
Byte Codes to control EV3 LEDs by dirrect command
import time
LED_off = '\x08\x00\x00\x00\x80\x00\x00\x82\x1B\x00'
LED_green = '\x08\x00\x00\x00\x80\x00\x00\x82\x1B\x01'
LED_orange = '\x08\x00\x00\x00\x80\x00\x00\x82\x1B\x03'
LED_red = '\x08\x00\x00\x00\x80\x00\x00\x82\x1B\x02'
# send commands to EV3 via bluetooth
with open('/dev/rfcomm0', 'w', 0) as bt:
bt.write(LED_red)
@thekitchenscientist
thekitchenscientist / EV3Examples.py
Created August 20, 2015 18:19
Examples of commands that can be sent to the brick using DirectCommand. Requires library from https://github.com/inductivekickback/ev3
import ev3
import direct_command
"""
The first example creates an object called fwd to which we bind the class called direct command . We can then call the functions of the direct command using the magic dot. When you type fwd. on each line a list of the available functions appear (in Spyder) which you can scroll through and choose the correct one. Then when you type ( the object inspector tells you about the commands this function accepts.
"""
# move forward
fwd = direct_command.DirectCommand()
fwd.add_output_speed(direct_command.OutputPort.PORT_C,100)
@thekitchenscientist
thekitchenscientist / MainWindow.xaml.cs
Last active August 29, 2015 14:27
The basic C# code required to send commands to a LEGO EV3 on windows and receive sensor data. A copy of the dll from https://legoev3.codeplex.com/ is required.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 31 19:02:16 2015
@author: [email protected]
"""
import ev3
import direct_command
import time
@safe_add
def add_input_device_ready_raw3(self, input_port,
mode=-1,
device_type=0,
layer=USB_CHAIN_LAYER_MASTER):
"""Waits until the device on the specified InputPort is ready and then
returns its value as a raw value.
"""
self._msg.append(Opcode.INPUT_DEVICE)