Mini McQueens rig
Moderator: dromia
Forum rules
Should your post be in Grumpy Old Men? This area is for general shooting related posts only please.
Should your post be in Grumpy Old Men? This area is for general shooting related posts only please.
Re: Mini McQueens rig
You lot are clever!
Let me know when you have a production model!
Seriously.
Let me know when you have a production model!
Seriously.
Re: Mini McQueens rig
Cheers :-)
I'm planning a trip to B&Q so I can figure out what mechanical parts work best and are easily sourced.
I'll write the code to run the program today too, see how that goes
I'm planning a trip to B&Q so I can figure out what mechanical parts work best and are easily sourced.
I'll write the code to run the program today too, see how that goes
- bradaz11
- Full-Bore UK Supporter
- Posts: 4791
- Joined: Mon Jun 02, 2014 1:23 am
- Home club or Range: The tunnel at Charmouth, BWSS
- Location: Bristol
- Contact:
Re: Mini McQueens rig
look in b&q, buy in screwfix...
When guns are outlawed, only Outlaws will have guns
Re: Mini McQueens rig
Lol, usually Bradaz. B&Q sadly have a better selection of fixings, loathe as I am to pay their prices :-(
Re: Mini McQueens rig
Plenty quick enough.Demonic69 wrote:Do you think it's quick enough David? I was going to use the micro servo but it's really twitchy and seems to hold the interrupt open
Re: Mini McQueens rig
Right, bashed some code out and it seems to do what I want it to do. That's not saying it does what you lot want it to do 
Currently it's full of debugging info for me and not annotated particularly well but it does as follows:-
Waits for a button press on the remote.
Beeps for 2 seconds to let the shooter know the CoF is due to start.
Randomly generates a delay in milliseconds before the target is shown.
Randomly selects a number from 0-8 relating to the 9 targets.
Shows the target for 3 seconds and pulls it back.
Loops back around to generating a random delay, 10 times in total.
Beeps 3 times to let the shooter know he's done.
I could only think of using case statements to manage the servos as they have to be named as far as I can see. I tried using an array but it doesn't work as it fills the variable with the string but the write function only sees the variable name, not it's contents. It's the long way but it seems to work OK. Will shrink down once all the serial stuff is gone.
Code is at the bottom, below is what the serial output looks like:

Currently it's full of debugging info for me and not annotated particularly well but it does as follows:-
Waits for a button press on the remote.
Beeps for 2 seconds to let the shooter know the CoF is due to start.
Randomly generates a delay in milliseconds before the target is shown.
Randomly selects a number from 0-8 relating to the 9 targets.
Shows the target for 3 seconds and pulls it back.
Loops back around to generating a random delay, 10 times in total.
Beeps 3 times to let the shooter know he's done.
I could only think of using case statements to manage the servos as they have to be named as far as I can see. I tried using an array but it doesn't work as it fills the variable with the string but the write function only sees the variable name, not it's contents. It's the long way but it seems to work OK. Will shrink down once all the serial stuff is gone.
Code is at the bottom, below is what the serial output looks like:
- 20565
Received 86101 / 24bit Protocol: 1
A
//////////////////// Run Number 0
Servo: 7
Delay: 5249
Servo: 7 Out
Servo: 7 In
//////////////////// Run Number 1
Servo: 3
Delay: 3658
Servo: 3 Out
Servo: 3 In
//////////////////// Run Number 2
Servo: 0
Delay: 1272
Servo: 0 Out
Servo: 0 In
//////////////////// Run Number 3
Servo: 4
Delay: 878
Servo: 4 Out
Servo: 4 In
//////////////////// Run Number 4
Servo: 3
Delay: 7709
Servo: 3 Out
Servo: 3 In
//////////////////// Run Number 5
Servo: 0
Delay: 8165
Servo: 0 Out
Servo: 0 In
//////////////////// Run Number 6
Servo: 2
Delay: 3042
Servo: 2 Out
Servo: 2 In
//////////////////// Run Number 7
Servo: 7
Delay: 2503
Servo: 7 Out
Servo: 7 In
//////////////////// Run Number 8
Servo: 9
Delay: 8840
Servo: 9 Out
Servo: 9 In
//////////////////// Run Number 9
Servo: 2
Delay: 4303
Servo: 2 Out
Servo: 2 In
*********Done!********************
Code: Select all
/*
Trial of coding for Mini McQueens smallbore target rig
*/
#include <RCSwitch.h>
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
Servo myservo9;
//int pos = 0;// variable to store the servo position
int runs;
int flag;
int previousflag = flag;
int randommillis;
int MAX_RAND = 10; //Maximum random generated number
int showdelay = 3200; //How long each target shows for, adjust to suit
RCSwitch mySwitch = RCSwitch();
const int buzzerpin = 11;
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
pinMode(buzzerpin, OUTPUT);
myservo1.attach(8); // attaches the servo on pin 8 to the servo object
/*myservo2.attach(8);// greyed out until more servos attached
myservo3.attach(8);
myservo4.attach(8);
myservo5.attach(8);
myservo6.attach(8);
myservo7.attach(8);
myservo8.attach(8);
myservo9.attach(8);*/
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.println(value);
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
switch (value) {
case 20565:
Serial.println("A"); // Prints which button was selected from the remote. useful for further functions
mcqueens(); // runs the C0f
break;
case 20564:
Serial.println("B");
myservo1.write(180);
break;
case 5205:
Serial.println("C");
myservo1.write(90);
break;
case 5204:
Serial.println("D");
myservo1.write(90);
break;
}
}
mySwitch.resetAvailable();
}
}
void mcqueens(){
beep(2000); //Beep to let shooter know it's about to begin
for (runs = 0;runs < 10; runs++){
Serial.print("//////////////////// Run Number ");
Serial.println(runs);
do { // Random routine, stop same flag being shown twice in succession
flag = random(MAX_RAND);
} while (flag == previousflag);
previousflag = flag; //save the currently selected flag
//flag = random(9); // Normal random routine, same flag can be chosen twice in succession
Serial.print("Servo: "); //DEBUG print random number from 0 to MAX_RAND
Serial.println(flag);
randommillis = random(10000); // random milliseconds for delay between flags, up to 10 seconds
Serial.print("Delay: ");
Serial.println(randommillis);
delay(randommillis);
switch (flag) { // Switch/Case statements to cover all servos
case 0:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 1:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 2:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 3:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 4:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 5:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 6:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 7:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 8:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
case 9:
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" Out");
myservo1.write(1);
delay(showdelay);
myservo1.write(90);
Serial.print("Servo: ");
Serial.print(flag);
Serial.println(" In");
break;
}
}
beep(1000);
beep(1000);
beep(1000);
Serial.println("*************Done!********************");
}
void beep(int delayms){
analogWrite(buzzerpin, 100); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // How long to beep for
analogWrite(buzzerpin, 0); // 0 turns it off
delay(500);
}
Re: Mini McQueens rig
Strange that the array version didn't work. Did you try something like the code below?Demonic69 wrote:I could only think of using case statements to manage the servos as they have to be named as far as I can see.
Don't forget to seed the random number generator.
Note that your 'case' approach has 10 cases, and 10 possible random numbers, but it looks like you intended there to be 9. Each case currently calls the same servo.
Code: Select all
/*
Trial of coding for Mini McQueens smallbore target rig
*/
#include <RCSwitch.h>
#include <Servo.h>
#define NUM_SERVOS 9
//int pos = 0;// variable to store the servo position
int runs;
int flag;
int previousflag = flag;
int randommillis;
int showdelay = 3200; //How long each target shows for, adjust to suit
RCSwitch mySwitch = RCSwitch();
const int buzzerpin = 11;
Servo ServoArray[NUM_SERVOS];
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
pinMode(buzzerpin, OUTPUT);
int ServoPinArray[NUM_SERVOS] = { 8, 12, 13, 14, 15, 16, 17, 18, 19 }; // Servo pins
for (int ServoNum = 0; ServoNum < NUM_SERVOS; ServoNum++)
ServoArray[ServoNum].attach(ServoPinArray[ServoNum]);
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.println(value);
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
switch (value) {
case 20565:
Serial.println("A"); // Prints which button was selected from the remote. useful for further functions
mcqueens(); // runs the C0f
break;
case 20564:
Serial.println("B");
ServoArray[0].write(180);
break;
case 5205:
Serial.println("C");
ServoArray[0].write(90);
break;
case 5204:
Serial.println("D");
ServoArray[0].write(90);
break;
}
}
mySwitch.resetAvailable();
}
}
void mcqueens(){
beep(2000); //Beep to let shooter know it's about to begin
for (runs = 0;runs < 10; runs++){
Serial.print("//////////////////// Run Number ");
Serial.println(runs);
do { // Random routine, stop same flag being shown twice in succession
flag = random(NUM_SERVOS);
} while (flag == previousflag);
previousflag = flag; //save the currently selected flag
//flag = random(NUM_SERVOS); // Normal random routine, same flag can be chosen twice in succession
Serial.print("Servo: "); //DEBUG print random number from 0 to MAX_RAND
Serial.println(flag);
randommillis = random(10000); // random milliseconds for delay between flags, up to 10 seconds
Serial.print("Delay: ");
Serial.println(randommillis);
delay(randommillis);
ServoArray[flag].write(1);
delay(showdelay);
ServoArray[flag].write(90);
}
beep(1000);
beep(1000);
beep(1000);
Serial.println("*************Done!********************");
}
void beep(int delayms){
analogWrite(buzzerpin, 100); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // How long to beep for
analogWrite(buzzerpin, 0); // 0 turns it off
delay(500);
}
Re: Mini McQueens rig
I tried something similar but it didn't work, I had an array of variable names. I'll run through what you've put and see if that works better.rox wrote: Strange that the array version didn't work. Did you try something like the code below?
I had a look at seeding but it didn't make sense to me. Does it just stop repeats? We want repeats really.rox wrote: Don't forget to seed the random number generator.
I was aiming for 9 yes, I've probably left some dodgy code in while playing about with things.rox wrote: Note that your 'case' approach has 10 cases, and 10 possible random numbers, but it looks like you intended there to be 9.
That was intentionalrox wrote: Each case currently calls the same servo.

Thanks for the input, I'll let you know how I get on with the changes.
Who is online
Users browsing this forum: No registered users and 4 guests