I2C OLED 加粗五角星绘制

本文介绍了如何在ESP8266 Nodemcu开发板上使用1.3寸SH1106 OLED屏幕,通过I2C接口进行控制,并展示了如何通过`OLED_DrawLine`函数绘制动态的五角星。从头文件导入到初始化、设置参数,直至实际的图形绘制步骤都有详细讲解。
摘要由CSDN通过智能技术生成

I2C OLED 加粗五角星绘制


  • 开发板esp8266 Nodemcu1.0
  • 1.3寸oled屏幕(保留0.96寸屏幕调用接口)
#include "SH1106Wire.h" //1.3寸用这个
//#include "SSD1306Wire.h"    //0.96寸用这个
#include "OLEDDisplayUi.h"

#if defined(ESP8266)    //OLED引脚定义
const int SDA_PIN = D2; //对应nodemcu接D5或者D1,,wemosD1mini的D2
const int SDC_PIN = D1; //对应nodemcu接D6或者D2,,wemosD1mini的D5
#else
const int SDA_PIN = D1; //对应nodemcu接D5或者D1
const int SCL = D2;     //对应nodemcu接D6或者D2
#endif

const int I2C_DISPLAY_ADDRESS = 0x3c;                      //I2c地址默认

SH1106Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN); // 1.3寸用这个
//SSD1306Wire     display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);   // 0.96寸用这个
 OLEDDisplayUi ui     ( &display );
 void OLED_DrawLine(int x1,int y1,int x2,int y2);
  void setup()   {
  Serial.begin(115200);
  randomSeed(analogRead(0));
  display.init();
  display.clear();
  display.display();
  //    display.flipScreenVertically(); //屏幕翻转
  // display.mirrorScreen();//使用分光棱镜显示需要用到此函数
  display.setContrast(240); //屏幕亮度
  delay(1000);
 ui.setTargetFPS(80);                   //刷新频率
  ui.disableAllIndicators();             //不显示页码小点。
 ui.enableAutoTransition();
  ui.setFrameAnimation(SLIDE_LEFT);           //切屏方向
  // ui.disableAutoTransition();
 ui.enableAutoTransition();
  ui.setAutoTransitionForwards();//设置自动过渡方向,
  
 // ui.setFrames(frames, numberOfFrames);       // 设置框架和显示屏幕内容数
  ui.setTimePerFrame(5000);                   //设置切换时间
  ui.setTimePerTransition(500);//设置转场大约所需要时间
  // ui.setOverlays(overlays, numberOfOverlays); //设置覆盖的画面数  
  ui.init();// UI负责初始化显示
  void loop()
{
OLED_DrawLine(63, 0, 86, 63);//五角星线条绘制
OLED_DrawLine( 63, 0,40, 64);
OLED_DrawLine( 25, 23,86, 63);
OLED_DrawLine(25, 23, 101, 23);
OLED_DrawLine( 101, 23,40, 64); 
delay(1200);
display.clear();
}
//路劲绘制过程函数
void OLED_DrawLine(int x1,int y1,int x2,int y2)
{
  unsigned int t; 
  int xerr=0,yerr=0,delta_x,delta_y,distance;
  int incx,incy,uRow,uCol;
  delta_x=x2-x1; //计算坐标增量 
  delta_y=y2-y1;
  uRow=x1;//画线起点坐标
  uCol=y1;
  if(delta_x>0)incx=1; //设置单步方向 
  else if (delta_x==0)incx=0;//垂直线 
  else {incx=-1;delta_x=-delta_x;}
  if(delta_y>0)incy=1;
  else if (delta_y==0)incy=0;//水平线 
  else {incy=-1;delta_y=-delta_x;}
  if(delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴 
  else distance=delta_y;
  for(t=0;t<distance+1;t++)
  {
    display.fillCircle(uRow ,uCol, 2);
 display.display(); delay(50); 
    xerr+=delta_x;
    yerr+=delta_y;
    if(xerr>distance)
    {
      xerr-=distance;
      uRow+=incx;
    }
    if(yerr>distance)
    {
      yerr-=distance;
      uCol+=incy;
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值