From 7a5d35f3e1c7cfe1bc8e35faf0fbae76361eb812 Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 31 Jan 2023 21:50:48 +0100 Subject: [PATCH] clean up code --- flipcontrol_esp32/src/main.cpp | 161 ++++++--------------------------- 1 file changed, 29 insertions(+), 132 deletions(-) diff --git a/flipcontrol_esp32/src/main.cpp b/flipcontrol_esp32/src/main.cpp index cf48724..b2c99ca 100644 --- a/flipcontrol_esp32/src/main.cpp +++ b/flipcontrol_esp32/src/main.cpp @@ -28,7 +28,6 @@ D3 - _clear #define NUMPANELS 1 -//void sr_clear(); void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); bool clearSelectedColumn(); bool setSelectedDot(); @@ -44,7 +43,7 @@ void resetColumns(); unsigned long loopmillis=0; unsigned long last_update=0; -#define UPDATE_INTERVAL 500 +#define UPDATE_INTERVAL 10 void setup() { @@ -62,7 +61,7 @@ void setup() { digitalWrite(PIN_OE, HIGH); //Active Low digitalWrite(PIN_LATCH, LOW); - //sr_clear(); + digitalWrite(PIN_DRIVE, LOW); Serial.begin(115200); @@ -70,18 +69,9 @@ void setup() { int countz=0; -//uint8_t rowA=0; //first shift register of own controller -//uint8_t rowB=0; //second shift register of own controller -uint16_t row; -/*uint8_t colA=0; -uint8_t colB=0; -uint8_t colC=0; -uint8_t colD=0; -uint8_t colE=0; -uint8_t colF=0; -uint8_t colG=0;*/ +uint16_t row; //controls shift registers on own controller pcb -uint8_t col[7]; +uint8_t col[7]; //column drivers and shift registers on annax pcb void loop() { loopmillis = millis(); @@ -91,6 +81,7 @@ void loop() { static bool init=false; if (!init) { delay(2000); + row=0; Serial.println("Clearing Display"); for (int l=0;l<25;l++) { selectColumnClear(l%25); @@ -103,7 +94,7 @@ void loop() { Serial.println("Cleared"); } - delay(50); + delay(10); } init=true; delay(1000); @@ -116,33 +107,6 @@ void loop() { Serial.print("count="); Serial.print(countz);Serial.print(": "); - /* - Serial.println("High"); - digitalWrite(PIN_DATA, HIGH); - - delay(1000); - - Serial.println("Low"); - digitalWrite(PIN_DATA, LOW); - - delay(1000); - */ - - - /* - rowA=pow(2, (countz/2)%8); - - - if (countz%2==0) { - colA=0; - }else{ - colA=64; //64=IL0 - } - */ - - - - //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 @@ -150,96 +114,42 @@ 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) - //selectColumnClear(countz%25); - - //cycle testing set dots - - + //cycle testing set dots 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) - 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.print("Row="); Serial.print(row); Serial.print(" Col="); + for (uint8_t i=0;i<7;i++) { + Serial.print(","); Serial.print(col[i]); } - */ - - if (run_setdots) - { - - 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(); - - - - /*if (!clearSelectedColumn()) { - Serial.println("Error clearing column!"); - }else{ - Serial.println("Cleared"); - }*/ - }else{ - Serial.println("END"); - } - - + Serial.println(); + //reset pin on ribbon cable high (12Vpullup/open), then low (via Transistor) + shiftData(); - + setSelectedDot(); + + + last_update=loopmillis; countz++; + if (countz>=16*25) { + countz=0; + init=false; + } + } } -// +#define SHIFTDELAYMICROS 100 void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) { uint8_t i; @@ -250,11 +160,11 @@ void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t v else digitalWrite(dataPin, !!(val & (1 << (7 - i)))); - delayMicroseconds(1000); + delayMicroseconds(SHIFTDELAYMICROS); digitalWrite(clockPin, HIGH); - delayMicroseconds(1000); + delayMicroseconds(SHIFTDELAYMICROS); digitalWrite(clockPin, LOW); - delayMicroseconds(1000); + delayMicroseconds(SHIFTDELAYMICROS); } } @@ -269,22 +179,9 @@ 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; - }*/ resetColumns(); col[sc_byte]=pow(2, (sc_bit*2+clear)); // possible numbers for clear=false: 1,4,16,64 - /* - if (!clear) { //when setting a dot set all other columns to 12v (to avoid ghost flipping) - for (uint8_t i=0;i<7;i++) { - col[i]+=2+8+32+128; //set to +12v - } - col[sc_byte]-=pow(2, (sc_bit*2+1)); //avoid short circuit on H-bridge - } - */ - - } bool clearSelectedColumn() { @@ -313,7 +210,7 @@ bool clearSelectedColumn() { bool setSelectedDot() { - /*for (uint8_t cc=0;cc<7;cc++) { + 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)) { @@ -322,7 +219,7 @@ bool setSelectedDot() { return 0; //a column is set to ground (should not be set for clear column) } } - }*/ + } if (!HBridgeOK) { return 0; @@ -357,7 +254,7 @@ void shiftData() { //send out all data to shift registers 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); + delayMicroseconds(100); digitalWrite(PIN_LATCH, LOW); //Select Columns via Shift registers