認真學習本教程,,可以讓你的高達動起來,。配合先前發(fā)布的兩篇教程: 【教程】鋼普拉LED筆記 一學就會 【教程】為模型增加音效 看了也不會! 高達模型就可以上戰(zhàn)場了,! 代碼部分為代碼下方配圖中的代碼,,請注意區(qū)分。
軟件下載:在圖中已寫
內(nèi)地板驅(qū)動程式下載:請點擊文末閱讀原文
Arduino micro pro
,!留意,!上載編碼時板子最好不要插上任何LED或周邊設(shè)備
!留意,!
ARDUINO 用的是C++ 編碼,,當中主要會有 void setup() { void loop() { 所以如果要把網(wǎng)上得到的編碼混合使用,,void setup()的CODE要放回void setup(),void loop() 的CODE要放回void loop(),,其他變數(shù)和載入周邊設(shè)備的CODE就要放在void setup()之前,。 //CODE: int led = 13; void setup() { pinMode(led, OUTPUT); } void loop() { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000); }
!留意,! const int led[]={8,9} ; 編碼會安先后把接腳8變成led[0] 接腳9變成led[1] 所以如果你把接腳加上去 const int led[]={8,9,10,11,12} ; 就會變成 接腳8=led[0] 接腳9=led[1] 接腳10=led[2] 接腳11=led[3] 接腳12=led[4] 而void setup() {內(nèi)的 for (i = 0 ; i<1 ; i++ ) 也要改成4顆LED for (i = 0 ; i<4; i++ ) //CODE: const int led[]={8,9} ; int i ; void setup() { for (i = 0 ; i<1 ; i++ ) { pinMode(led[ i ], OUTPUT ); } } void loop() { analogWrite (led[0],250); delay(250); digitalWrite(led[0],0); delay(250); analogWrite (led[1],250); delay(250); digitalWrite(led[1],0); delay(250); }
///CODE const int ledpin[]={2,3,4,5,6} ;////LED+線接2,3,4,5 int eyesrun ; int eyesmove; int speed=100;////轉(zhuǎn)動速度 int lightness=250;////亮度 int center_eye_delay=5000;////中間眼的停頓時間 int L_eye_delay=1000;///最左眼的停頓時間 int R_eye_delay=2000;///最右眼的停頓時間 void setup() { for (eyesrun = 0 ; eyesrun <5 ; eyesrun ++ ) { pinMode(ledpin[ eyesrun ], OUTPUT ); } } void loop() { for (eyesmove= 0 ; eyesmove<4 ; eyesmove++ ){ analogWrite (ledpin[eyesmove],lightness); if (eyesmove==2){ delay(center_eye_delay); } else if(eyesmove==0){ delay(R_eye_delay); } else delay(speed); analogWrite (ledpin[eyesmove],0); } for (eyesmove= 4 ; eyesmove>0 ; eyesmove-- ){ analogWrite (ledpin[eyesmove],lightness); if(eyesmove==4){ delay(L_eye_delay); } else delay(speed); analogWrite (ledpin[eyesmove],0); } }
1:100 MG ZAKUII Var2.0
//CODE const int led[] = {4, 5, 6, 7, 8 , 3 , 2, 9, 10 }; int i ; int j=2000 ; int k=500 ; int x=10 ; int y=250 ; void setup() { for (i = 0 ; i<8 ; i++ ) { pinMode(led[ i ], OUTPUT ); }
}
void loop() { analogWrite (led[0],y); delay(k); digitalWrite(led[0],LOW); delay(x);
analogWrite (led[1],y); delay(k); digitalWrite(led[1],LOW); delay(x);
analogWrite (led[2],y); delay(j); digitalWrite(led[2],LOW); delay(x);
analogWrite (led[3],y); delay(k); digitalWrite(led[3],LOW); delay(x);
analogWrite (led[4],y); delay(j); digitalWrite(led[4],LOW); delay(x);
analogWrite (led[3],y); delay(k); digitalWrite(led[3],LOW); delay(x);
analogWrite (led[2],y); delay(k); digitalWrite(led[2],LOW); delay(x);
analogWrite (led[5],y); delay(k); digitalWrite(led[5],LOW); delay(x);
analogWrite (led[6],y); delay(k); digitalWrite(led[6],LOW); delay(x);
analogWrite (led[5],y); delay(k); digitalWrite(led[5],LOW); delay(x);
analogWrite (led[2],y); delay(j); digitalWrite(led[2],LOW); delay(x);
analogWrite (led[7],y); delay(k); digitalWrite(led[7],LOW); delay(x);
analogWrite (led[8],y); delay(j); digitalWrite(led[8],LOW); delay(x);
analogWrite (led[7],y); delay(k); digitalWrite(led[7],LOW); delay(x);
analogWrite (led[2],y); delay(j); digitalWrite(led[2],LOW); delay(x);
analogWrite (led[1],y); delay(k); digitalWrite(led[1],LOW); delay(x); }
,!留意! 您可以先用 int x=???; int y=???; int z =???; 去預設(shè)多個角度,, 這樣做的好處是日后修改也只需改變x,y,z的數(shù)值就可以了,,甚至可以加入數(shù)式x-10,x+20的簡單算數(shù)去改變角度。 //CODE: #include <Servo.h> Servo myservo; int x=0; int y=90; int z=180; void setup() { myservo.attach(13); } void loop() { myservo.write(x); delay(1000); myservo.write(y); delay(1000); myservo.write(z); delay(1000); }
//CODE: #include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(0);
}
void loop() {
myservo.write(x); delay(1000);
}
//CODE:
#include <Servo.h>
Servo myservo; int speed=20; int angle;
void setup() {
myservo.attach(13);
}
void loop() {
for (angle= 0 ; angle<=90 ; angle++ ){ myservo.write(angle); delay(speed); }
for (angle= 90 ; angle>=0 ; angle-- ){ myservo.write(angle); delay(speed); } }
//CODE:
void setup() { pinMode( 13 , OUTPUT); pinMode( 12, OUTPUT); pinMode( 11, OUTPUT); }
void loop() { analogWrite(13 , 250);
digitalWrite(11 , HIGH); digitalWrite(12, LOW); delay(3000);
digitalWrite(11 , LOW); digitalWrite(12, LOW); delay(3000);
digitalWrite(11, LOW); digitalWrite(12, HIGH); delay(3000);
digitalWrite(11 , LOW); digitalWrite(12, LOW); delay(3000);
}
//CODE: #include <Servo.h> Servo servo1; Servo servo2;
const int button1Pin = 2; int buttonState = 0;
int x =0; int y =180;
void setup() { servo1.attach(13); servo2.attach(12);
pinMode(button1Pin, INPUT);
}
void loop() { buttonState = digitalRead(button1Pin);
servo1.write(x); servo2.write(y); delay(10);
if (buttonState == HIGH) { x=x+10; y=y-10; } else { x=x-10; y=y+10; }
if (x>170) { x=180; y=0; } else if (x<10) { x=0; y=180; }
}
用mini就可整個板子收藏,。
//GOTECK 1.5g //CODE: #include <Servo.h>
Servo myservo;
int x=20; int y=90; int z=160;
void setup() {
myservo.attach(13);
}
void loop() {
myservo.write(x); delay(1000);
myservo.write(y); delay(1000);
myservo.write(z); delay(1000);
}
編碼的"HIGH"和"LOW"除了供電給LED也可供電給其他的雜成IC
要留意的是,,摩打越大動力越大,摩打越小動力也相對小,。
用不同顏色的電線方便記認,。
廣告 歡迎大家留言交流!
原創(chuàng)文章聲明
|