找传奇、传世资源到传世资源站!

光照度计传感器

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

STM32_GY_39光照度计应用示例from clipboard#include <color.h>#include <delay.h>#include <oled.h>u8 Rgena,Ggena,Bgena;u16 Ramount,Gamount,Bamount;u16 amount;//float Max=0,Min=0;//float Rhsv=0,Ghsv=0,Bhsv=0;//float H=0,S=0,V=0;u8 R=0x00,G=0x00,B=0x00;//u16 RGB=0x0000;void Color_Init(void){GPIO_InitTypeDef GPIO_InitStruct;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_8|GPIO_Pin_9;GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStruct);GPIO_SetBits(GPIOB, GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_8|GPIO_Pin_9);}//*************外部中断线7***************/void EXTIX_Init(void){GPIO_InitTypeDef GPIO_InitStruct;EXTI_InitTypeDef EXTI_InitStruct;NVIC_InitTypeDef NVIC_InitStruct;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;GPIO_Init(GPIOB,&GPIO_InitStruct);GPIO_SetBits(GPIOB, GPIO_Pin_7);GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource7);EXTI_InitStruct.EXTI_Line = EXTI_Line7;EXTI_InitStruct.EXTI_LineCmd = ENABLE;EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;EXTI_Init(&EXTI_InitStruct);NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;NVIC_Init(&NVIC_InitStruct);}void EXTI9_5_IRQHandler(void){amount ;EXTI_ClearITPendingBit(EXTI_Line7);}/********************************************* 白平衡********************************************/void whitebalance(void){EXTI9_5_IRQHandler(); //外部中断初始化S2=0;S3=0;//红色通道amount=0; //开始计数delay_ms(10);Rgena = amount; //求出红色因子 amount=0;//----------------------------------S2=1;S3=1;//绿色通道amount=0;delay_ms(10);Ggena = amount; //求出绿色因子amount=0;//----------------------------------S2=0;S3=1;//蓝色通道amount=0;delay_ms(10);Bgena = amount; //求出蓝色因子amount=0;S2=1;S3=0;//关闭通道 }//********************************************//读取RGB值//********************************************u16 Color_RED(void){S2=0;S3=0;amount=0;delay_ms(10);Ramount=(u32) amount*255/Rgena; //取R值if(Ramount>255) Ramount = 255;return Ramount;//amount=0;}u16 Color_GREEN(void){S2=1;S3=1;amount=0;delay_ms(10);Gamount=(u32) amount*255/Ggena;//取G值if(Gamount>255) Gamount = 255;return Gamount;//amount=0;}u16 Color_BLUE(void){S2=0;S3=1;amount=0;delay_ms(10);Bamount=(u32) amount*255/Bgena;//去B值if(Bamount>255) Bamount = 255;return Bamount;//amount=0;} void Color_HSV(void){//=================================================================================R = Color_RED();G = Color_GREEN();//取RGB值B = Color_BLUE(); //================================================================================//Rhsv = (float) R/25/10;//Ghsv = (float) G/25/10; //RGB转换成0,1.//Bhsv = (float) B/25/10;////=================================================================================////RGB转HSV算法///********************************************************///Max = (Rhsv>Ghsv)?Rhsv:Ghsv;//Max = (Max>Bhsv)?Max:Bhsv;//取RGB最大值//Min = (Rhsv<Ghsv)?Rhsv:Ghsv;//Min = (Min<Bhsv)?Min:Bhsv;//去RGB最小值////if(Rhsv==Max) H = (Ghsv-Bhsv)/(Max-Min);//if(Ghsv==Max) H = 2 (Bhsv-Rhsv)/(Max-Min);//if(Bhsv==Max) H = 4 (Rhsv-Ghsv)/(Max-Min);//H =(int) (H*60); //if(H<0) H = H 360; // //V = (Rhsv>Ghsv)?Rhsv:Ghsv;//V = (V>Bhsv)?V:Bhsv;//取V的数值// //S = (Max-Min)/Max;//取S的数值// //V = (int) (V*100);//S = (int) (S*100); //======================================================================================================OLED_ShowNum(0,0,R,5,12); //显示一个数字OLED_ShowNum(0,12,G,5,12); //显示一个数字OLED_ShowNum(0,24,B,5,12); //显示一个数字//OLED_ShowNum(0,36,H,5,12); //显示一个数字//OLED_ShowNum(0,48,V,5,12); //显示一个数字//OLED_ShowNum(0,50,S,5,12); //显示一个数字delay_ms(50);}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复