放假这两天自学了arduino单片机编程,自己有其他编程语言的基础,现在给我们小组的二级火箭写了个控制程序,用了大概8小时吧。这是我第一个写的arduino程序,有什么错误的地方请大家帮忙指出。
单片机使用arduino NANO 3.0 ,体积小,重量轻
说明:通过Arduino单片机控制固体燃料二级火箭的分离和开伞动作,以及航拍模块控制
1~4针脚分别为继电器1~4
继电器1控制航拍模块供电
继电器2控制航拍模块拍照按钮
继电器3控制二级点火及爆破切割分离
继电器4控制降落伞打开
5针脚为三轴加速度传感器Z轴的数据接入
整个程序基本就是通过判断Z轴加速度大小来进行操作
程序思路
由于航拍采用成品化的D82密拍,自带的电池质量不好,所以直接拆掉,节省体积。USB接口5V供电,通过继电器1控制航拍模块电源,上电后自动开启声控录像,由于此模式不稳定。所以在继电器1上电10秒后自动接通继电器2,虚拟按下拍照键,终止声控录像模式。再通过持续接通继电器2,一秒,进入录像模式。
void setup()
{
pinMode( 3 , OUTPUT);
XXXXXXXXXgin(9600); pinMode( 4 , OUTPUT);
pinMode( 2 , OUTPUT);
pinMode( 1 , OUTPUT);
}
void loop()
{
delay( 1500 );
XXXXXXXXXint( "System Start Success!!" ); XXXXXXXXXintln(""); digitalWrite( 1 , LOW );
XXXXXXXXXint( "Samera Turn On ......" ); XXXXXXXXXintln(""); delay( 10000 );
XXXXXXXXXint( "Camera Turn On Success!" ); XXXXXXXXXintln(""); digitalWrite( 2 , LOW );
delay( 100 );
digitalWrite( 2 , HIGH );
XXXXXXXXXint( "Camera Start ....." ); XXXXXXXXXintln(""); digitalWrite( 2 , LOW );
delay( 1000 );
digitalWrite( 2 , HIGH );
XXXXXXXXXint( "Camera Start Success!!" ); XXXXXXXXXintln(""); while ( ( ( analogRead(A5) ) <= ( 1 ) ) )
{
XXXXXXXXXint( "Wait Start....." ); XXXXXXXXXintln(""); delayMicroseconds( 1000 );
}
XXXXXXXXXint( "Start !!!" ); XXXXXXXXXintln(""); while ( ( ( analogRead(A5) ) >= ( 1 ) ) )
{
XXXXXXXXXint( "a=" ); XXXXXXXXXint( analogRead(A5) ); XXXXXXXXXintln(""); }
XXXXXXXXXint( "First Rocket Power Over!" ); XXXXXXXXXintln(""); XXXXXXXXXint( "Start Leave Program......" ); XXXXXXXXXintln(""); while ( ( ( analogRead(A5) ) < ( 1 ) ) )
{
digitalWrite( 3 , LOW );
delay( 2000 );
digitalWrite( 3 , HIGH );
delay( 1000 );
XXXXXXXXXint( "Second Fire....." ); XXXXXXXXXintln(""); }
delayMicroseconds( 1000 );
while ( ( ( analogRead(A5) ) < ( 1 ) ) )
{
XXXXXXXXXint( "Wait satrt....." ); XXXXXXXXXintln(""); delayMicroseconds( 1000 );
}
XXXXXXXXXint( "Second Frie Success!!" ); XXXXXXXXXintln(""); while ( ( ( analogRead(A5) ) >= ( 0 ) ) )
{
delayMicroseconds( 1000 );
XXXXXXXXXint( "a=" ); XXXXXXXXXint( analogRead(A5) ); XXXXXXXXXintln(""); }
delayMicroseconds( 1000 );
if (( ( analogRead(A5) ) <= ( 0 ) ))
{
XXXXXXXXXint( "[s:9]arachute Open....." ); XXXXXXXXXintln(""); digitalWrite( 4 , LOW );
delay( 2000 );
digitalWrite( 4 , HIGH );
while ( ( ( analogRead(A5) ) < ( 0 ) ) )
{
XXXXXXXXXint( "a=" ); XXXXXXXXXint( analogRead(A5) ); XXXXXXXXXintln(""); }
}
XXXXXXXXXint( "A Successful Landing" ); XXXXXXXXXintln(""); delay( 20000 );
XXXXXXXXXint( "Close Cream...." ); XXXXXXXXXintln(""); digitalWrite( 1 , HIGH );
XXXXXXXXXint( "Game00over" ); XXXXXXXXXintln(""); XXXXXXXXXint( "GPS" ); XXXXXXXXXintln(""); }
H3C小组二次会议将于近日召开。届时,将进行程序测试,以及数传模块测试。
最终感谢科创论坛对于H3C小组假期火箭项目的基金支持!
200字以内,仅用于支线交流,主线讨论请采用回复功能。