Is this the place to post code? Who cares, here it is, respectfully stolen of the net and tweaked to suit my own fiendish desires, a lot of the old stuff is in there from the original code and lots of test code slashed out, man alive i cut corners! My coding is nearly as messy as my workshop :) It should compile on an arduino.
Here is the Transmitter code;
#include <Servo.h>
#include <JeeLib.h> //from jeelabs.org
#include <Wire.h>
//#include "nunchuck_funcs.h"
#define myNodeID 10 //node ID of tx (range 0-30)
#define network 210 //network group (can be in the range 1-250).
#define freq RF12_868MHZ //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module
byte byteRead;
typedef struct // create structure - a neat way of packaging data for RF comms
{
int jx, jy, acy, acx, zButton, cButton; // data from the controller. these have to match.
}
PayloadTX;
PayloadTX wiichuck;
byte accx,accy,zbut,cbut,joyx,joyy; // names of the nunchuck data
// constants won't change. They're used here to
// set pin numbers:
const int right = 4; // the number of the pushbutton pin
const int backward = 5;
const int forward = 6;
const int left = 7;
int p = 0;
int t = 0;
int r = 0;
int potpin0 = 5;
int potpin1 = 4;
int potpin2 = 3;
int val0;
int val1;
int val3;
//const int ledPin = 13; // the number of the LED pin
// variables will change:
//int buttonState = 0; // variable for reading the pushbutton status
int Right = 0;
int Backward = 0;
int Forward = 0;
int Left = 0;
//int cbut = 0;
void setup() {
// initialize the LED pin as an output:
// pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
rf12_initialize(myNodeID,freq,network);
Serial.begin(9600);
pinMode(right, INPUT);
pinMode(backward, INPUT);
pinMode(forward, INPUT);
pinMode(left, INPUT);
// accx = 90;
// accy = 90;
// zbut = 90;
//Stuff here for reading the three pots.
}
void loop(){
Serial.print(" 1pan ");
Serial.print(accx);
// Serial.print("\n");
Serial.print(" 1tilt ");
Serial.print(accy);
// Serial.print("\n");
Serial.print(" 1raise ");
Serial.print(zbut);
Serial.print("\n");
p = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)
accx = map(p, 0, 1023, 0, 179); //
t = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
accy = map(t, 0, 1023, 0, 179); //
r = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
zbut = map(r, 0, 1023, 0, 179); //
// read the state of the pushbutton value:
Right = digitalRead(right);
Backward = digitalRead(backward);
Forward = digitalRead(forward);
Left = digitalRead(left);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
//LEFT
//Serial.print(cbut);
//Serial.print("cbut val\n");
Serial.print(" pan ");
Serial.print(accx);
// Serial.print("\n");
Serial.print(" tilt ");
Serial.print(accy);
// Serial.print("\n");
Serial.print(" raise ");
Serial.print(zbut);
Serial.print("\n");
if (Left == HIGH) {
// turn LED on:
Serial.print("left\n");
cbut = 4;
//Serial.print(cbut);
//digitalWrite(ledPin, HIGH);
}
else if (Forward == HIGH) {
// turn LED on:
Serial.print("forward\n");
cbut = 1;
//Serial.print(cbut);
//digitalWrite(ledPin, HIGH);
}
//BACKWARD
else if (Backward == HIGH) {
// turn LED on:
Serial.print("Back\n");
cbut = 2;
//Serial.print(cbut);
//digitalWrite(ledPin, HIGH);
}
//BACKWARD
//RIGHT
else if (Right == HIGH) {
// turn LED on:
Serial.print("right\n");
cbut = 3;
//Serial.print(cbut);
//digitalWrite(ledPin, HIGH);
}
else {
cbut=0;
// turn LED off:
//Serial.print("right off\n");
//digitalWrite(ledPin, LOW);
}
//RIGHT
//cbut = 1;// nunchuck_cbutton();
//accx = 71; //nunchuck_accelx(); // ranges from approx 70 - 182
//accy = 65;// nunchuck_accely(); // ranges from approx 65 - 173
//zbut = 2;//nunchuck_zbutton();
joyx = 3...
Read more »