Skip to content

Instantly share code, notes, and snippets.

@thekitchenscientist
Last active August 29, 2015 14:27
Show Gist options
  • Save thekitchenscientist/cc46b89080fe3e7de228 to your computer and use it in GitHub Desktop.
Save thekitchenscientist/cc46b89080fe3e7de228 to your computer and use it in GitHub Desktop.
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;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Lego.Ev3.Core;
using Lego.Ev3.Desktop;
using System.Diagnostics;
namespace LegoLogger
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Brick _brick;
public MainWindow()
{
InitializeComponent();
}
private async void Grid_Loaded(object sender, RoutedEventArgs e)
{
_brick = new Brick(new BluetoothCommunication("COM3"));
_brick.BrickChanged += _brick_BrickChanged;
await _brick.ConnectAsync();
await _brick.DirectCommand.PlayToneAsync(50, 1000, 300);
}
private void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
{
Debug.WriteLine(_brick.Ports[InputPort.One].SIValue);
Debug.WriteLine(_brick.Ports[InputPort.A].SIValue);
Debug.WriteLine(_brick.Ports[InputPort.B].SIValue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment