Este código funciona con la versión 0022 del IDE de Arduino!!
Arduino
/*
* WiiChuckDemo --
*
* 2008 Tod E. Kurt, http://thingm.com/
*
*/
#include <Wire.h>
#include "nunchuck_funcs.h"
int loop_cnt=0;
byte accx,accy,zbut,cbut;
int ledPin = 13;
void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake
Serial.print("WiiChuckDemo ready\n");
}
void loop()
{
if( loop_cnt > 100 ) { // every 100 msecs get new data
loop_cnt = 0;
nunchuck_get_data();
nunchuck_obtener_datos();
/*
accx = nunchuck_accelx(); // ranges from approx 70 - 182
accy = nunchuck_accely(); // ranges from approx 65 - 173
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton();
Serial.print("accx: "); Serial.print((byte)accx,DEC);
Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC);*/
}
loop_cnt++;
delay(1);
}
---------------------------------------------------------------------
.NET
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace WiiChuck
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void cmdComenzar_Click(object sender, EventArgs e)
{
SerialPort port = new SerialPort("COM7", 19200);
int n = 0; string t;
String[] v;
port.Open();
if (port.IsOpen)
{
while (true)
{
//port.Write("a");
t = port.ReadLine();
v = t.Split(',');
try
{
//String s = v[3];
//String[] v2 = s.Split(':');
//pic.Left = int.Parse(v2[1]);
pic.Left = int.Parse(v[1]) * 4;
//pic.Top = this.Height - int.Parse(v[2]) - 100;
if (v[6] == "but:1")
pic.BackColor = Color.Red;
else
pic.BackColor = Color.Blue;
}
catch (Exception ex)
{ }
txtDatos.Text = t;
System.Threading.Thread.Sleep(10);
Application.DoEvents();
}
}
}
}
}
No hay comentarios:
Publicar un comentario