Wii chuck kontrollerad luft-soft kanontorn: D
Koden
#include
#include
/*
* WiiChuck torn--
*
* 2011 Luke Cudnik
*
*/
#include
#include "nunchuck_funcs.h"
int loop_cnt = 0;
Servo s1;
Servo s2.
byte accx, accy, zbut, CMen;
int ledPin = 13.
void setup()
{
pinMode (11, OUTPUT);
Serial.BEGIN(19200);
nunchuck_setpowerpins();
nunchuck_init(); Skicka initilization handslag
S1.attach(6);
S2.attach(8);
Serial.Print ("WiiChuckDemo ready\n");
}
void loop()
{
om (loop_cnt > 100) {/ / varje 100 uppdateringsförsök få nya data
loop_cnt = 0;
nunchuck_get_data();
accx = nunchuck_joyx(); varierar från ca 70-182
accy = nunchuck_joyy(); varierar från ca 65-173
zbut = nunchuck_zbutton();
CMen = nunchuck_cbutton();
int ax = map(accx,30,230,1,180);
int ay = map(accy,30,230,1,180);
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);
Serial.Print ("\ax:");
Serial.println((byte)AX,dec);
Serial.Print ("\ay:");
Serial.println((byte)AY,dec);
om (CMen == 1) {
S1.write(90);
S2.write(90);
}
om (CMen == 0) {
om ((ax<80) eller (ax > 100)) {
S1.write(AX);
}
annat {
S1.write(90);
}
}
om (CMen == 0) {
om ((ay<80) eller (ay > 100)) {
S2.write(AY);
}
annat {
S2.write(90);
}
}
}
om (zbut == 1) {
digitalWrite (11, hög).
}
om (zbut == 0) {
digitalWrite (11, låg).
}
loop_cnt ++;
Delay(1);
}