谷谷 发表于 13-8-15 11:12:24

用arduino做了一个会动的铁球

http://v.youku.com/v_show/id_XNTk2MjEzNTIw.html





下面是程序



/*
Button

Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.


The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board
attached to pin 13.


created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;   // the number of the pushbutton pin
const int ledPinA =8;
const int ledPinB =9;
const int ledPinC =10;
const int ledPinD =11;
const int ledPinE =12;// the number of the LED pin
#include <Servo.h>
Servo myservo;// 定义舵机对象,最多八个

   int pos = 0;    // 定义舵机转动位置
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);   
myservo.attach(7);// 设置舵机控制针脚
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {   
    // turn LED on:   
    digitalWrite(ledPinA, HIGH);
    digitalWrite(ledPinB, LOW);
    digitalWrite(ledPinC, LOW);
    digitalWrite(ledPinD, LOW);
    delay(700);
    digitalWrite(ledPinD, HIGH);
    digitalWrite(ledPinE, LOW);   
          for(pos = pos; pos>=1; pos-=1)
      {                              
      myservo.write(pos);
      delay(10);
      }
}
else {
    // turn LED off:
    digitalWrite(ledPinA, LOW);
      digitalWrite(ledPinD, LOW);
   digitalWrite(ledPinD, HIGH);
   // 0到180旋转舵机,每次延时15毫秒
      for(pos = pos; pos < 180; pos += 1)
   {
      myservo.write(pos);
      delay(10);
      }
   delay(800);
   
   
   
   
    digitalWrite(ledPinB, HIGH);
   delay(400);
   digitalWrite(ledPinB, LOW);
    digitalWrite(ledPinC, HIGH);
    delay(400);
    digitalWrite(ledPinC, LOW);
   
    digitalWrite(ledPinB, HIGH);
   delay(400);
   digitalWrite(ledPinB, LOW);

delay(500);
   
   
   digitalWrite(ledPinC, HIGH);
   delay(300);
   digitalWrite(ledPinC, LOW);
    delay(250);
    digitalWrite(ledPinB, HIGH);
    delay(100);
    digitalWrite(ledPinB, LOW);
    delay(100);
    digitalWrite(ledPinB, HIGH);
    delay(100);
    digitalWrite(ledPinB, LOW);
   
   
    digitalWrite(ledPinB, HIGH);
   delay(300);
   digitalWrite(ledPinB, LOW);
    delay(250);
    digitalWrite(ledPinC, HIGH);
    delay(100);
    digitalWrite(ledPinC, LOW);
    delay(100);
    digitalWrite(ledPinC, HIGH);
    delay(100);
    digitalWrite(ledPinC, LOW);
   
   
    digitalWrite(ledPinB, HIGH);
   delay(300);
   digitalWrite(ledPinB, LOW);
    delay(250);
    digitalWrite(ledPinB, HIGH);
    delay(100);
    digitalWrite(ledPinB, LOW);
    delay(100);
    digitalWrite(ledPinB, HIGH);
    delay(100);
    digitalWrite(ledPinB, LOW);
    delay(100);
    digitalWrite(ledPinC, HIGH);
    delay(80);
    digitalWrite(ledPinC, LOW);
   
   
   
    delay(600);
   
   
   
    digitalWrite(ledPinE, HIGH);
    delay(300);
    digitalWrite(ledPinE, LOW);
    delay(100);
    digitalWrite(ledPinE, HIGH);
    delay(100);
    digitalWrite(ledPinE, LOW);
    delay(100);
    digitalWrite(ledPinE, HIGH);
    delay(100);
    digitalWrite(ledPinE, LOW);
}
}

宅宅宅 发表于 13-8-15 11:36:22

这是摄像头吗?技术宅啊。

TIGER9901 发表于 13-8-15 19:41:09

帅,程序完全看不懂。

Rseason 发表于 13-8-23 19:05:46

技术贴!呵呵!顶起!

唐乾钧 发表于 13-8-29 03:49:07

说句实在话,这个有点小肉啊。。。程序只是设定了两个舵机的转动角度和一些灯光闪烁的时序,只是为了给静态做灯饰的话用arduion就有点杀鸡用牛刀了。

谷谷 发表于 13-8-29 19:56:57

唐乾钧 发表于 13-8-29 03:49 static/image/common/back.gif
说句实在话,这个有点小肉啊。。。程序只是设定了两个舵机的转动角度和一些灯光闪烁的时序,只是为了给静态 ...

是的。。。。初学,不会玩啊

谷谷 发表于 13-8-29 20:10:36

谷谷 发表于 13-8-29 19:56 static/image/common/back.gif
是的。。。。初学,不会玩啊

我用的是uno,刚刚接触这块,还不是很懂,你有作品什么的可以分享一下吗?

kuSAdelang 发表于 13-8-30 13:35:08

高手啊。。技术宅男啊。

ETHANCHEN 发表于 13-9-2 13:13:42

LZ很牛逼啊,怎么做的,灯光怎么穿啊?我之前试过就是电线很难搞进去啊

yjz03658 发表于 13-9-11 10:33:22

这个程序没看懂,东西外观和前卫,就是动作没表现好 帮顶
页: [1] 2
查看完整版本: 用arduino做了一个会动的铁球