0

我目前正在做一个项目。我正在从计算机上的一个程序向一个树莓派发送 UDP 消息,该树莓派通过串行连接了一个核 F303RE 微控制器。微控制器连接了一个传感器和一个 LED。如果传感器电压下降到特定值以下,则 LED 会亮起。从我的程序中,我向树莓派发送一条 UDP 消息,树莓派将其转发到串行端口和微控制器。在程序中设置触发值“d”只起作用一次。第一次设置后,它不会让我再次设置它。我已经搜索了一天,但没有找到任何解决方案。这里有人有想法吗?

#include "mbed.h" 
DigitalOut Vcc(PA_0);
AnalogIn aInnA1(PA_1);
DigitalOut Gnd(PA_4);
DigitalOut myled(PA_6);

static float voltage1=0.0f;


void utspenning() 
{
float voltage1 = aInnA1*3.3f;  
printf("$VOLTAGE,A1,%.2f\r\n" ); // This sends value back to the program
}

int main()
{
Vcc=1; Gnd=0;
char e [9];

while(1)
 {   
 scanf("%[^\r\n]s",e); // Reads my input from the program
 float d = atof(e);

    if (voltage1 > d ) 
        {
                    myled = 1;
        }
    if (voltage1 < d ) //  
             {
                myled = 1;
                wait(0.1);
                myled = 0;
                wait(0.1); 
            }
}}
4

1 回答 1

-1

我不熟悉这个微型或您正在开发的环境,但我怀疑电压 1 需要被声明为易失性。

于 2016-11-08T15:29:58.310 回答