app上开关不稳定的问题
APP与ESP8266模块连接上以后有一个开关总是自动跳到开的那一端,把它关掉之后,还是会自动跳到开,而其他相似的开关并不会出现类似的情况。请问有没有人有出现过类似的情况啊?是如何解决的?附上部分程序:#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
#include "usart3.h"
#include "gizwits_product.h"
#include "adc.h"
#include "math.h"
#include "beep.h"
dataPoint_t currentDataPoint;
int maopi;
u8 wifi_sta=0,t=0;
unsigned long*p;
unsigned long Read_HX(void)//¶ÁHX711оƬÊä³öµÄÊý¾Ý¡£
{
unsigned long val = 0;
unsigned char i = 0;
GPIO_SetBits(GPIOB,GPIO_Pin_13); //DOUT=1
GPIO_ResetBits(GPIOB,GPIO_Pin_12); //SCK=0
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)); //µÈ´ýDOUT=0
delay_us(1);
for(i=0;i<24;i++)
{
GPIO_SetBits(GPIOB,GPIO_Pin_12); //SCK=1
val=val<<1;
delay_us(1);
GPIO_ResetBits(GPIOB,GPIO_Pin_12); //SCK=0
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)) //DOUT=1
val++;
delay_us(1);
}
GPIO_SetBits(GPIOB,GPIO_Pin_12);
val = val^0x800000;
delay_us(1);
GPIO_ResetBits(GPIOB,GPIO_Pin_12);
delay_us(1);
printf("µçѹ%d",val);
maopi=val;
return val;
}
unsigned long Read_HX711(void)//¶ÁHX711оƬÊä³öµÄÊý¾Ý¡£
{
unsigned long val = 0;
unsigned char i = 0;
GPIO_SetBits(GPIOB,GPIO_Pin_13); //DOUT=1
GPIO_ResetBits(GPIOB,GPIO_Pin_12); //SCK=0
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)); //µÈ´ýDOUT=0
delay_us(1);
for(i=0;i<24;i++)
{
GPIO_SetBits(GPIOB,GPIO_Pin_12); //SCK=1
val=val<<1;
delay_us(1);
GPIO_ResetBits(GPIOB,GPIO_Pin_12); //SCK=0
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)) //DOUT=1
val++;
delay_us(1);
}
GPIO_SetBits(GPIOB,GPIO_Pin_12);
val = val^0x800000;
delay_us(1);
GPIO_ResetBits(GPIOB,GPIO_Pin_12);
delay_us(1);
val=val-maopi;
val=abs(val);
val=val/400;
p=&val;
return val;
}
void Gizwits_Init(void)
{
TIM3_Int_Init(9,7199);//1MSϵͳ¶¨Ê±
usart3_init(9600);//WIFI³õʼ»¯
memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));//É豸״̬½á¹¹Ìå³õʼ»¯
gizwitsInit();//»º³åÇø³õʼ»¯
}
/*void userHandle(void)
{
//Åжϵ±Ç°LED1¿ª¹ØÁ¿
if(LED2==0)
currentDataPoint. valuekey1 = 1;
else
currentDataPoint. valuekey1 = 0;
}
*/
int main(void)
{ int sum;
int aver;
int i,c;
u16 a5;
int xin;
u16 a6,a7,a4;
int key;
delay_init(168); //³õʼ»¯ÑÓʱº¯Êý
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //ÉèÖÃNVICÖжϷÖ×é2:2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶
uart_init(115200); //´®¿Ú³õʼ»¯Îª115200
LED_Init(); //LED¶Ë¿Ú³õʼ»¯
KEY_Init();
TIM3_Int_Init(4999,7199);//10KhzµÄ¼ÆÊýƵÂÊ£¬¼ÆÊýµ½5000Ϊ500ms
Gizwits_Init(); //ÐÒé³õʼ»¯
printf("--------»úÖÇÔƲâÊÔʵÑé----------\r\n");
printf("KEY1:AirLinkÁ¬½Óģʽ\t KEY_UP:¸´Î»\r\n\r\n");
Adc_Init();
//userHandle();//Óû§²É¼¯
gizwitsHandle((dataPoint_t *)¤tDataPoint); //ÐÒé´¦Àí
Read_HX();//¶ÁHX711оƬÊä³öµÄÊý¾Ý
while(1)
{
//userHandle();//Óû§²É¼¯
gizwitsHandle((dataPoint_t *)¤tDataPoint); //ÐÒé´¦Àí
key = KEY_Scan(0);
if(key==KEY1_PRES)//KEY1°´¼ü
{
printf("WIFI½øÈëAirLinkÁ¬½Óģʽ\r\n");
gizwitsSetMode(WIFI_AIRLINK_MODE);//Air-linkģʽ½ÓÈë
}
if(key==WKUP_PRES)//KEY_UP°´¼ü
{
printf("WIFI¸´Î»£¬ÇëÖØÐÂÅäÖÃÁ¬½Ó\r\n");
gizwitsSetMode(WIFI_RESET_MODE);//WIFI¸´Î»
}
delay_ms(200);
Read_HX711() ;
printf("whileÀïµÄvalÖµ %d \n",*p);
if(*p>100)
{
Read_HX711() ;
if(*p<50)
{
LED2=0;
LED3=0;
LED9=0;
LED10=0;
}
}
if(LED2==1)
{
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a4=Get_Adc_Average(ADC_CH4,20);
sum=sum+a4;
}
aver=sum/10;
printf("µÚһ·ƽ¾ùÖµ %d\n",aver);
if(aver<3010)
{ delay_ms(3000);
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a4=Get_Adc_Average(ADC_CH4,20);
sum=sum+a4;
}
aver=sum/10;
if(aver<3010)
{ printf("¹Ø±Õ¼ÌµçÆ÷Ç°µÄ¾ùÖµ %d\n",aver);
LED2=0;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
}
}
}
if(LED3==1)
{
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a5=Get_Adc_Average(ADC_CH5,20);
sum=sum+a5;
}
aver=sum/10;
printf("µÚ¶þ·ƽ¾ùÖµ %d\n",aver);
if(aver<3025)
{ delay_ms(3000);
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a5=Get_Adc_Average(ADC_CH5,20);
sum=sum+a5;
}
aver=sum/10;
if(aver<3025)
{ printf("¹Ø±Õ¼ÌµçÆ÷Ç°µÄ¾ùÖµ %d\n",aver);
LED3=0;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
}
}
}
if(LED9==1)
{
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a6=Get_Adc_Average(ADC_CH6,20);
sum=sum+a6;
}
aver=sum/10;
printf("µÚÈý·ƽ¾ùÖµ %d\n",aver);
if(aver<3005)
{ delay_ms(3000);
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a6=Get_Adc_Average(ADC_CH6,20);
sum=sum+a6;
}
aver=sum/10;
if(aver<3005)
{ printf("¹Ø±Õ¼ÌµçÆ÷Ç°µÄ¾ùÖµ %d\n",aver);
LED9=0;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
}
}
}
if(LED10==1)
{
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a7=Get_Adc_Average(ADC_CH7,20);
sum=sum+a7;
}
aver=sum/10;
printf("µÚËÄ·ƽ¾ùÖµ %d\n",aver);
if(aver<3023)
{ delay_ms(3000);
sum=0;
aver=0;
for(i=0;i<10;i++)
{ a7=Get_Adc_Average(ADC_CH7,20);
sum=sum+a7;
}
aver=sum/10;
if(aver<3023)
{ printf("¹Ø±Õ¼ÌµçÆ÷Ç°µÄ¾ùÖµ %d\n",aver);
LED10=0;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
BEEP=!BEEP;
}
}
}
}
}
你要说明白哪个开关,哪个数据自动跳到开
页:
[1]