so im trying to display ESE! on a 6x24 LED array but when I compile and verify it, I keep getting errors and don't know what the issue. i pasted the code below
Code:
#include <stdio.h> // some Arduino-specific libraries are pre-included. They can be picked from within the Library tab in Arduino IDE.
#define SERIAL_CLOCK 12 // shifts data into shift registers when pulsed (SRCLK)
#define LATCH_CLOCK 11 // releases shift register data to LED matrix when pulsed (RCLK)
#define SERIAL_DATA 10 // data line for the shift registers
#define DEMUX_A 7
#define DEMUX_B 8
#define DEMUX_C 9
//initalizes pin outputs
pinMode(SERIAL_CLOCK, OUTPUT);
pinMode(LATCH_CLOCK, OUTPUT);
pinMode(SERIAL_DATA, OUTPUT);
pinMode(DEMUX_A, OUTPUT);
pinMode(DEMUX_B, OUTPUT);
pinMode(DEMUX_C, OUTPUT);
//**All other preprocessor directives will be placed here
// The two scripting functions prototyped right here. Also hidden.
void setup();
void loop();
//**All other prototypes and global variables are added here
//this section is completely hidden in the back scene of Arduino C Scripting Environment
void main()
{
// declared variables in Arduino are pasted here
setup(); //calling setup function ONCE
while(1) //infinite while loop / PROGRAM LOOP
{
loop();
}
}
/*
- Function Name: start()
- Purpose: Initialization Sequence for Arduino Embedded Target
- Input(s): Variable Name Variable Type Purpose
No input
- Output: Return Type
no return type required
*/
#define BUF_LEN 200
#define STR_LEN 30 //this means I only can support up to 15 characters pre-drawn
char myLEDDisplayBuffer[6][BUF_LEN]; // this is my 6x120 LED array display buffer
// the first 6x6 section of this buffer will be filled by
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', } ,
{'1', '1', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', } ,
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', } ,
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', } ,
{'1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', } ,
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', }
char string[STR_LEN] = "ESE!"; // {'E', 'S', 'E', '!', '\0'}
char charE[6][6] = { {'1', '1', '1', '1', '1', '1'} ,
{'1', '1', '0', '0', '0', '0'} ,
{'1', '1', '1', '1', '1', '1'} ,
{'1', '1', '1', '1', '1', '1'} ,
{'1', '1', '0', '0', '0', '0'} ,
{'1', '1', '1', '1', '1', '1'}
};
char charS[6][6] = { {'1', '1', '1', '1', '1', '1'} ,
{'1', '1', '0', '0', '0', '0'} ,
{'1', '1', '1', '1', '1', '1'} ,
{'1', '1', '1', '1', '1', '1'} ,
{'0', '0', '0', '0', '1', '1'} ,
{'1', '1', '1', '1', '1', '1'}
};
char puncExcl[6][3] = { {'1', '1', '1'} ,
{'1', '1', '1'} ,
{'1', '1', '1'} ,
{'1', '1', '1'} ,
{'0', '0', '0'} ,
{'1', '1', '1'}
};
int windowPointer = 0;
#define ROLLING_DELAY 500;
int startTime = 0;
void assembleString()
{
// need an assmebly pointer
int pointer = 0;
for(int i = 0; i < STR_LEN; i++)
{
if(string[i] == 'E')
{
// load the E pattern using nested for-loop
for(int j = 0; j < 6; j++) // row
{
for(int k = 0; k < 6; k++) //col
{
myLEDDisplayBuffer[j][k + pointer] = charE[j][k];
}
}
// increase my pointer 6 + 1 unit
pointer += 7;
}
else if(string[i] == 'S')
{
// load the S pattern using nested for-loop
for(int j = 0; j < 6; j++) // row
{
for(int k = 0; k < 6; k++) //col
{
myLEDDisplayBuffer[j][k + pointer] = charS[j][k];
}
}
// increase my pointer 6 + 1 unit
pointer += 7;
}
else if(string[i] == '!')
{
// Load the ! pattern using nested for-loop
// increase my pointer 3 + 1 unit
}
}
}
void setup(); // function, ONLY RUN ONCE
{
// put your setup code here, to run once:
assembleString();
} // myOtherIndex will be destroyed....
/*
- Function Name: loop()
- Purpose: The Master Program Loop (Game Loop) Arduino Embedded Target, repeats forever
- Input(s): Variable Name Variable Type Purpose
No input
- Output: Return Type
no return type required
*/
void loop() //function
{
// put your main code here, to run repeatedly:
// the way to roll the display / move the sliding window (mask) is to add the "scanner offset"
// i.e. the windowPointer...
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', } ,
{'1', '1', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', } ,
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', } ,
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', } ,
{'1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', } ,
{'1', '1', '1', '1', '1', '1', '0', '1', '1', '1', '1', '1', '1', '0', }
// question... what would happen if windowPointer > 8 (e.g. 10)
// because windowPointer is constantly increased for every program iteration, at one point, windowPointer + col > BUF_LEN
// (col + windowPointer) % BUF_LEN (e.g. col: [0 .. 5], windowPointer: 10, BUF_LEN = 14)
// [10] % 14 = 10
// [11] % 14 = 11
// [12] % 14 = 12
// [13] % 14 = 13
// [14] % 14 = 0
// [15] % 14 = 1
// modulus with BUF_LEN on the col index will ensure that myLEDDisplayBuffer becomes a CIRCULAR BUFFER
// this part needs to be executed as fast as possible
for(int row = 0; row < 6; row++)
{
// 1. Send the corresponding ABC selection signals to the DEMUX to turn on the row indexed by the variable "row" in the for loop.
// 2. load all LED bits to the LED column shift register bank
for( int col = 0; col < 6; col++)
{
if( myLEDDisplayBuffer[row][ (col + windowPointer) % BUF_LEN ] == '0' )
digitalWrite(SERIAL_DATA, HIGH); // digital write HIGH to the Serial Data!
else
digitalWrite(SERIAL_DATA, LOW); // digital write LOW to the serial data.
digitalWrite(SERIAL_CLOCK, HIGH); // clock the shift register once!
digitalWrite(SERIAL_CLOCK, LOW);
}
digitalWrite(LATCH_CLOCK, HIGH);
digitalWrite(LATCH_CLOCK, LOW); //Latch the shift register.
}
// this statement needs to be conditionally executed at a slower time interval!
// We need a TIMER!
// delay(500); // this statement will block your loop from proceeding to the next iteration. BAD IDEA!!!
// Use a ASYNC / NON_BLOCKING timer method.
if( startTime == 0 )
{
startTime = millis(); // 5000
}
else
{
if( millis() - startTime > ROLLING_DELAY )
{
windowPointer++;
startTime = 0;
}
}
}