thanks to everyone here I was able to complete the launch controller on time and my brother loves it XD.
I hope to ask everyone if anyone willing to help on the following project
it's nothing more than a gun that keeps track of the shots "fired" by lighting LED's one by one in fact it's close to the power mitt code
simple right?
To give a better understanding it's based off the Change State Detection code each press lights an led
I'm grateful for any and all help below is the code I have so far
// this constant won't change:
const int buttonPin = 14; // the pin that the pushbutton is attached to
const int ledPin1 = 2; // the pin that the LED is attached to
const int ledPin2 = 3; // the pin that the LED is attached to
const int ledPin3 = 4; // the pin that the LED is attached to
const int ledPin4 = 5; // the pin that the LED is attached to
boolean fired = true; // Boolean used to remember if the trigger has already been read.
int maxShots = 4; // You can fire 4 safe shots;
int myShots = 0; // You can fire 4 safe shots;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
senseFire();
}
void senseFire() {
digitalRead(buttonPin);
fired = true;
if (buttonPin == HIGH && fired == true) {
buttonPushCounter++;
Serial.println(buttonPushCounter, DEC);
Serial.println("Button Pressed");
Serial.println("Firing Shot:");
if (buttonPushCounter == 1 && true) {
digitalWrite(ledPin1, HIGH);
}
else {
digitalWrite(ledPin1, LOW && false);
}
if (buttonPushCounter == 2 && true) {
digitalWrite(ledPin2, HIGH);
}
else {
digitalWrite(ledPin2, LOW && false);
}
if (buttonPushCounter == 3 && true) {
digitalWrite(ledPin3, HIGH);
}
else {
digitalWrite(ledPin3, LOW && false);
}
if (buttonPushCounter == 4 && true) {
digitalWrite(ledPin4, HIGH);
}
else {
digitalWrite(ledPin4, LOW && false);
}
if (myShots >= maxShots) {
(buttonPushCounter == 0);
Serial.println("Out of ammo");
Serial.println("myShots");
}
}
else if (buttonPin == LOW && fired == false) {
Serial.println("Button Released");
}
// reset the fired variable
fired = false;
}