@@ -17,8 +17,8 @@ void Screen_::setBrightness(uint8_t brightness, bool shouldStore)
1717 brightness_ = brightness;
1818
1919#ifndef ESP8266
20- // analogWrite disable the timer1 interrupt on esp8266
21- analogWrite (PIN_ENABLE, 255 - brightness );
20+ pinMode (PIN_ENABLE, OUTPUT);
21+ digitalWrite (PIN_ENABLE, LOW );
2222#endif
2323
2424#ifdef ENABLE_STORAGE
@@ -157,6 +157,10 @@ void Screen_::setup()
157157
158158 // TODO find proper unused pins for MISO and SS
159159#ifdef ESP8266
160+ // Initialize control pins
161+ pinMode (PIN_LATCH, OUTPUT);
162+ digitalWrite (PIN_LATCH, LOW);
163+
160164 SPI.pins (PIN_CLOCK, 12 , PIN_DATA, 15 ); // SCLK, MISO, MOSI, SS);
161165 SPI.begin ();
162166 SPI.beginTransaction (SPISettings (10000000 , MSBFIRST, SPI_MODE0));
@@ -167,7 +171,13 @@ void Screen_::setup()
167171#endif
168172
169173#ifdef ESP32
170- SPI.begin (PIN_CLOCK, 34 , PIN_DATA, 25 ); // SCLK, MISO, MOSI, SS
174+ // Initialize control pins
175+ pinMode (PIN_LATCH, OUTPUT);
176+ pinMode (PIN_ENABLE, OUTPUT);
177+ digitalWrite (PIN_LATCH, LOW);
178+ digitalWrite (PIN_ENABLE, LOW);
179+
180+ SPI.begin (PIN_CLOCK, -1 , PIN_DATA, -1 ); // SCLK, MISO, MOSI, SS (-1 for unused pins)
171181 SPI.beginTransaction (SPISettings (10000000 , MSBFIRST, SPI_MODE0));
172182
173183 hw_timer_t *Screen_timer = timerBegin (1000000 );
@@ -262,7 +272,8 @@ ICACHE_RAM_ATTR void Screen_::_render()
262272
263273 for (int idx = 0 ; idx < ROWS * COLS; idx++)
264274 {
265- bits[idx >> 3 ] |= (buf[positions[idx]] > counter ? 0x80 : 0 ) >> (idx & 7 );
275+ uint16_t scaledValue = ((uint16_t )buf[positions[idx]] * brightness_) / 255 ;
276+ bits[idx >> 3 ] |= (scaledValue > counter ? 0x80 : 0 ) >> (idx & 7 );
266277 }
267278
268279 counter += (256 / GRAY_LEVELS);
0 commit comments