void st7565DrawChar(uint16_t x, uint16_t y, uint8_t c ) { uint8_t bpc, b; uint8_t bytesPerChar = ( (currentFont->Height-1) / 8 + 1 ); // calc how many bytes we need to read // Render each column uint16_t xoffset, yoffset; for (xoffset = 0; xoffset < currentFont->Width; xoffset++) { for (bpc = 0; bpc < bytesPerChar; bpc++) { b = pgm_read_byte(¤tFont->FontTable[((c - currentFont->FirstChar) * currentFont->Width * bytesPerChar) + (xoffset*bytesPerChar)+bytesPerChar-bpc-1]); // not super-happy with this, but it works.... for (yoffset = 0; yoffset < currentFont->Height; yoffset++) { if (yoffset/8 == bpc && CHECKBIT(b , yoffset%8)) { st7565DrawPixel(x + xoffset, y + yoffset); } } } } }
void st7565DrawLine( uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2 ) { int16_t dx, dy, stepx=1, stepy=1, fraction; dy = y2 - y1; dx = x2 - x1; if ( dy < 0 ) { dy = -dy; stepy = -1; } if ( dx < 0 ) { dx = -dx; stepx = -1; } dx <<= 1; dy <<= 1; st7565DrawPixel( x1, y1 ); if ( dx > dy ) { fraction = dy - (dx >> 1); while ( x1 != x2 ) { if ( fraction >= 0 ) { y1 += stepy; fraction -= dx; } x1 += stepx; fraction += dy; st7565DrawPixel( x1, y1 ); } } else {
int main() { int i, last_led_update = 0; initWiring(); st7565Init(Font5x7); st7565ClearScreen(); st7565SetBrightness(12); st7565DrawString(1, 5, "Test"); for(i = 0; i < 100; i++) { st7565DrawPixel(1+i,14); } st7565Refresh(); #if KKVER == 21 Fastwire::setup(100, true); MPU6050 mpu; mpu.initialize(); #endif DDRB &= _BV(LED_PIN); // Set pin 3 of port B to output (LED pin) for(;;) { char buff[512]; if(millis() - last_led_update > 1000) { PORTB ^= _BV(LED_PIN); last_led_update = millis(); } st7565ClearScreen(); #if KKVER == 21 if(mpu.testConnection()) { st7565DrawString(1,20, "Connected"); } else { st7565DrawString(1,20, "Not connected"); } sprintf(buff, "acc_x = %d\n", mpu.getAccelerationX()); st7565DrawString(1,30, buff); #else st7565DrawString(1,20, "No ACC available"); #endif st7565Refresh(); delay(50); } return 0; }