Evening all,
A few years ago I 'programmed' a series of 'bit bashed' outputs to control 48 LED 'Cells' I soldered together.
A $h!t tonne of work, not only hardware to solder the LEDs, but to write the mother of all bit bashing below.
Now, you can see in my infinite wisdom, I ignored any notion of not using delay(). It's relied on heavily in this sketch. During loop as well as user defined functions. Deeming the sketch as a 'setup and play' light show.
SO... my question is, am I able to 'Find and Replace' all of my different delay() functions through all the user defined functions etc to bring this sketch in to something I can then interrupt and move between functions?
(User defined functions have been condensed as hit 9000 character limit in post)
// Setup for Time Variables
int Blink = 70;
int Pause = 500;
int Flash = 70;
int Add = 20;
int Snake = 200;
int on = 50;
int off = 50;
void setup() {
// put your setup code here, to run once:
// Error here could mean wrong board selected
DDRA |= B11111111; // Sets PA 7 - 0 as output (8)
DDRB |= B11111000; // Sets PB 7 - 3 as output (5)
DDRC |= B11111111; // Sets PC 7 - 0 as output (8)
DDRD |= B10001111; // Sets PD 3 - 0 as output (5)
DDRE |= B00111000; // Sets PE 5 - 3 as output (3)
DDRG |= B00100111; // Sets PG 5, 2, 1, 0 as output (4)
DDRH |= B01111011; // Sets PH 6, 5, 4, 3, 1, 0 as output (6)
DDRJ |= B00000011; // Sets PJ 1, 0 as output (2)
DDRL |= B11111111; // Sets PL 7 - 0 as output (8)
// DO NOT TOUCH PE0 or PE1 as used for serial data
}
void loop() {
// put your main code here, to run repeatedly:
AllOn();
delay(100);
AllOff();
delay(100);
for (int i = 0;i < 2; i ++){
Random(Flash);
}
RandomAddOn(Flash);
RandomAddOff(Flash);
for(int i = 0;i < 8; i ++){
MultiArrowLeftRight(80);
}
for(int i = 0;i < 8; i ++){
MultiArrowRightLeft(80);
}
for(int i = 0;i < 8; i ++){
ArrowOutIn(Blink);
ArrowInOut(Blink);
}
for(int i = 0;i < 10; i ++){
RightLeftAddOn(Add);
RightLeftAddOff(Add);
LeftRightAddOn(Add);
LeftRightAddOff(Add);
}
for(int i = 500; i > 10; i = i * 0.9){
HVOn();
delay(Blink);
HVOff();
delay(Blink);
}
for(int i = 500; i > 10; i = i * 0.9){
Checkers1On();
delay(i);
Checkers1Off();
delay(i);
Checkers2On();
delay(i);
Checkers2Off();
delay(i);
}
}
// Setting up user-defined Functions
void AllOn(){
PORTA |= B11111111;PORTB |= B11111000;PORTC |= B11111111;PORTD |= B10001111;PORTE |= B00111000;PORTG |= B00100111;PORTH |= B01111011;PORTJ |= B00000011;PORTL |= B11111111;
}
void AllOff(){
PORTA &= B00000000;PORTB &= B00000111;PORTC &= B00000000;PORTD &= B01110000;PORTE &= B11000111;PORTG &= B11011000;PORTH &= B10000100;PORTJ &= B11111100;PORTL &= B00000000;
}
// COLUMNS 1 - 16
void Column1On(){
PORTE |= B00010000;PORTH |= B01000010;
}
void Column1Off(){
PORTE &= B11101111;PORTH &= B10111101;
}
void Column2On(){
PORTE |= B00100000;PORTB |= B00010000;PORTH |= B00000001;
}
void Column2Off(){
PORTE &= B11011111;PORTB &= B11101111;PORTH &= B11111110;
}
void Column3On(){
PORTG |= B00100000;PORTB |= B00100000;PORTD |= B00001000;
}
void Column3Off(){
PORTG &= B11011111;PORTB &= B11011111;PORTD &= B11110111;
}
void Column4On(){
PORTE |= B00001000;PORTB |= B01000000;PORTD |= B00000100;
}
void Column4Off(){
PORTE &= B11110111;PORTB &= B10111111;PORTD &= B11111011;
}
void Column5On(){
PORTH |= B00001000;PORTB |= B10000000;PORTD |= B00000010;
}
void Column5Off(){
PORTH &= B11110111;PORTB &= B01111111;PORTD &= B11111101;
}
void Column6On(){
PORTH |= B00010000;PORTJ |= B00000010;PORTD |= B00000001;
}
void Column6Off(){
PORTH &= B11101111;PORTJ &= B11111101;PORTD &= B11111110;
}
void Column7On(){
PORTH |= B00100000;PORTJ |= B00000001;PORTA |= B00000001;
}
void Column7Off(){
PORTH &= B11011111;PORTJ &= B11111110;PORTA &= B11111110;
}
void Column8On(){
PORTA |= B00000010;PORTC |= B10000001;
}
void Column8Off(){
PORTA &= B11111101;PORTC &= B01111110;
}
void Column9On(){
PORTA |= B00000100;PORTC |= B01000000;PORTD |= B10000000;
}
void Column9Off(){
PORTA &= B11111011;PORTC &= B10111111;PORTD &= B01111111;
}
void Column10On(){
PORTA |= B00001000;PORTC |= B00100000;PORTG |= B00000100;
}
void Column10Off(){
PORTA &= B11110111;PORTC &= B11011111;PORTG &= B11111011;
}
void Column11On(){
PORTA |= B00010000;PORTC |= B00010000;PORTG |= B00000010;
}
void Column11Off(){
PORTA &= B11101111;PORTC &= B11101111;PORTG &= B11111101;
}
void Column12On(){
PORTA |= B00100000;PORTC |= B00001000;PORTG |= B00000001;
}
void Column12Off(){
PORTA &= B11011111;PORTC &= B11110111;PORTG &= B11111110;
}
void Column13On(){
PORTA |= B01000000;PORTC |= B00000100;PORTL |= B10000000;
}
void Column13Off(){
PORTA &= B10111111;PORTC &= B11111011;PORTL &= B01111111;
}
void Column14On(){
PORTC |= B00000010;PORTL |= B01000000;PORTA |= B10000000;
}
void Column14Off(){
PORTC &= B11111101;PORTL &= B10111111;PORTA &= B01111111;
}
void Column15On(){
PORTL |= B00111000;
}
void Column15Off(){
PORTL &= B11000111;
}
void Column16On(){
PORTL |= B00000111;
}
void Column16Off(){
PORTL &= B11111000;
}
void ColumnLeftRight(int on, int off){
Column1On();delay(on);Column1Off();delay(off);Column2On();delay(on);Column2Off();delay(off);Column3On();delay(on);Column3Off();delay(off);
Column4On();delay(on);Column4Off();delay(off);Column5On();delay(on);Column5Off();delay(off);Column6On();delay(on);Column6Off();delay(off);
Column7On();delay(on);Column7Off();delay(off);Column8On();delay(on);Column8Off();delay(off);Column9On();delay(on);Column9Off();delay(off);
Column10On();delay(on);Column10Off();delay(off);Column11On();delay(on);Column11Off();delay(off);Column12On();delay(on);Column12Off();delay(off);
Column13On();delay(on);Column13Off();delay(off);Column14On();delay(on);Column14Off();delay(off);Column15On();delay(on);Column15Off();delay(off);
Column16On();delay(on);Column16Off();delay(off);
}
void ColumnLeftRightInverse(int on, int off){
AllOn();
Column1Off();delay(off);Column1On();delay(on);Column2Off();delay(off);Column2On();delay(on);Column3Off();delay(off);Column3On();delay(on);
Column4Off();delay(off);Column4On();delay(on);Column5Off();delay(off);Column5On();delay(on);Column6Off();delay(off);Column6On();delay(on);
Column7Off();delay(off);Column7On();delay(on);Column8Off();delay(off);Column8On();delay(on);Column9Off();delay(off);Column9On();delay(on);
Column10Off();delay(off);Column10On();delay(on);Column11Off();delay(off);Column11On();delay(on);Column12Off();delay(off);Column12On();delay(on);
Column13Off();delay(off);Column13On();delay(on);Column14Off();delay(off);Column14On();delay(on);Column15Off();delay(off);Column15On();delay(on);
Column16Off();delay(off);Column16On();delay(on);
}
void ColumnLeftRightAddOn(int Blink){
Column1On();delay(Blink);Column2On();delay(Blink);Column3On();delay(Blink);
Column4On();delay(Blink);Column5On();delay(Blink);Column6On();delay(Blink);
Column7On();delay(Blink);Column8On();delay(Blink);Column9On();delay(Blink);
Column10On();delay(Blink);Column11On();delay(Blink);Column12On();delay(Blink);
Column13On();delay(Blink);Column14On();delay(Blink);Column15On();delay(Blink);
Column16On();delay(Blink);
}
void ColumnLeftRightAddOff(int Blink){
Column1Off();delay(Blink);Column2Off();delay(Blink);Column3Off();delay(Blink);
Column4Off();delay(Blink);Column5Off();delay(Blink);Column6Off();delay(Blink);
Column7Off();delay(Blink);Column8Off();delay(Blink);Column9Off();delay(Blink);
Column10Off();delay(Blink);Column11Off();delay(Blink);Column12Off();delay(Blink);
Column13Off();delay(Blink);Column14Off();delay(Blink);Column15Off();delay(Blink);
Column16Off();delay(Blink);
}
Your help is appreciated - please let there be a simple answer to replace all those delays ?!