- Joined
- Nov 20, 2007
- Messages
- 11,970
- Reaction score
- 768
- Points
- 188
I'm doing a blog on this kit, mostly to get a handle on PID.
https://en.wikipedia.org/wiki/PID_controller.
I thought I would put code questions on the forum for a quicker response.
This is the code for the hand-controller.
Its only sending one byte for the two axis of the joystick? I'm guessing its doing something clever with the left shifts and "OR"ing the two axis?
Could someone talk me throght this please.
thanks, N.
https://en.wikipedia.org/wiki/PID_controller.
I thought I would put code questions on the forum for a quicker response.
This is the code for the hand-controller.
Code:
#include "SPI.h"
#include "Mirf.h"
#include "nRF24L01.h"
#include "MirfHardwareSpiDriver.h"
#include "Wire.h"
long Joystick_1_X;
long Joystick_1_Y;
long Joystick_2_X;
long Joystick_2_Y;
long Joystick_1;
long Joystick_2;
void setup(){
Serial.begin(115200);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setTADDR((byte *)"serv1");
Mirf.payload = sizeof(long);
Mirf.config();
}
void loop(){
Joystick_1_X = analogRead(A0);
Joystick_1_Y = analogRead(A1);
//Joystick_2_X = analogRead(A2);
//Joystick_2_Y = analogRead(A3);
//Serial.print("Joystick_1_X=");Serial.print(Joystick_1_X);
Serial.print(" Joystick_1_Y=");Serial.print(Joystick_1_Y);
Serial.print(" Joystick_2_X=");Serial.print(Joystick_2_X);
Serial.print(" Joystick_2_Y=");Serial.print(Joystick_2_Y);
Joystick_1_X = Joystick_1_X << 16;
Joystick_1 = Joystick_1_X | Joystick_1_Y;
//Serial.print(" Joystick_1_X=");Serial.print(Joystick_1_X);
Serial.print(" Joystick_1=");Serial.print(Joystick_1);
//Joystick_2_X = Joystick_2_X << 16;
//Joystick_2 = - (Joystick_2_X | Joystick_2_Y);
//Serial.print(" Joystick_2_X=");Serial.print(Joystick_2_X);
//Serial.print(" Joystick_2=");Serial.println(Joystick_2);
Mirf.send((byte *)&Joystick_1);
//delay(10);
//Mirf.send((byte *)&Joystick_2);
while(Mirf.isSending()){
}
}
Could someone talk me throght this please.
thanks, N.
