#include "Servo.h" Servo myservo; const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) void setup() { myservo.attach(9); Serial.begin(9600); }
#include "Servo.h" Servo myservo; const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) void setup() { myservo.attach(9); Serial.begin(9600); }
焊接技巧:
回覆刪除http://blog.tmu.edu.tw/cool8/%E7%84%8A%E6%8E%A5%E6%8A%80%E5%B7%A7.pdf
http://www.hk-tree.org/downloads/DivisionIIISoldering.pdf
piezo + servo
Example:
http://www.youtube.com/watch?v=OBRTMCDxbJ0
http://www.instructables.com/answers/Would-arduino-be-good-for-a-piezo-triggering-a-ser/
練習範例:
回覆刪除digital >> DigitalInputPullup
analog >> analogInoutSerial
servo >> sweep
servo motor 接線圖:
回覆刪除http://www.azega.com/wp-content/uploads/2011/02/Arduino_Servo_1.png
作者已經移除這則留言。
回覆刪除
回覆刪除#include "Servo.h"
Servo myservo;
void setup()
{
myservo.attach(9);
pinMode(2, INPUT_PULLUP);
}
void loop()
{
int sensorVal = digitalRead(2);
if(sensorVal == HIGH)
{
myservo.write(150);
}
else{
myservo.write(10);
}
}
光敏接線圖:
回覆刪除http://fritzing.org/media/fritzing-repo/projects/s/simple-ldr/images/ldr_mounting_.png
使用範例:
analogInoutSerial
#include "Servo.h"
回覆刪除Servo myservo;
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
myservo.attach(9);
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
if(sensorValue > 100){
myservo.write(150);
}
else{
myservo.write(10);
}
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
delay(100);
}
#include "Servo.h"
回覆刪除Servo myservo;
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
myservo.attach(9);
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
if(sensorValue > 0){
myservo.write(150);
Serial.println("big");
delay(3000);
}
else{
Serial.println("small");
myservo.write(10);
}
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
delay(100);
}