欢迎大家来到IT世界,在知识的湖畔探索吧!
认真学习本教程,可以让你的高达动起来。配合先前发布的两篇教程:
【教程】钢普拉LED笔记 一学就会
【教程】为模型增加音效 看了也不会!
高达模型就可以上战场了!
代码部分为代码下方配图中的代码,请注意区分。
软件下载:在图中已写
內地板驱动程式下载:请点击文末阅读原文
Arduino micro pro
!留意!上载编码时板子最好不要插上任何LED或周边设备
!留意!
ARDUINO 用的是C++ 编码,当中主要会有
void setup() {
void loop() {
所以如果要把网上得到的编码混合使用,void setup()的CODE要放回void setup(),void loop() 的CODE要放回void loop(),其他变数和载入周边设备的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() {内的
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;////转动速度
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 =???;
去预设多个角度,
这样做的好处是日后修改也只需改变x,y,z的数值就可以了,甚至可以加入数式x-10,x+20的简单算数去改变角度。
//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
要留意的是,摩打越大动力越大,摩打越小动力也相对小。
用不同颜色的电线方便记认。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/37887.html