Thanks again.
I think I understand but I'm afraid that I am a bit out of my depth! This is my first Arduino project and my first attempt at programming since writing touch typing trainers and racer games on the C64! ![]()
Here's my attempt at code for what it's worth!
/*
tank controller try 1
License: CC-BY SA 3.0 - Creative commons share-alike 3.0
use this code however you'd like, just keep this license and
attribute. Let me know if you make hugely, awesome, great changes.
*/
#include <Servo.h>
#include <IRLib.h>
//Constant
//int RECV_PIN = 2;Â Â Â Â Â // IR Sensor not required, done through interrupt - but it is in pin 2
int led = 13;Â Â Â Â Â Â Â Â // Hit LED
//int hashAnswer = 84696349;Â // The hashed answer of recived IR signal (IRrecv)
int hashAnswer = 22621;Â Â Â // The hashed answer of recived IR signal (IRrecvPCI)
Servo myservoL;Â Â Â Â Â Â Â // Servo object for ServoL
Servo myservoR;Â Â Â Â Â Â Â // Servo object for ServoR
unsigned long interval=1000;Â // Time we need to turn on hit LED to signal we are hit
int n = 4;
//variables
IRsend My_Sender;Â Â Â Â Â Â //IR send object
unsigned int Signal[] = {
 3100,2800,5950}; //RAW outout code for IR
int i;Â Â Â Â Â Â Â Â Â Â Â Â // Counter for IR send loop
IRrecvPCI My_Receiver(0);Â Â //IR recieve function
IRdecode My_Decoder;Â Â Â Â Â //IR decode function
IRdecodeHash My_Hash_Decoder; //Decode hash function
int hashResult;Â Â Â Â Â Â Â //The result of the hashed IR recived value
int chL;Â Â Â Â Â Â Â Â Â Â Â // Here's where we'll keep our left channel values
int chR;Â Â Â Â Â Â Â Â Â Â Â // Here's where we'll keep our right channel values
int chF;Â Â Â Â Â Â Â Â Â Â Â // Channel value for fire
int hitcount;Â Â Â Â Â Â Â Â // variable to use to count hits
int slowstage1;Â Â Â Â Â Â Â // point at which we slow by 50%
int slowstage2;Â Â Â Â Â Â Â // point at which we slow by 75%
unsigned long waitUntil=interval; // millis() returns an unsigned long.
void setup() {
 pinMode(5, INPUT);      // Set our left servo input pins as such
 myservoL.attach(8);     // attaches the servo on pin 9 to the servo object
 pinMode(6, INPUT);      // Set our right servo input pins as such
 myservoR.attach(9);     // attaches the servo on pin 10 to the servo object
 pinMode(7, INPUT);      // set our fire channel to pin 7
 pinMode(led, OUTPUT);    //Set hit LED pin as output
 My_Receiver.enableIRIn();  // Start IR the receiver
 Serial.begin(9600);     // Pour a bowl of Serial
 hitcount = 0;        // initially set hitcount to 0
 slowstage1 = 1;       // number of hits to first slowstage
 slowstage2 = 5;       // number of hits to second slowstage
}
void loop() {
 chL = pulseIn(5, HIGH, 25000); // Read the pulse width of left Servo
 chR = pulseIn(6, HIGH, 25000); // Read the pulse width of Right servo
 chF = pulseIn(7, HIGH, 25000); // Read the pulse width of Fire servo
 if (hitcount >= slowstage1){
  chL = constrain(chL, 1250, 1530); //I got hit to slowstage 1. Axis contrained to 50%
  chR = constrain(chR, 1250, 1530);
 }
 if (hitcount >= slowstage2) {
  chL = constrain(chL, 1125, 1510); //I got hit to slowstage 2. Axis constrained to 25%
  chR = constrain(chR, 1125, 1510);
 }
 if (hitcount >=9) {
  chL = 1000;           // Set both servos to zero... because I'm dead
  chR = 1000;
  myservoL.write(chL);       // tell left servo to go to position in variable 'chL'
  myservoR.write(chR);       // tell right servo to go to position in variable 'chR' Â
  delay(15000);          // I'm dead! wait for 15 seconds to recover
  hitcount = 0;          // reset the hit counter to zero and get going!
 }
 // there two send the outputs to the servos.
 myservoL.write(chL);       // tell left servo to go to position in variable 'chL'
 myservoR.write(chR);       // tell right servo to go to position in variable 'chR'Â
 // 'Fire' routine.
 if (chF >= 1700) { // if fire is pressed.....:
  for (i = 0; i < n; i++) {
   My_Sender.IRsendRaw::send(Signal, sizeof(Signal)/sizeof(int), 38); //AnalysIR Batch Export - RAW
   delay (10);
  }
  My_Receiver.enableIRIn();   //make sure IR reciever stays on after doing fire routine
 }
 // Got hit routine.
 if (My_Receiver.GetResults(&My_Decoder)) {//Puts results in My_Decoder
  My_Hash_Decoder.copyBuf(&My_Decoder);//copy the results to the hash decoder
  My_Decoder.decode();
  My_Hash_Decoder.decode();
  hashResult = (My_Hash_Decoder.hash);
  if (hashResult == hashAnswer) {   //compare the result to known answer
   if ((unsigned long)(millis() - waitUntil) >= interval) {Â
    waitUntil =+ interval; // Increase our wait for 1000ms.
    digitalWrite(led, HIGH);
   }
   digitalWrite(led, LOW);
   hitcount ++;
   //Serial.println (hitcount);
  }
  //Serial.println (hashResult);
  My_Receiver.resume();
 }
}