2 Star 2 Fork 0

[email protected]/clock8266

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dis.cpp 4.63 KB
一键复制 编辑 原始数据 按行查看 历史
[email protected] 提交于 2020-11-22 23:40 . 分离dis.hpp
#define FASTLED_ESP8266_D1_PIN_ORDER
#include <FastLED.h>
#include "./font.h"
#define NUM_LEDS 256
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
void disSetup(){
pinMode(DATA_PIN, OUTPUT);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
}
int INDEX_XY(char x,char y){
if(x<=8){
return 8*y+x-9;
}
if(x<=16){
return 8*y+x+47;
}
if(x<=24){
return 8*y+x+103;
}
return 8*y+x+159;
}
void printc(char x,char y,char n,unsigned long C){
unsigned char findex=5*n;
for(char i=0;i<5;i++){
unsigned char k=Fonts[findex+i];
for(char p=0;p<=7;p++){
if(k&(1<<p)){
leds[INDEX_XY(x+i,y+p)]=C;
}
}
}
}
void printNum2(char x,char y,char n,unsigned long C){
if(n<9){
printc(x,y,16,C);
printc(x+5,y,16 + n % 10,C);
}else if(n<99){
printc(x+5,y,16 + n % 10,C);
printc(x,y,16 + n / 10,C);
}
}
void printNum(char x,char y,char n,unsigned long C){
x--;
y--;
if(n==1){
leds[INDEX_XY(x+3,y+1)]=C;leds[INDEX_XY(x+3,y+2)]=C;leds[INDEX_XY(x+3,y+3)]=C;leds[INDEX_XY(x+3,y+4)]=C;leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==2){
leds[INDEX_XY(x+1,y+1)]=C;leds[INDEX_XY(x+2,y+1)]=C;leds[INDEX_XY(x+3,y+1)]=C;leds[INDEX_XY(x+3,y+2)]=C;leds[INDEX_XY(x+1,y+3)]=C;leds[INDEX_XY(x+2,y+3)]=C;leds[INDEX_XY(x+3,y+3)]=C;leds[INDEX_XY(x+1,y+4)]=C;leds[INDEX_XY(x+1,y+5)]=C;leds[INDEX_XY(x+2,y+5)]=C;leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==3){
leds[INDEX_XY(x+1,y+1)]=C;leds[INDEX_XY(x+2,y+1)]=C;leds[INDEX_XY(x+3,y+1)]=C;
leds[INDEX_XY(x+3,y+2)]=C;
leds[INDEX_XY(x+1,y+3)]=C;leds[INDEX_XY(x+2,y+3)]=C;
leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+1,y+5)]=C;leds[INDEX_XY(x+2,y+5)]=C;leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==4){
leds[INDEX_XY(x+1,y+1)]=C;leds[INDEX_XY(x+3,y+1)]=C;leds[INDEX_XY(x+1,y+2)]=C;leds[INDEX_XY(x+3,y+2)]=C;leds[INDEX_XY(x+1,y+3)]=C;
leds[INDEX_XY(x+2,y+3)]=C;leds[INDEX_XY(x+3,y+3)]=C;leds[INDEX_XY(x+3,y+4)]=C;leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==5){
leds[INDEX_XY(x+1,y+1)]=C;leds[INDEX_XY(x+2,y+1)]=C;leds[INDEX_XY(x+3,y+1)]=C;leds[INDEX_XY(x+1,y+2)]=C;leds[INDEX_XY(x+1,y+3)]=C;
leds[INDEX_XY(x+2,y+3)]=C;leds[INDEX_XY(x+3,y+3)]=C;leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+1,y+5)]=C;leds[INDEX_XY(x+2,y+5)]=C;//leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==6){
leds[INDEX_XY(x+1,y+1)]=C;
leds[INDEX_XY(x+2,y+1)]=C;
leds[INDEX_XY(x+3,y+1)]=C;
leds[INDEX_XY(x+1,y+2)]=C;
leds[INDEX_XY(x+1,y+3)]=C;
leds[INDEX_XY(x+2,y+3)]=C;
leds[INDEX_XY(x+3,y+3)]=C;
leds[INDEX_XY(x+1,y+4)]=C;
leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+1,y+5)]=C;
leds[INDEX_XY(x+2,y+5)]=C;
leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==7){
leds[INDEX_XY(x+1,y+1)]=C;
leds[INDEX_XY(x+2,y+1)]=C;
leds[INDEX_XY(x+3,y+1)]=C;
leds[INDEX_XY(x+3,y+2)]=C;
leds[INDEX_XY(x+3,y+3)]=C;
leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==8){
leds[INDEX_XY(x+1,y+1)]=C;
leds[INDEX_XY(x+2,y+1)]=C;
leds[INDEX_XY(x+3,y+1)]=C;
leds[INDEX_XY(x+1,y+2)]=C;
leds[INDEX_XY(x+3,y+2)]=C;
leds[INDEX_XY(x+1,y+3)]=C;
leds[INDEX_XY(x+2,y+3)]=C;
leds[INDEX_XY(x+3,y+3)]=C;
leds[INDEX_XY(x+1,y+4)]=C;
leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+1,y+5)]=C;
leds[INDEX_XY(x+2,y+5)]=C;
leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==9){
leds[INDEX_XY(x+1,y+1)]=C;
leds[INDEX_XY(x+2,y+1)]=C;
leds[INDEX_XY(x+3,y+1)]=C;
leds[INDEX_XY(x+1,y+2)]=C;
leds[INDEX_XY(x+3,y+2)]=C;
leds[INDEX_XY(x+1,y+3)]=C;
leds[INDEX_XY(x+2,y+3)]=C;
leds[INDEX_XY(x+3,y+3)]=C;
leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+3,y+5)]=C;
return;
}
if(n==0){
leds[INDEX_XY(x+1,y+1)]=C;
leds[INDEX_XY(x+2,y+1)]=C;
leds[INDEX_XY(x+3,y+1)]=C;
leds[INDEX_XY(x+1,y+2)]=C;
leds[INDEX_XY(x+3,y+2)]=C;
leds[INDEX_XY(x+1,y+3)]=C;
leds[INDEX_XY(x+3,y+3)]=C;
leds[INDEX_XY(x+1,y+4)]=C;
leds[INDEX_XY(x+3,y+4)]=C;
leds[INDEX_XY(x+1,y+5)]=C;
leds[INDEX_XY(x+2,y+5)]=C;
leds[INDEX_XY(x+3,y+5)]=C;
return;
}
}
void clearToColor(unsigned char r,unsigned char g,unsigned char b){
for(int i=0;i<NUM_LEDS;i++){
leds[i].red=r;
leds[i].green=g;
leds[i].blue=b;
}
}
void ledTest(){
static uint8_t v = 0;
int i=20;
while(true){
FastLED.showColor(CHSV(0, 255, v));
v+=i;
if(v>=240||v<=0){
i=20-i;
}
delay(10);
}
}
void refresh(){
FastLED.show();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/menghui/clock8266.git
[email protected]:menghui/clock8266.git
menghui
clock8266
clock8266
master

搜索帮助