 volatile uint8_t may_flip = 0;
 int pwm_lengths[] = { 0x30, 0x10, 0x06 }; // PWM cycle lengths
 int pwm_i = 0; // Current PWM cycle
-uint8_t *buf_pwm = buf_a[0];
 
 // Hardware configuration
 uint8_t pin_col[] = {6, 7, A0, A1, A2, A3, A4, A5};

	
	// Set run length
	OCR1A = pwm_lengths[pwm_i];
	
	// Main screen turn off.
	digitalWrite(cur_pin, HIGH);
	digitalWrite(PIN_COL_LATCH, HIGH);

	// Switch the row on row driver if needed
	if (col_i == 0) {
		SPI.transfer(1 << row_i);

		// Latch it
		digitalWrite(PIN_ROW_LATCH, LOW);
		digitalWrite(PIN_ROW_LATCH, HIGH);
	}
	
	// Main screen turn on!
	cur_pin = pin_col[col_i];
	digitalWrite(cur_pin, LOW);
	TCNT1 = 0;
	
	// After turning on the screen, we have "plenty" of CPU cycles
	// to spend. Preparing a new segment to display.
	
	// Go to the next column. If reached the end of line, jump to next.
	col_i++;
	if (col_i > 7) {
		col_i = 0;
		row_i++;
		if (row_i > 6) {
			row_i = 0;
			pwm_i++;
			if (pwm_i >= ARRAY_SIZE(pwm_lengths)) {
				pwm_i = 0;
				if (may_flip) {
					buf_swap();
				}
			}
			// Switch to next PWM cycle
			buf_pwm = buf_front[pwm_i];
		}
	}


	
	// Send new data via SPI. Don't need to wait it to complete
	// because it completes before the next timer interrupt.
	SPDR = buf_front[pwm_i][8*row_i+col_i];
}
