fix row flipping

This commit is contained in:
interfisch 2023-01-31 21:28:49 +01:00
parent f916bafb84
commit 387a02b37d
1 changed files with 91 additions and 33 deletions

View File

@ -40,6 +40,8 @@ void selectColumn(uint8_t selcolumn, bool clear);
bool HBridgeOK(); bool HBridgeOK();
void shiftData(); void shiftData();
void resetColumns();
unsigned long loopmillis=0; unsigned long loopmillis=0;
unsigned long last_update=0; unsigned long last_update=0;
#define UPDATE_INTERVAL 500 #define UPDATE_INTERVAL 500
@ -83,7 +85,7 @@ uint8_t col[7];
void loop() { void loop() {
loopmillis = millis(); loopmillis = millis();
digitalWrite(PIN_OE, LOW); //Active Low
static bool init=false; static bool init=false;
@ -150,34 +152,79 @@ void loop() {
//selectColumnClear(countz%25); //selectColumnClear(countz%25);
selectColumnSet((12+(countz/25))%25); //lower column number is on the left //cycle testing set dots
row=pow(2, countz%16); //low significant bits are lower rows (when connector at top)
Serial.print("Row="); Serial.print(row); Serial.print(" Col="); selectColumnSet(countz/16); //lower column number is on the left
for (uint8_t i=0;i<7;i++) { row=pow(2, (countz)%16);//low significant bits are lower rows (when connector at top)
Serial.print(","); Serial.print(col[i]);
bool run_setdots=true;
/*
switch(countz) {
case 0:
selectColumnSet(5);
row=pow(2, 3); //4. zeile von unten
break;
case 1:
selectColumnSet(5);
row=pow(2, 4); //5. zeile von unten
break;
case 2:
selectColumnSet(5);
row=pow(2, 5);
break;
case 3:
selectColumnSet(5);
row=pow(2, 8);
break;
case 4:
selectColumnSet(2);
row=pow(2, 1);
break;
default:
row=0;
resetColumns();
run_setdots=false;
} }
Serial.println(); */
//reset pin on ribbon cable high (12Vpullup/open), then low (via Transistor)
if (run_setdots)
shiftData(); {
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();
//reset pin on ribbon cable high (12Vpullup/open), then low (via Transistor)
shiftData();
setSelectedDot(); setSelectedDot();
/*if (!clearSelectedColumn()) { /*if (!clearSelectedColumn()) {
Serial.println("Error clearing column!"); Serial.println("Error clearing column!");
}else{
Serial.println("Cleared");
}*/
}else{ }else{
Serial.println("Cleared"); Serial.println("END");
}*/ }
@ -203,11 +250,11 @@ void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t v
else else
digitalWrite(dataPin, !!(val & (1 << (7 - i)))); digitalWrite(dataPin, !!(val & (1 << (7 - i))));
delayMicroseconds(100); delayMicroseconds(1000);
digitalWrite(clockPin, HIGH); digitalWrite(clockPin, HIGH);
delayMicroseconds(100); delayMicroseconds(1000);
digitalWrite(clockPin, LOW); digitalWrite(clockPin, LOW);
delayMicroseconds(100); delayMicroseconds(1000);
} }
} }
@ -222,9 +269,10 @@ void selectColumn(uint8_t selcolumn, bool clear) {
uint8_t sc_bit=3-(selcolumn%4); //each two shift registers control four columns uint8_t sc_bit=3-(selcolumn%4); //each two shift registers control four columns
uint8_t sc_byte=selcolumn/4; uint8_t sc_byte=selcolumn/4;
for (uint8_t i=0;i<7;i++) { /*for (uint8_t i=0;i<7;i++) {
col[i]=0; col[i]=0;
} }*/
resetColumns();
col[sc_byte]=pow(2, (sc_bit*2+clear)); // possible numbers for clear=false: 1,4,16,64 col[sc_byte]=pow(2, (sc_bit*2+clear)); // possible numbers for clear=false: 1,4,16,64
/* /*
@ -280,8 +328,10 @@ bool setSelectedDot() {
return 0; return 0;
} }
digitalWrite(PIN_OE, LOW); //Active Low
digitalWrite(PIN_DRIVE, HIGH); digitalWrite(PIN_DRIVE, HIGH);
delay(10); delay(10);
digitalWrite(PIN_OE, HIGH); //Active Low
digitalWrite(PIN_DRIVE, LOW); digitalWrite(PIN_DRIVE, LOW);
return 1; return 1;
} }
@ -301,15 +351,23 @@ bool HBridgeOK() {
} }
void shiftData() { //send out all data to shift registers void shiftData() { //send out all data to shift registers
//select Rows via shift registers on own controller board
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
digitalWrite(PIN_LATCH, HIGH);
delayMicroseconds(1000);
digitalWrite(PIN_LATCH, LOW);
//Select Columns via Shift registers //Select Columns via Shift registers
for (uint8_t i=0;i<7;i++) { for (uint8_t i=0;i<7;i++) {
shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, col[6-i]); shiftOutSlow(PIN_DATA_DRVBRD, PIN_CLK_DRVBRD, LSBFIRST, col[6-i]);
} }
}
//select Rows via shift registers on own controller board
shiftOutSlow(PIN_DATA, PIN_CLK, LSBFIRST, row%256); void resetColumns() {
shiftOutSlow(PIN_DATA, PIN_CLK, LSBFIRST, row/256); //LSBFIRST= LSB is QH, bit 8 is QA. for (uint8_t i=0;i<7;i++) {
digitalWrite(PIN_LATCH, HIGH); col[i]=0;
delayMicroseconds(100); }
digitalWrite(PIN_LATCH, LOW);
} }