这是一个简易的作画机器人,它使用两个便宜的24BYJ步进电机。所有零件至少填充50%以获得良好的稳定性和强度。步进器由Arduino Nano控制,驱动ULN2003。下面是它的作画程序。
//NanoFull step mode
//512 >> 360 degrees 1.4 step/degree
int M1A = 2; int M1B = 3; int M1C = 4; int M1D = 5;
int M2A = 9; int M2B = 10; int M2C = 11; int M2D = 12;
int t=3;
void setup()
{
pinMode(M1A, OUTPUT); pinMode(M1B, OUTPUT); pinMode(M1C, OUTPUT); pinMode(M1D, OUTPUT);
pinMode(M2A, OUTPUT); pinMode(M2B, OUTPUT); pinMode(M2C, OUTPUT); pinMode(M2D, OUTPUT);
}
void loop()
{
//Motor 1
for (int x=0; x<20;x++){
digitalWrite(M1A, HIGH); digitalWrite(M1B, HIGH); digitalWrite(M1C, LOW); digitalWrite(M1D, LOW); delay(t);
digitalWrite(M1A, LOW); digitalWrite(M1B, HIGH); digitalWrite(M1C, HIGH); digitalWrite(M1D, LOW); delay(t);
digitalWrite(M1A, LOW); digitalWrite(M1B, LOW); digitalWrite(M1C, HIGH); digitalWrite(M1D, HIGH); delay(t);
digitalWrite(M1A, HIGH); digitalWrite(M1B, LOW); digitalWrite(M1C, LOW); digitalWrite(M1D, HIGH); delay(t);}
for (int x=0; x<30;x++){
digitalWrite(M1A, HIGH); digitalWrite(M1B, LOW); digitalWrite(M1C, LOW); digitalWrite(M1D, HIGH); delay(t);
digitalWrite(M1A, LOW); digitalWrite(M1B, LOW); digitalWrite(M1C, HIGH); digitalWrite(M1D, HIGH); delay(t);
digitalWrite(M1A, LOW); digitalWrite(M1B, HIGH); digitalWrite(M1C, HIGH); digitalWrite(M1D, LOW); delay(t);
digitalWrite(M1A, HIGH); digitalWrite(M1B, HIGH); digitalWrite(M1C, LOW); digitalWrite(M1D, LOW); delay(t);}
//Motor 2
for (int x=0; x<20;x++){
digitalWrite(M2A, HIGH); digitalWrite(M2B, LOW); digitalWrite(M2C, LOW); digitalWrite(M2D, HIGH); delay(t);
digitalWrite(M2A, HIGH); digitalWrite(M2B, HIGH); digitalWrite(M2C, LOW); digitalWrite(M2D, LOW); delay(t);
digitalWrite(M2A, LOW); digitalWrite(M2B, HIGH); digitalWrite(M2C, HIGH); digitalWrite(M2D, LOW); delay(t);
digitalWrite(M2A, LOW); digitalWrite(M2B, LOW); digitalWrite(M2C, HIGH); digitalWrite(M2D, HIGH); delay(t);}
for (int x=0; x<30;x++){
digitalWrite(M2A, LOW); digitalWrite(M2B, LOW); digitalWrite(M2C, HIGH); digitalWrite(M2D, HIGH); delay(t);
digitalWrite(M2A, LOW); digitalWrite(M2B, HIGH); digitalWrite(M2C, HIGH); digitalWrite(M2D, LOW); delay(t);
digitalWrite(M2A, HIGH); digitalWrite(M2B, HIGH); digitalWrite(M2C, LOW); digitalWrite(M2D, LOW); delay(t);
digitalWrite(M2A, HIGH); digitalWrite(M2B, LOW); digitalWrite(M2C, LOW); digitalWrite(M2D, HIGH); delay(t);}
}
缩略图 | 名称 | 格式 | 大小(KB) |
---|
CopyRight 2007-2017, mfcad.COM, Inc. All Rights Reserved 沪ICP备09092249号 冀公网安备 13010402001320号