2023-01-22 21:47:03 +00:00
# include <Arduino.h>
2023-01-24 22:46:52 +00:00
# define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
2023-01-22 21:47:03 +00:00
/*
D7 - Ser ( data )
D5 - clock
D1 - _OE
D2 - latch
D3 - _clear
*/
//Pins connected to Shift registers on own controller board
# define PIN_DATA 13
# define PIN_CLK 14
# define PIN_OE 27 //active low
# define PIN_LATCH 26
//Pins connected to stuff on annax driver board
# define PIN_DATA_DRVBRD 33
# define PIN_CLK_DRVBRD 32
//#define PIN_CLEAR 25 //active low
2023-01-24 22:46:52 +00:00
# define PIN_DRIVE 25 //enables 12v to panels via transistor
# define PIN_CLEAR 12 //connects CLEAR Pin from Annax board to GND (clears column)
2023-01-22 21:47:03 +00:00
# define NUMPANELS 1
void shiftOutSlow ( uint8_t dataPin , uint8_t clockPin , uint8_t bitOrder , uint8_t val ) ;
2023-01-24 22:46:52 +00:00
bool clearSelectedColumn ( ) ;
bool setSelectedDot ( ) ;
void selectColumnClear ( uint8_t selcolumn ) ;
void selectColumnSet ( uint8_t selcolumn ) ;
void selectColumn ( uint8_t selcolumn , bool clear ) ;
2023-01-22 21:47:03 +00:00
2023-01-24 23:18:15 +00:00
bool HBridgeOK ( ) ;
void shiftData ( ) ;
2023-01-31 20:28:49 +00:00
void resetColumns ( ) ;
2023-01-22 21:47:03 +00:00
unsigned long loopmillis = 0 ;
unsigned long last_update = 0 ;
2023-01-31 20:50:48 +00:00
# define UPDATE_INTERVAL 10
2023-01-24 22:46:52 +00:00
2023-01-22 21:47:03 +00:00
void setup ( ) {
pinMode ( PIN_DATA , OUTPUT ) ;
pinMode ( PIN_CLK , OUTPUT ) ;
pinMode ( PIN_OE , OUTPUT ) ;
pinMode ( PIN_LATCH , OUTPUT ) ;
2023-01-24 22:46:52 +00:00
pinMode ( PIN_CLEAR , OUTPUT ) ;
2023-01-22 21:47:03 +00:00
pinMode ( PIN_DRIVE , OUTPUT ) ;
2023-01-24 22:46:52 +00:00
2023-01-22 21:47:03 +00:00
pinMode ( PIN_DATA_DRVBRD , OUTPUT ) ;
pinMode ( PIN_CLK_DRVBRD , OUTPUT ) ;
digitalWrite ( PIN_OE , HIGH ) ; //Active Low
digitalWrite ( PIN_LATCH , LOW ) ;
2023-01-31 20:50:48 +00:00
2023-01-22 21:47:03 +00:00
digitalWrite ( PIN_DRIVE , LOW ) ;
Serial . begin ( 115200 ) ;
}
int countz = 0 ;
2023-01-31 20:50:48 +00:00
uint16_t row ; //controls shift registers on own controller pcb
2023-01-24 22:46:52 +00:00
2023-01-31 20:50:48 +00:00
uint8_t col [ 7 ] ; //column drivers and shift registers on annax pcb
2023-01-22 21:47:03 +00:00
void loop ( ) {
loopmillis = millis ( ) ;
2023-01-31 20:28:49 +00:00
2023-01-22 21:47:03 +00:00
2023-01-24 23:18:15 +00:00
static bool init = false ;
if ( ! init ) {
delay ( 2000 ) ;
2023-01-31 20:50:48 +00:00
row = 0 ;
2023-01-24 23:18:15 +00:00
Serial . println ( " Clearing Display " ) ;
for ( int l = 0 ; l < 25 ; l + + ) {
selectColumnClear ( l % 25 ) ;
shiftData ( ) ;
if ( ! clearSelectedColumn ( ) ) {
Serial . println ( " Error clearing column! " ) ;
} else {
Serial . println ( " Cleared " ) ;
}
2023-01-31 20:50:48 +00:00
delay ( 10 ) ;
2023-01-24 23:18:15 +00:00
}
init = true ;
delay ( 1000 ) ;
}
2023-01-22 21:47:03 +00:00
if ( loopmillis > last_update + UPDATE_INTERVAL )
{
Serial . print ( " count= " ) ;
2023-01-24 22:46:52 +00:00
Serial . print ( countz ) ; Serial . print ( " : " ) ;
2023-01-22 21:47:03 +00:00
//setting colX to 128, 32, 8,2 (or a combination of), then appling 12V to driver and GND to Clear, clears these colums
// this applies +12v to selected columns
//setting colX to 64,16,4,1 (or a combination of), then setting row shift registers to some setting sets the selected dots
// this applies GND to selected columns
//reset pin on annax board input should be used (not pulled to gnd for a short time) after dots have been flipped (to disable potentially activated transistors)
2023-01-24 22:46:52 +00:00
2023-01-31 20:50:48 +00:00
//cycle testing set dots
2023-01-31 20:28:49 +00:00
selectColumnSet ( countz / 16 ) ; //lower column number is on the left
row = pow ( 2 , ( countz ) % 16 ) ; //low significant bits are lower rows (when connector at top)
2023-01-22 21:47:03 +00:00
2023-01-31 20:28:49 +00:00
2023-01-31 20:50:48 +00:00
Serial . print ( " Row= " ) ; Serial . print ( row ) ; Serial . print ( " Col= " ) ;
for ( uint8_t i = 0 ; i < 7 ; i + + ) {
Serial . print ( " , " ) ; Serial . print ( col [ i ] ) ;
2023-01-31 20:28:49 +00:00
}
2023-01-31 20:50:48 +00:00
Serial . println ( ) ;
//reset pin on ribbon cable high (12Vpullup/open), then low (via Transistor)
shiftData ( ) ;
2023-01-24 22:46:52 +00:00
2023-01-31 20:50:48 +00:00
setSelectedDot ( ) ;
2023-01-31 20:28:49 +00:00
2023-01-31 20:50:48 +00:00
2023-01-22 21:47:03 +00:00
last_update = loopmillis ;
countz + + ;
2023-01-31 20:50:48 +00:00
if ( countz > = 16 * 25 ) {
countz = 0 ;
init = false ;
}
2023-01-22 21:47:03 +00:00
}
}
2023-01-31 20:50:48 +00:00
# define SHIFTDELAYMICROS 100
2023-01-22 21:47:03 +00:00
void shiftOutSlow ( uint8_t dataPin , uint8_t clockPin , uint8_t bitOrder , uint8_t val )
{
uint8_t i ;
for ( i = 0 ; i < 8 ; i + + ) {
if ( bitOrder = = LSBFIRST )
digitalWrite ( dataPin , ! ! ( val & ( 1 < < i ) ) ) ;
else
digitalWrite ( dataPin , ! ! ( val & ( 1 < < ( 7 - i ) ) ) ) ;
2023-01-31 20:50:48 +00:00
delayMicroseconds ( SHIFTDELAYMICROS ) ;
2023-01-22 21:47:03 +00:00
digitalWrite ( clockPin , HIGH ) ;
2023-01-31 20:50:48 +00:00
delayMicroseconds ( SHIFTDELAYMICROS ) ;
2023-01-22 21:47:03 +00:00
digitalWrite ( clockPin , LOW ) ;
2023-01-31 20:50:48 +00:00
delayMicroseconds ( SHIFTDELAYMICROS ) ;
2023-01-22 21:47:03 +00:00
}
2023-01-24 22:46:52 +00:00
}
void selectColumnClear ( uint8_t selcolumn ) {
selectColumn ( selcolumn , true ) ;
}
void selectColumnSet ( uint8_t selcolumn ) {
selectColumn ( selcolumn , false ) ;
}
void selectColumn ( uint8_t selcolumn , bool clear ) {
uint8_t sc_bit = 3 - ( selcolumn % 4 ) ; //each two shift registers control four columns
uint8_t sc_byte = selcolumn / 4 ;
2023-01-31 20:28:49 +00:00
resetColumns ( ) ;
2023-01-24 22:46:52 +00:00
2023-01-24 23:18:15 +00:00
col [ sc_byte ] = pow ( 2 , ( sc_bit * 2 + clear ) ) ; // possible numbers for clear=false: 1,4,16,64
2023-01-24 22:46:52 +00:00
}
bool clearSelectedColumn ( ) {
//Clear Columns
if ( row ! = 0 ) {
return 0 ; //error. row is selected (short circuit!)
}
for ( uint8_t cc = 0 ; cc < 7 ; cc + + ) {
//Serial.print("checking cc="); Serial.println(cc);
for ( uint8_t i = 0 ; i < 8 ; i + = 2 ) {
if ( CHECK_BIT ( col [ cc ] , i ) ) {
Serial . print ( " Error on bit " ) ;
Serial . print ( i ) ; Serial . print ( " col= " ) ; Serial . println ( cc ) ;
return 0 ; //a column is set to ground (should not be set for clear column)
}
}
}
digitalWrite ( PIN_DRIVE , HIGH ) ;
digitalWrite ( PIN_CLEAR , HIGH ) ;
2023-01-24 23:18:15 +00:00
delay ( 50 ) ;
2023-01-24 22:46:52 +00:00
digitalWrite ( PIN_CLEAR , LOW ) ;
digitalWrite ( PIN_DRIVE , LOW ) ;
return 1 ;
}
bool setSelectedDot ( ) {
2023-01-31 20:50:48 +00:00
for ( uint8_t cc = 0 ; cc < 7 ; cc + + ) {
2023-01-24 22:46:52 +00:00
//Serial.print("checking cc="); Serial.println(cc);
for ( uint8_t i = 1 ; i < 8 ; i + = 2 ) {
if ( CHECK_BIT ( col [ cc ] , i ) ) {
Serial . print ( " Error on bit " ) ;
Serial . print ( i ) ; Serial . print ( " col= " ) ; Serial . println ( cc ) ;
return 0 ; //a column is set to ground (should not be set for clear column)
}
}
2023-01-31 20:50:48 +00:00
}
2023-01-24 23:18:15 +00:00
if ( ! HBridgeOK ) {
return 0 ;
2023-01-24 22:46:52 +00:00
}
2023-01-31 20:28:49 +00:00
digitalWrite ( PIN_OE , LOW ) ; //Active Low
2023-01-24 22:46:52 +00:00
digitalWrite ( PIN_DRIVE , HIGH ) ;
2023-01-24 23:18:15 +00:00
delay ( 10 ) ;
2023-01-31 20:28:49 +00:00
digitalWrite ( PIN_OE , HIGH ) ; //Active Low
2023-01-24 22:46:52 +00:00
digitalWrite ( PIN_DRIVE , LOW ) ;
return 1 ;
2023-01-24 23:18:15 +00:00
}
bool HBridgeOK ( ) {
for ( uint8_t cc = 0 ; cc < 7 ; cc + + ) {
//Serial.print("checking cc="); Serial.println(cc);
for ( uint8_t i = 0 ; i < 8 ; i + = 2 ) {
if ( CHECK_BIT ( col [ cc ] , i ) & & CHECK_BIT ( col [ cc ] , i + 1 ) ) {
Serial . print ( " Short circuit on bit " ) ;
Serial . print ( i ) ; Serial . print ( " col= " ) ; Serial . println ( cc ) ;
return 0 ; //a column is set to ground (should not be set for clear column)
}
}
}
return 1 ;
}
void shiftData ( ) { //send out all data to shift registers
2023-01-31 20:28:49 +00:00
2023-01-24 23:18:15 +00:00
//select Rows via shift registers on own controller board
2023-01-31 20:28:49 +00:00
shiftOutSlow ( PIN_DATA , PIN_CLK , LSBFIRST , row & 0xff ) ; //lower byte
shiftOutSlow ( PIN_DATA , PIN_CLK , LSBFIRST , row > > 8 ) ; //LSBFIRST= LSB is QH, bit 8 is QA. //upper byte
2023-01-24 23:18:15 +00:00
digitalWrite ( PIN_LATCH , HIGH ) ;
2023-01-31 20:50:48 +00:00
delayMicroseconds ( 100 ) ;
2023-01-24 23:18:15 +00:00
digitalWrite ( PIN_LATCH , LOW ) ;
2023-01-31 20:28:49 +00:00
//Select Columns via Shift registers
for ( uint8_t i = 0 ; i < 7 ; i + + ) {
shiftOutSlow ( PIN_DATA_DRVBRD , PIN_CLK_DRVBRD , LSBFIRST , col [ 6 - i ] ) ;
}
}
void resetColumns ( ) {
for ( uint8_t i = 0 ; i < 7 ; i + + ) {
col [ i ] = 0 ;
}
2023-01-22 21:47:03 +00:00
}