0

I'm currently working on a project. I'm sending UDP messages from a program on the computer, to a raspberry PI who has a nuclear F303RE microcontroller connected via serial. The microcontroller has one sensor and one led connected. If the sensor voltage drop under a specific value, the led will lighted up. From my program, I send a UDP message to the raspberry PI, who forwards it to the serial port and the microcontroller. Setting the trigger value "d" in the program only works one time. After setting it for the first time, it won't let me set it again. I've been searching around for a day now, but haven't found any solution. Anyone here have an idea ?

#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); 
            }
}}
duck
  • 369
  • 3
  • 17
Eivindo
  • 1
  • 1
  • In your function `void utspenning()`, you are declaring `voltage1` again. Hence in that function, you are using it as local variable. Value won't be updated in `static float voltage1`. Also, When are you calling `utspenning() `?? – Swanand Nov 08 '16 at 15:44
  • The scanf format specifier is suspicious. Perhaps you want `"%8s"` or `"%[^\r\n]"`, but I don't believe the 's' should appear after the ']'. The call to printf also seems wrong. You specify a float to be printed but you don't provide the value of the float in a subsequent argument. – kkrambo Nov 08 '16 at 18:51
  • Have you stepped through the code in the debugger? What happens? – kkrambo Nov 08 '16 at 18:54
  • It works fine in the debugger. The program let me set the d value once. – Eivindo Nov 09 '16 at 09:21

1 Answers1

-1

I"m not familiar with this micro or the environment you're developing in but I suspect voltage1 needs to be declared volatile.