基本塗装を済ませました。ちょっと色が濃いかな?もう少し薄くて青みがかった方が良さそうです。カラーを買ってきて調整してみたいと思います。
回路図とArduinoスケッチを載せておきます。ArduinoはPro mini 5V 16MHzの互換機を使っています。
///
/// PzKpfwIV
/// 6ch HC-05 BT serial receiver
///
#include
int ND0 = 0; //serial data 0 L_UD
int ND1 = 0; //serial data 1 L_LR
int ND2 = 0; //serial data 2 R_LR
int ND3 = 0; //serial data 3 R_UD
int ND4 = 0; //serial data 4 LSW
int ND5 = 0; //serial data 5 RSW
int PWML = 0;//左速度
int PWMR = 0;//右速度
int SPD = 1; //走行スピード
Servo servo09; //サーボの名称を設定
Servo servo10; //サーボの名称を設定
int unsigned long time = 0;
int unsigned long dt;
void setup() {
pinMode(3, OUTPUT);//L正転(490Hz)
pinMode(5, OUTPUT);//L反転(977Hz)
pinMode(6, OUTPUT);//R反転(977Hz)
pinMode(11, OUTPUT); //R正転(490Hz)
pinMode(12, OUTPUT); //砲火
pinMode(7, OUTPUT);//砲塔右回転
pinMode(8, OUTPUT);//砲塔左回転
Serial.begin(115200); // HC05 serial speed
Serial.write(65); //'A'
time = millis();
}
void loop() {
//バッファ領域に7個以上のデータがあるとき
if (Serial.available() > 6 ) {
if (Serial.read() == 63 ) { //'?'
ND0 = Serial.read(); //L_UD //L_UD
ND1 = Serial.read(); //R_UD //L_LR
ND2 = Serial.read(); //L_LR //R_LR
ND3 = Serial.read(); //R_LR //R_UD
ND4 = Serial.read(); //LSW
ND5 = Serial.read(); //RSW
if (ND0 > 144 ) {
PWML = (ND0 - 128) * SPD ; //128以上はマイナス128してSPD倍に
analogWrite(3, PWML) ; //L正転
analogWrite(5, 0 ) ;
}
else if (ND0 < 112 ) {
PWML = (127 - ND0) * SPD ; //128未満は反転してSPD倍に
analogWrite(3, 0 ) ;
analogWrite(5, PWML) ; //L反転
}
else {
PWML = 0;
analogWrite(3, 0) ; //L stop
analogWrite(5, 0) ; //L stop
}
//11:R正転、6:R反転
if (ND3 > 144 ) {
PWMR = (ND3 - 128) * SPD ; //128以上はマイナス128してSPD倍に
analogWrite(11, PWMR) ; //R正転
analogWrite(6, 0 ) ;
}
else if (ND3 < 112 ) {
PWMR = (127 - ND3) * SPD ; //128未満は反転してSPD倍に
analogWrite(11, 0 );
analogWrite(6, PWMR) ; //R反転
}
else {
PWMR = 0;
analogWrite(11, 0) ; //R stop
analogWrite(6, 0) ; //R stop
}
// 0V(000)判定 JOYSTIK_button 砲火
if ( ND5 < 20 ) {
digitalWrite(12, HIGH); //砲火点灯
analogWrite ( 3, 0 ); //
analogWrite ( 5, 127 ); //L反転
analogWrite (11, 0 ); //
analogWrite ( 6, 127 ); //R反転
delay ( 100 ); //後退
digitalWrite(12, LOW ); //砲火消灯
analogWrite ( 3, 127 ); //L正転
analogWrite ( 5, 0 ); //
analogWrite (11, 127 ); //正反転
analogWrite ( 6, 0 ); //
delay ( 100 ); //前進
analogWrite ( 3, 0 ); //stop
analogWrite ( 5, 0 ); //stop
analogWrite (11, 0 ); //stop
analogWrite ( 6, 0 ); //stop
delay ( 100 ); //
}
// 4.17V(213)判定 砲塔回転
if (ND4 > 193 && ND4 < 233 ) {
digitalWrite ( 7, HIGH);
digitalWrite ( 8, LOW );
}
else if (ND5 > 193 && ND5 < 233 ) {
digitalWrite ( 7, LOW );
digitalWrite ( 8, HIGH);
}
else {
digitalWrite ( 7, LOW );
digitalWrite ( 8, LOW );
}
// 2.50V(128 7Fh)Aボタン判定 Normal speed
if (ND5 > 108 && ND5 < 148 ) {
SPD = 1 ;
//} else {
}
// 3.33V(170 AAh)Bボタン判定 High speed
if (ND5 > 150 && ND5 < 190 ) {
SPD = 2 ;
//} else {
}
Serial.write(65);//合図用のデータ'A'を送る
}
}
}