完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#define F_CPU 1000000UL // 1 MHz
#include til/delay.h> #include #include #define Cali_temp 25 #define Cali_value 0x12E #define Melting_point 273 #define LED_port PORTB #define LED_ddr DDRB #define LED_pin 0 #define Ring_scale 5 /* #define Hysteresis_T_NtoH 40 #define Hysteresis_T_HtoN 35 */ #define Hysteresis_T_NtoH 38 #define Hysteresis_T_HtoN 33 #define Hysteresis_T_NtoC 5 #define Hysteresis_T_CtoN 10 ISR(ADC_vect){ } void send_led(unsigned char r,unsigned char g,unsigned char b){ for (unsigned char i=0;i<6;i++){ if (b&1){ LED_port|=(1< LED_port&=~(1< LED_ddr|=(1< } for (unsigned char i=0;i<6;i++){ if (g&1){ LED_port|=(1< LED_port&=~(1< LED_ddr|=(1< } for (unsigned char i=0;i<6;i++){ if (r&1){ LED_port|=(1< LED_port&=~(1< LED_ddr|=(1< } } void conv_phase_to_rgb(unsigned char* ptr, unsigned char phase){ unsigned char r_t=0,g_t=0,b_t=0; //0~41 R->G->B->R //42~49 BLACK->R //50~57 BLACK->G //58~65 BLACK->B if (phase<42){ //normal phase if (phase<=7){ r_t=7;g_t=phase; }else if(phase<=14){ r_t=14-phase;g_t=7; }else if(phase<=21){ g_t=7;b_t=phase-14; }else if(phase<=28){ g_t=28-phase;b_t=7; }else if(phase<=35){ b_t=7;r_t=phase-28; }else if(phase<42){ b_t=42-phase;r_t=7; } }else if(phase<66){ if (phase<50){ r_t=phase-42; }else if (phase<58){ g_t=phase-50; }else{ b_t=phase-58; } } ptr[0]=r_t; ptr[1]=g_t; ptr[2]=b_t; } void delay_display(unsigned char* ptr){ _delay_ms(100); for(unsigned char i=0;i<6;i++){ send_led(ptr[3*i],ptr[3*i+1],ptr[3*i+2]); } } unsigned char RGB_data; volatile unsigned int temp_in_Kelvin; int main(void){ unsigned char i,j,swap; unsigned char phase[6]={0,7,14,21,28,35}; unsigned char led_color[6*3]={0}; unsigned char status=0,last_status=0; unsigned char ring_position=3; MCUCR|=(1< MCUCR|=(1< asm("sleep"); cli(); MCUCR&=~(1< for (j=0;j<8;j++){ //Initialize fade in for(i=0;i<6;i++){ phase++; if (phase==42) phase=0; conv_phase_to_rgb(led_color+3*i, phase); } for(i=0;i<6*3;i++){ if (led_color>7-j){ led_color-=7-j; }else{ led_color=0; }; } delay_display(led_color); } while(1){ MCUCR|=(1< asm("sleep"); cli(); MCUCR&=~(1< asm("nop"); if (last_status==0){//0 Normal; 1 Cold; 2 Hot if (temp_in_Kelvin>Hysteresis_T_NtoH + Melting_point){ status=2; }else if (temp_in_Kelvin }else{ status=0; } }else if (last_status==2){ if (temp_in_Kelvin }else{ status=2; } }else if (last_status==1){ if (temp_in_Kelvin>Hysteresis_T_CtoN + Melting_point){ status=0; }else{ status=1; } } if (status==0){ //NOW NORMAL if (last_status==0){ for(i=0;i<6;i++){ phase++; if (phase==42) phase=0; conv_phase_to_rgb(led_color+3*i, phase); } delay_display(led_color); }else{ for (j=0;j<10;j++){//all fade out for (i=0;i<6*3;i++){ if (led_color>0) led_color--; if (led_color>0) led_color--; if (led_color>0) led_color--; } delay_display(led_color); } for (i=0;i<6*3;i++){ led_color=0; } for (j=0;j<8;j++){ //fade in for(i=0;i<6;i++){ phase++; if (phase==42) phase=0; conv_phase_to_rgb(led_color+3*i, phase); } for(i=0;i<6*3;i++){ if (led_color>7-j){ led_color-=7-j; }else{ led_color=0; }; } delay_display(led_color); } } }else if (status==1) { //NOW COLD if (last_status==1){ for(i=0;i<6;i++){ led_color[3*i+2]++; if (led_color[3*i+2]>5*Ring_scale+Ring_scale) led_color[3*i+2]=1; } delay_display(led_color); }else if (last_status==0){ for (j=0;j<7;j++){//all fade out for (i=0;i<6*3;i++){ if (led_color>0) led_color--; } delay_display(led_color); } for (j=0;j<5*Ring_scale+1;j++){//blue ring fade in for (i=0;i<6;i++){ if (i }else{ swap=i-ring_position; } if (led_color[i*3+2] delay_display(led_color); } } }else if (status==2) { //NOW HOT if (last_status==2){ for(i=0;i<6;i++){ led_color[3*i]++; if (led_color[3*i]>5*Ring_scale+Ring_scale) led_color[3*i]=1; } delay_display(led_color); }else if (last_status==0){ for (j=0;j<7;j++){//all fade out for (i=0;i<6*3;i++){ if (led_color>0) led_color--; } delay_display(led_color); } for (j=0;j<5*Ring_scale+1;j++){//red ring fade in for (i=0;i<6;i++){ if (i }else{ swap=i-ring_position; } if (led_color[i*3] delay_display(led_color); } } } last_status=status; } }
code.zip
(1.68 KB, 下载次数: 7
)
|
|
相关推荐
3个回答
|
|
编译错误如下:请指教
Build started 7.9.2012 at 09:25:06 avr-gcc.exe -I"D:Program FilesAtmelAVR Tools" -mmcu=attiny24 -Wall -gdwarf-2 -O0 -fsigned-char -MD -MP -MT 1234.o -MF dep/1234.o.d -c ../1234.c In file included from ../1234.c:2: d:/winavr-20071221/bin/../avr/include/util/delay.h:90:3: warning: #warning "Compiler optimizations disabled; functions from ../1234.c: In function 'send_led': ../1234.c:32: error: 'for' loop initial declaration used outside C99 mode ../1234.c:42: error: redefinition of 'i' ../1234.c:32: error: previous definition of 'i' was here ../1234.c:42: error: 'for' loop initial declaration used outside C99 mode ../1234.c:52: error: redefinition of 'i' ../1234.c:42: error: previous definition of 'i' was here ../1234.c:52: error: 'for' loop initial declaration used outside C99 mode ../1234.c: In function 'delay_display': ../1234.c:103: error: 'for' loop initial declaration used outside C99 mode make: *** [1234.o] Error 1 Build failed with 8 errors and 1 warnings... |
|
|
|
都是些常识性错误。重复定义,初始化错误,自己看英文提示进行改
|
|
|
|
已经改好了,多谢指教{:soso_e179:}
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
203 浏览 0 评论
761 浏览 0 评论
806 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
743 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1195 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11807 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 00:20 , Processed in 0.692819 second(s), Total 77, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号