7 years, 4 months ago.  This question has been closed. Reason: I have answer

LED1 and LED4 then LED2 and LED3 blinking

I use threads (RTOS.h) and few other functions. In case only threads are used (without queue and other) all works properly. But now no functions working and mbed start to blink synchronously and continously : (LED1, LED4) then (LED2, LED3). What does it mean? What's wrong with my code?


#include "mbed.h"
#include "rtos.h"
#include "Servo.h"
#include "TextLCD.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
DigitalIn button(p5);
AnalogIn RUD(p21);

Servo ESC(p20);

TextLCD display(p5, p6, p7, p8, p9, p10); //по порядку (GND, Vcc, Vo, p5, GND, p6, nc, nc, nc, nc, p7, p8, p9, p10)

Queue<float, 4> qThrust;

Serial com(USBTX, USBRX);

float *thrust;

void sensor_read_thread(void const *args) {
    float RUD_val;
    float RUD_val_prev;
    while (true) {
        RUD_val= RUD.read();
        if (RUD_val!=RUD_val_prev) {
            qThrust.put(&RUD_val, 500);
            RUD_val_prev= RUD_val;
        led1 = !led1;

int main() {
    display.printf("Thrust :");
    display.printf("RUD :");
    Thread thread_1(sensor_read_thread);
    while (true) {
        osEvent evt= qThrust.get();
        if((!button) && (evt.status == osEventMessage)){
            thrust= (float*)evt.value.p;
            com.printf("Thrust : %f", *thrust);
            led3 = !led3;
            led3 = !led3;

2 Answers

7 years, 4 months ago.

Hi Peter,

You have declared p5 twice and p21 can't be used as AnalogIn. If the Servo is using PWM then that can't be used on p20 either! Look at http://mbed.org/handbook/mbed-NXP-LPC1768 to see what can be used on what pin.


Accepted Answer

Yes. I will be careful. Thank you.

posted by Peter Hirt 19 Sep 2013
7 years, 4 months ago.

I think you may have a runtime error, do the lights look something like this?


Oh, that's it! Thank you.

posted by Peter Hirt 19 Sep 2013