--- title: 無用盒 Arduino 程式碼 tags: - 電資創客營 - 無用盒 - Arduino --- # 無用盒 Arduino 程式碼 ```clike= #include <Servo.h> #define SERVO_PIN 9 #define SW_PIN 8 #define INIT_DEG 10 Servo serv; int deg=INIT_DEG; void setup() { // put your setup code here, to run once: serv.attach(SERVO_PIN); pinMode(SERVO_PIN,OUTPUT); pinMode(SW_PIN,INPUT_PULLUP); Serial.begin(9600); serv.write(INIT_DEG); } void loop() { // put your main code here, to run repeatedly: deg=INIT_DEG; serv.write(INIT_DEG); delay(200); if(digitalRead(SW_PIN)==HIGH){ Serial.println("is pulled."); while(digitalRead(SW_PIN)==HIGH && deg<=170){ serv.write(++deg); delay(2); } }else Serial.println("is pushed."); } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up