Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 2 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?
ESC_test
#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; Thread::wait(50); } } int main() { com.baud(115200); button.mode(PullUp); ESC.write(0); display.locate(0,0); display.printf("Thrust :"); display.locate(1,0); 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); //ESC.write(thrust); led3 = !led3; wait(0.2); led3 = !led3; } } }
2 Answers
11 years, 2 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.
Martin
11 years, 2 months ago.
I think you may have a runtime error, do the lights look something like this?
http://mbed.org/handbook/Debugging#runtime-errors