bag06a:
Still plan on sharing this with the world and not shutting me out when its done?
No, now I have it and it's mine! ] j/k
Of course! At the moment things are a mess, but you're more than welcome to have a look. I'm programming in the Atmel AVR studio, but things should transfer easily to Arduino if you choose. I'll paste the code at the end of this post.
bag06a:
...what are the things I'll need when I am able to program this on my own?
You will need an ISP, software that works with the ISP, some jumper wire, code (and/or binary file from me), and really steady hands. I bought an AVRISP mkII because I was concerned that I wouldn't get another ISP to work. On hand, I had a cheap USBasp ISP and an Arduino. I was able to get both the Arduino and the mkII to work. No luck with the generic USBasp.
I'll post better instructions once I build a proper forum for it. Perhaps I'll start a blog on it.
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
#define HIGH 1
#define LOW 0
int BALLS_PER_SECOND;
int ROUND_DELAY; // delay between shots in ms
int DEBOUNCE;Β // Debounce in ms
void initialize() {
BALLS_PER_SECOND = 30;
DEBOUNCE = 8;
ROUND_DELAY = (1000 - DEBOUNCE) / BALLS_PER_SECOND;
}
void delay_ms( int ms ){
for (int i = 0; i < ms; i++) {
_delay_ms(1);
}
}
int getPinMask(int pinNumber) {
if (pinNumber == 2) {
return (1 << 0);
} else if (pinNumber == 3) {
return (1 << 1);
} else if (pinNumber == 4) {
return (1 << 3);
} else if (pinNumber == 5) {
return (1 << 2);
} else if (pinNumber == 6) {
return (1 << 7);
} else if (pinNumber == 7) {
return (1 << 6);
} else if (pinNumber == 8) {
return (1 << 5);
} else if (pinNumber == 9) {
return (1 << 4);
} else if (pinNumber == 10) {
return (1 << 3);
} else if (pinNumber == 11) {
return (1 << 2);
} else if (pinNumber == 12) {
return (1 << 1);
} else if (pinNumber == 13) {
return (1 << 0);
}
return 0;
}
void setInputPin(int pinNumber) {
if (pinNumber >= 2 && pinNumber <= 5) {
DDRB &= ~(getPinMask(pinNumber));
} else if (pinNumber >=6 && pinNumber <= 13) {
DDRA &= ~(getPinMask(pinNumber));
}
}
void setOutputPin(int pinNumber) {
if (pinNumber >= 2 && pinNumber <= 5) {
DDRB |= (getPinMask(pinNumber));
} else if (pinNumber >= 6 && pinNumber <= 13) {
DDRA |= (getPinMask(pinNumber));
}
}
void pinOutput(int pinNumber, int state) {
if (pinNumber >= 2 && pinNumber <= 5) {
if (state == HIGH) {
PORTB |= (getPinMask(pinNumber));
} else {
PORTB &= ~(getPinMask(pinNumber));
}
} else if (pinNumber >= 6 && pinNumber <= 13) {
if (state == HIGH) {
PORTA |= (getPinMask(pinNumber));
} else {
PORTA &= ~(getPinMask(pinNumber));
}
}
}
int pinHasInput(int pinNumber) {
if (pinNumber >= 2 && pinNumber <= 5) {
return (PINB & (getPinMask(pinNumber))) <= 0;
} else if (pinNumber >= 6 && pinNumber <= 13) {
return (PINA & (getPinMask(pinNumber))) <= 0;
} else {
return 0;
}
}
void threeRoundBurst() {
for (int i = 0; i < 3; i++) {
pinOutput(6, HIGH);
delay_ms(DEBOUNCE);
pinOutput(6, LOW);
// don't delay on the last round
if (i < 2) {
delay_ms(ROUND_DELAY);
}
}
}
void fullAuto() {
while (pinHasInput(7)) {
pinOutput(6, HIGH);
delay_ms(DEBOUNCE);
pinOutput(6, LOW);
delay_ms(ROUND_DELAY);
}
}
int main (void) {
initialize();
setOutputPin(12);
setOutputPin(11);
setInputPin(7);
setInputPin(5);
setOutputPin(6);
setInputPin(3);
////////////////////////////////////
// Enable pull up on trigger inputs
////////////////////////////////////
// Trigger
pinOutput(5, HIGH);
pinOutput(7, HIGH);
pinOutput(3, HIGH);
pinOutput(13, HIGH);
pinOutput(10, HIGH);
pinOutput(9, LOW);
pinOutput(8, LOW);
pinOutput(12, LOW);
// turn on green LED
pinOutput(11, HIGH);
while(1) {
if (!pinHasInput(7)) {
delay_ms(DEBOUNCE);
while (!pinHasInput(7)) {
// NOOP
}
// Fire!
//threeRoundBurst();
fullAuto();
}
}
return 1;
}