ESP32 S3 ardino平台,配中景园7针0.96OLED屏显示小数
 OLED网上的驱动代码一般厂商发货会提供驱动程序,但是显示小数很多都没有编写。这里编写了一段可显示任意位小数的代码(以正点原子代码为基础),需要显示有符号的小数程序稍微修改即可。
 //显示小数数字
 //x,y :起点坐标
 //num :要显示的小数字
 //z_len :整数数字的位数
 //f_len :小数数字的位数
 //size:字体大小
 //mode:0,反色显示;1,正常显示
 //z_len为整数显示位数,f_len为小数显示位数,size1为字体大小
 //******************************************************
 void OLED_Showdecimal(u8 x,u8 y,float num,u8 z_len,u8 f_len,u8 size1,u8 mode)
 { 
 u8 t,temp;
 u8 enshow=0;
 int z_temp,f_temp;
 z_temp=(int)num;
 //整数部分
 for(t=0;t<z_len;t++)
 {
 //temp=(z_temp/OLED_Pow(10,z_len-t-1))%10;
 temp=(z_temp/oled_pow(10,z_len-t-1))%10;
 if(enshow0 && t<(z_len-1))
 {
 if(temp0)
 {
 //OLED_ShowChar(x+(size1/2)*t,y,’ ‘,size1,mode);
 OLED_ShowChar(x+(size1/2)*t,y,’ ‘,size1);
 continue;
 }
 else
 enshow=1;
 }
 //OLED_ShowChar(x+(size1/2)t,y,temp+‘0’,size1,mode);
 OLED_ShowChar(x+(size1/2)t,y,temp+‘0’,size1);
 }
 //小数点
 //OLED_ShowChar(x+(size1/2)(z_len),y,‘.’,size1,mode);
 OLED_ShowChar(x+(size1/2)(z_len),y,’.',size1);
//f_temp=(int)((num-z_temp)*(OLED_Pow(10,f_len)));
 
f_temp=(int)((num-z_temp)(oled_pow(10,f_len)));
 //小数部分
 for(t=0;t<f_len;t++)
 {
 //temp=(f_temp/OLED_Pow(10,f_len-t-1))%10;
 //OLED_ShowChar(x+(size1/2)(t+z_len)+5,y,temp+‘0’,size1,mode);
 temp=(f_temp/oled_pow(10,f_len-t-1))%10;
 OLED_ShowChar(x+(size1/2)*(t+z_len)+5,y,temp+‘0’,size1);
 }
 }
主程序部分
 void loop()
 {
 uint8_t t=’ ';
 OLED_Init();
 OLED_ColorTurn(0);//0正常显示 1反色显示
 OLED_DisplayTurn(0);//0正常显示 1翻转180度显示
 while(1)
 {
OLED_ShowString(0,6,"ASCII:",16);  
OLED_ShowString(0,4,"CODE:",16);
OLED_ShowChar(48,6,t,16);
t++;
vv++;
if(t>'~')t=' ';
if(vv>15.0)vv=0.11;
OLED_ShowNum(40,4,t,3,16);
OLED_Showdecimal(2,2,vv,3,3,16,1);
delay(500);
OLED_Clear();
 
}
 }
 效果看下
 
 


















