working single column clear

This commit is contained in:
interfisch 2023-01-24 23:46:52 +01:00
parent d41228113d
commit 0438b4094a
1 changed files with 116 additions and 39 deletions

View File

@ -1,4 +1,5 @@
#include <Arduino.h> #include <Arduino.h>
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
/* /*
D7 - Ser (data) D7 - Ser (data)
@ -21,26 +22,35 @@ D3 - _clear
//#define PIN_CLEAR 25 //active low //#define PIN_CLEAR 25 //active low
#define PIN_DRIVE 33 //enables 12v to panels #define PIN_DRIVE 25 //enables 12v to panels via transistor
#define PIN_CLEAR 12 //connects CLEAR Pin from Annax board to GND (clears column)
#define NUMPANELS 1 #define NUMPANELS 1
//void sr_clear(); //void sr_clear();
void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
bool clearSelectedColumn();
bool setSelectedDot();
void selectColumnClear(uint8_t selcolumn);
void selectColumnSet(uint8_t selcolumn);
void selectColumn(uint8_t selcolumn, bool clear);
unsigned long loopmillis=0; unsigned long loopmillis=0;
unsigned long last_update=0; unsigned long last_update=0;
#define UPDATE_INTERVAL 5000 #define UPDATE_INTERVAL 3000
void setup() { void setup() {
pinMode(PIN_DATA, OUTPUT); pinMode(PIN_DATA, OUTPUT);
pinMode(PIN_CLK, OUTPUT); pinMode(PIN_CLK, OUTPUT);
pinMode(PIN_OE, OUTPUT); pinMode(PIN_OE, OUTPUT);
pinMode(PIN_LATCH, OUTPUT); pinMode(PIN_LATCH, OUTPUT);
//pinMode(PIN_CLEAR, OUTPUT); pinMode(PIN_CLEAR, OUTPUT);
pinMode(PIN_DRIVE, OUTPUT); pinMode(PIN_DRIVE, OUTPUT);
pinMode(PIN_DATA_DRVBRD, OUTPUT); pinMode(PIN_DATA_DRVBRD, OUTPUT);
pinMode(PIN_CLK_DRVBRD, OUTPUT); pinMode(PIN_CLK_DRVBRD, OUTPUT);
@ -55,15 +65,18 @@ void setup() {
int countz=0; int countz=0;
uint8_t rowA=0; //first shift register of own controller //uint8_t rowA=0; //first shift register of own controller
uint8_t rowB=0; //second shift register of own controller //uint8_t rowB=0; //second shift register of own controller
uint8_t colA=0; uint16_t row;
/*uint8_t colA=0;
uint8_t colB=0; uint8_t colB=0;
uint8_t colC=0; uint8_t colC=0;
uint8_t colD=0; uint8_t colD=0;
uint8_t colE=0; uint8_t colE=0;
uint8_t colF=0; uint8_t colF=0;
uint8_t colG=0; uint8_t colG=0;*/
uint8_t col[7];
void loop() { void loop() {
loopmillis = millis(); loopmillis = millis();
@ -77,7 +90,7 @@ void loop() {
{ {
Serial.print("count="); Serial.print("count=");
Serial.print(countz); Serial.print(countz);Serial.print(": ");
/* /*
Serial.println("High"); Serial.println("High");
@ -103,14 +116,8 @@ void loop() {
} }
*/ */
if (countz%2==0) {
colC=2+8+32+128;
colB=0;
}else{
//colA=64; //64=IL0
colC=0; //IH
colB=32+128;
}
//setting colX to 128, 32, 8,2 (or a combination of), then appling 12V to driver and GND to Clear, clears these colums //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 // this applies +12v to selected columns
@ -119,35 +126,50 @@ void loop() {
//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) //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)
selectColumnClear(countz%25);
//selectColumnSet(countz%25);
//row=pow(2, countz/25);
Serial.print(", rowA=");
Serial.print(rowA);
Serial.print(", colA=");
Serial.print(colA);
Serial.print("Row="); Serial.print(row); Serial.print(" Col=");
for (uint8_t i=0;i<7;i++) {
Serial.print(","); Serial.print(col[i]);
}
Serial.println(); Serial.println();
//reset pin on ribbon cable high (12Vpullup/open), then low (via Transistor) //reset pin on ribbon cable high (12Vpullup/open), then low (via Transistor)
//Select Columns via Shift registers //Select Columns via Shift registers
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colG); for (uint8_t i=0;i<7;i++) {
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colF); shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, col[6-i]);
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colE); }
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colD);
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colC);
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colB);
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, colA); //colA=128(bit 8) sets first output of shift registers high (lsbfirst)
//select Rows via shift registers on own controller board //select Rows via shift registers on own controller board
shiftOutSlow(PIN_DATA, PIN_CLK, LSBFIRST, rowB); shiftOutSlow(PIN_DATA, PIN_CLK, LSBFIRST, row%256);
shiftOutSlow(PIN_DATA, PIN_CLK, LSBFIRST, rowA); //LSBFIRST= LSB is QH, bit 8 is QA. shiftOutSlow(PIN_DATA, PIN_CLK, LSBFIRST, row/256); //LSBFIRST= LSB is QH, bit 8 is QA.
digitalWrite(PIN_LATCH, HIGH); digitalWrite(PIN_LATCH, HIGH);
delayMicroseconds(100); delayMicroseconds(100);
digitalWrite(PIN_LATCH, LOW); digitalWrite(PIN_LATCH, LOW);
//setSelectedDot();
if (!clearSelectedColumn()) {
Serial.println("Error clearing column!");
}else{
Serial.println("Cleared");
}
last_update=loopmillis; last_update=loopmillis;
countz++; countz++;
@ -157,13 +179,7 @@ void loop() {
} }
/* //
void sr_clear() {
digitalWrite(PIN_CLEAR, LOW);
delayMicroseconds(1000);
digitalWrite(PIN_CLEAR, HIGH);
delayMicroseconds(1000);
}*/
void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{ {
@ -182,3 +198,64 @@ void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t v
delayMicroseconds(100); delayMicroseconds(100);
} }
} }
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;
for (uint8_t i=0;i<7;i++) {
col[i]=0;
}
col[sc_byte]=pow(2, (sc_bit*2+clear));
}
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);
delay(200);
digitalWrite(PIN_CLEAR, LOW);
digitalWrite(PIN_DRIVE, LOW);
return 1;
}
bool setSelectedDot() {
for (uint8_t cc=0;cc<7;cc++) {
//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)
}
}
}
digitalWrite(PIN_DRIVE, HIGH);
delay(200);
digitalWrite(PIN_DRIVE, LOW);
return 1;
}