int main(int argc, char **argv) { float soil = 65.5; float temp = 5.5; // I2C change parameters to fit to your LCD if ( !display.init(OLED_I2C_RESET,OLED_ADAFRUIT_I2C_128x64) ) exit(EXIT_FAILURE); display.begin(); // init done display.clearDisplay(); // clears the screen and buffer // text display tests display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.print(" XBee Messung\n"); display.drawLine(0, 10, display.width()-1, 10, WHITE); display.setCursor(0,15); display.printf("Bodenfeuchte: %4.1f %%\n", soil); display.printf("Temperatur: %4.1f C\n\n\n", temp); if(soil > 50) { display.print("--> Feucht genug\n"); } else { display.print("--> Zu Trocken! \n"); } display.display(); // Free PI GPIO ports display.close(); }
void testdrawline() { for (int16_t i=0; i<display.width(); i+=4) { display.drawLine(0, 0, i, display.height()-1, WHITE); display.display(); } for (int16_t i=0; i<display.height(); i+=4) { display.drawLine(0, 0, display.width()-1, i, WHITE); display.display(); } delay(25); display.clearDisplay(); for (int16_t i=0; i<display.width(); i+=4) { display.drawLine(0, display.height()-1, i, 0, WHITE); display.display(); } for (int8_t i=display.height()-1; i>=0; i-=4) { display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); display.display(); } delay(25); display.clearDisplay(); for (int16_t i=display.width()-1; i>=0; i-=4) { display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); display.display(); } for (int16_t i=display.height()-1; i>=0; i-=4) { display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); display.display(); } delay(25); display.clearDisplay(); for (int16_t i=0; i<display.height(); i+=4) { display.drawLine(display.width()-1, 0, 0, i, WHITE); display.display(); } for (int16_t i=0; i<display.width(); i+=4) { display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE); display.display(); } delay(25); }
void Demos::CK_logo(Adafruit_SSD1306& d) { #define K 1024 // wave // scale ofs #define CX(x) { x = w-cx; x = ( (x*(K +ax*Cos(8*w +tt[0])/SY*Sin(7*w +tt[1])/SY) /K) +cx)/8 +6; } #define CY(y) { y = w-cy; y = ( (y*(K +ay*Cos(9*w+ x*73+tt[2])/SY*Sin(6*w+ x*52+tt[3])/SY) /K) +cy)/9 -1; } const uint tt[4] = {t*7,t*5,t*8,t*5}; for (int w2=0; w2<2; ++w2) { const int cx = cw[ckCur][w2], cy = cw[ckCur][2+w2], ax = cw[ckCur][4+w2], ay = cw[ckCur][6+w2]; int a=0,w, i=0,rst=1, x1=0,y1=0,x=0,y=0; do { w = w2 ? word2[a++] : word1[a++]; if (w<=0) { rst=1; i=0; } else if (rst) switch(i) { case 0: CX(x) ++i; break; case 1: CY(y) rst=0; i=0; break; } else switch(i) { case 0: x1=x; CX(x) ++i; break; case 1: y1=y; CY(y) i=2; break; } if (i==2) { i=0; d.drawLine(x1,y1, x,y, WHITE); } } while (w >= 0); } if (iInfo > 0) { d.setCursor(0,8); d.print("Cur "); d.println(ckCur); d.print("Spd "); d.println(ckSpeed); } t += ckSpeed; delay(6); }
/// Draw 3D void Demos::Hedrons(Adafruit_SSD1306& d) { if (hdtOn) { ++hdt; if (hdt >= hdtMax) { hdt = 0; ++hdCur; // next type if (hdCur >= hdA) hdCur = 0; } } const int u = hdCur; const float SC = SCa[u]; // scale float rx=0.f,ry=0.f,rz=0.f, s = SC, ss=1.f; switch (hdRot) //par rot speed { case 0: rx = t*0.0055f; ry = t*0.0065f; rz = t*0.0075f; break; case 1: rx = t*0.0061f; ry = t*0.0084f; rz = t*0.0077f; break; case 2: rx = t*0.0067f; ry = t*0.0098f; rz = t*0.0083f; ss = 1.0f - 0.4f * (abs(cos(t*0.0125f))); break; case 3: ry = t*0.0060f; rz = t*0.0020f; break; } const int NP = NPa[u], NE = NEa[u], NF = NFa[u]; const float* pp = ppA[u]; const uint8_t* ee = eeA[u], *ff = ffA[u]; const float ///par z pos screen scale fovy = 30.f, zz = 3.f, se = 2.f, fv = 1.f/tan(fovy*0.5f), // const cx = cos(rx), sx = sin(rx), cy = cos(ry), sy = sin(ry), cz = cos(rz), sz = sin(rz), mx[3][3] = {{1.f,0.f,0.f},{0.f,cx,-sx},{0.f,sx,cx}}, // rot x my[3][3] = {{cy,0.f,sy},{0.f,1.f,0.f},{-sy,0.f,cy}}, // y mz[3][3] = {{cz,-sz,0.f},{sz,cz,0.f},{0.f,0.f,1.f}}; // z // transform all points int16_t px[NP], py[NP]; int8_t c[NP]; int i, a; for (i=0,a=0; i < NP; ++i) { float x = pp[a++], y = pp[a++], z = pp[a++]; float v[3]; v[0] = mx[0][0]*x +mx[0][1]*y +mx[0][2]*z; // rotate v[1] = mx[1][0]*x +mx[1][1]*y +mx[1][2]*z; v[2] = mx[2][0]*x +mx[2][1]*y +mx[2][2]*z; x = v[0]; y = v[1]; z = v[2]; v[0] = my[0][0]*x +my[0][1]*y +my[0][2]*z; v[1] = my[1][0]*x +my[1][1]*y +my[1][2]*z; v[2] = my[2][0]*x +my[2][1]*y +my[2][2]*z; x = v[0]; y = v[1]; z = v[2]; v[0] = mz[0][0]*x +mz[0][1]*y +mz[0][2]*z; v[1] = mz[1][0]*x +mz[1][1]*y +mz[1][2]*z; v[2] = mz[2][0]*x +mz[2][1]*y +mz[2][2]*z; x = v[0] * s; y = v[1] * s; z = v[2] * s + ss*zz; px[i] = H/2 * se * (fv * x / -z) +W/2; // pos 3d to 2d py[i] = H/2 * se * (fv * y / -z) +H/2; c[i] = z < 0.9f ? -1 : (z < zz ? 1 : 0); if (px[i]<0 || px[i]>=W || py[i]<0 || py[i]>=H) c[i] = -1; // outside //c[i] = z < zz ? 1 : 0; //d.drawPixel(px[i], py[i],WHITE); } // draw far/covered edges -- for (i=0,a=0; i < NE; ++i) { int e0 = ee[a++], e1 = ee[a++]; int8_t cc = max(c[e0],c[e1]); if (cc==0) d.drawLine( px[e0],py[e0], px[e1],py[e1], WHITE); } // draw far faces /| if (ff) for (i=0,a=0; i < NF; ++i) { int f0 = ff[a++], f1 = ff[a++], f2 = ff[a++]; int8_t cc = min(c[f0],c[f1]); cc = min(cc,c[f2]); if (cc==0) d.fillTriangle( px[f0],py[f0], px[f1],py[f1], px[f2],py[f2], WHITE); } // dither 2 full screen -------- uint8_t* buf = d.getBuffer(); for (i=0; i < W*H/8; i+=2) buf[i] &= 0xAA; for (i=1; i < W*H/8; i+=2) buf[i] &= 0x55; // draw near/visible edges -- for (i=0,a=0; i < NE; ++i) { int e0 = ee[a++], e1 = ee[a++]; int8_t cc = max(c[e0],c[e1]); if (cc>0) d.drawLine( px[e0],py[e0], px[e1],py[e1], WHITE); } // draw near faces /| if (ff) for (i=0,a=0; i < NF; ++i) { int f0 = ff[a++], f1 = ff[a++], f2 = ff[a++]; int8_t cc = min(c[f0],c[f1]); cc = min(cc,c[f2]); if (cc>0) d.fillTriangle( px[f0],py[f0], px[f1],py[f1], px[f2],py[f2], WHITE); } if (iInfo > 0) { d.setCursor(0,8); d.print("Cur "); d.println(hdCur); d.print("Rot "); d.println(hdRot); if (hdtOn) d.println("On"); } ++t; delay(8); }