please can someone help I have the following circuit finally using two shift registers and have freed up so many pins on my uno, thank you to all that have helped me. as I was saying the following circuit I have got working very nicely with 16 leds scrolling from both sides and meeting in the middle then delay on centre led and back to repeat. I want to only have the program one once with a pushbutton on the first press, then I will write a second different sequence for the second push of the button and then also a third sequence on pressing the push button three times then finally a fourth press to turn off. I just don't know how to add a pushbutton into the circuit can anyone help me please.
[code]
//DECLARING SOME VARIABLES
//Pin connected to ST_CP of 74HC595
int latchPin = 9;
//Pin connected to SH_CP of 74HC595
int clockPin = 10;
////Pin connected to DS of 74HC595
int dataPin = 8;
bool registerArray1 = LOW;
bool registerArray2 = LOW;
bool registerArray3 = LOW;
bool registerArray4 = LOW;
bool registerArray5 = LOW;
bool registerArray6 = LOW;
bool registerArray7 = LOW;
bool registerArray8 = LOW;
void setup() {
Serial.begin ( 115200 ); //Enable the Serial Monitor
Serial.println ( "Starting.." ); //Write someting
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
registerWrite(0,HIGH);// turn far right led on
registerWrite(15,HIGH);// Turn far left led on
delay(50); // wait 50 milliseconds
registerWrite(0,LOW);// Turn first set of leds off
registerWrite(15,LOW);
registerWrite(1, HIGH);// and repeat for LED 4 to 13
registerWrite(14, HIGH);
delay(50);
registerWrite(1, LOW);
registerWrite(14, LOW);
registerWrite(2, HIGH);
registerWrite(13, HIGH);
delay(50);
registerWrite(2, LOW);
registerWrite(13, LOW);
registerWrite(3, HIGH);
registerWrite(12,HIGH);
delay(50);
registerWrite(3, LOW);
registerWrite(12, LOW);
registerWrite(4, HIGH);
registerWrite(11, HIGH);
delay(50);
registerWrite(4, LOW);
registerWrite(11, LOW);
registerWrite(5, HIGH);
registerWrite(10, HIGH);
delay(50);
registerWrite(5, LOW);
registerWrite(10, LOW);
registerWrite(6, HIGH);
registerWrite(9, HIGH);// central led turn on and delay
delay(50);
registerWrite(6, LOW);
registerWrite(9, LOW);
registerWrite(7, HIGH);
registerWrite(8, HIGH);
delay(50);
registerWrite(7, LOW);
registerWrite(8, LOW); // turn central led off after delay
delay(50); // then delay off time
registerWrite(8, HIGH); // turn central led back on for phaser fire
delay(1000);// then hold on for set time as phaser fires
registerWrite(8,LOW); // then turn off central led
}
void registerWrite(int PIN, bool BOOL){
//Writer to the 8 bit register, PIN - Pin No, BOOL - Status HIGH or LOW
//Update the saved outputs bits
if (PIN == 1) {registerArray1 = BOOL;}
if (PIN == 2) {registerArray2 = BOOL;}
if (PIN == 3) {registerArray3 = BOOL;}
if (PIN == 4) {registerArray4 = BOOL;}
if (PIN == 5) {registerArray5 = BOOL;}
if (PIN == 6) {registerArray6 = BOOL;}
if (PIN == 7) {registerArray7 = BOOL;}
if (PIN == 8) {registerArray8 = BOOL;}
//Shift Register the statuses
//Starting with last array so that the first array gets to the first pin.
if (registerArray8 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray7 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray6 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray5 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray4 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray3 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray2 == HIGH) {shiftOn();} else {shiftOff();}
if (registerArray1 == HIGH) {shiftOn();} else {shiftOff();}
//Latch Outputs
//This will shift the statuses of to the pins
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
}
void shiftOn() {
//ON - Shift with the status ON
// Serial.println ( "Sent On" );
digitalWrite(dataPin, HIGH);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
// delay(10);
}
void shiftOff() {
//OFF - Shift with the status OFF
// Serial.println ( "Sent Off" );
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
// delay(10);
}
[/code]
