对于飞控来说,其实主要难点还是在软件代码上,代码我做了很多减法,删除了原项目的多余部分。
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////These functions handle the red and green LEDs. The LEDs on the flip 32 are inverted. That is why a Flip32 test is needed.///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void red_led(int8_t level) {if (flip32)digitalWrite(PB4, !level); //If a Flip32 is used invert the output.else digitalWrite(PB4, level); //When using the BluePill the output should not be inverted.}void green_led(int8_t level) {if (flip32)digitalWrite(PB3, !level); //If a Flip32 is used invert the output.else digitalWrite(PB3, level); //When using the BluePill the output should not be inverted.}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////In this part the error LED signal is generated.///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void error_signal(void) {if (error >= 100) red_led(HIGH); //When the error is 100 the LED is always on.else if (error_timer < millis()) { //If the error_timer value is smaller that the millis() function.error_timer = millis() + 250; //Set the next error_timer interval at 250ms.if (error > 0 && error_counter > error + 3) error_counter = 0; //If there is an error to report and the error_counter > error +3 reset the error.if (error_counter < error && error_led == 0 && error > 0) { //If the error flash sequence isn't finisched (error_counter < error) and the LED is off.red_led(HIGH); //Turn the LED on.error_led = 1; //Set the LED flag to indicate that the LED is on.}else { //If the error flash sequence isn't finisched (error_counter < error) and the LED is on.red_led(LOW); //Turn the LED off.error_counter++; //Increment the error_counter variable by 1 to keep trach of the flashe由于文件格式原因,代码仅展示部分,需要的伙伴可以在评论区滴滴,无偿分享~
<hr>参考资料:立创开源硬件平台《YMFC开源小四轴》作者:jamesshao8
https://oshwhub.com/jamesshao8/mini-drone#P4
如果你认为这篇文章很有用,欢迎点赞、关注、转发、收藏~
我会持续更新优质的开源项目!