Last active
August 29, 2015 14:02
-
-
Save abruzzi/92c89953bab4ede7d95d to your computer and use it in GitHub Desktop.
Arduino Servo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Arduino pin 9 -> S3003 PWM(orange) | |
* Arduino 5V -> S3003 VCC(red) | |
* Arduino GND -> S3003 GND(brown) | |
*/ | |
#include <Servo.h> | |
Servo servo; | |
int servoPin = 9; | |
int pos = 0; | |
void setup() { | |
servo.attach(servoPin); | |
} | |
void loop() { | |
for(pos = 0; pos < 180; pos += 1) { | |
servo.write(pos); | |
delay(20); | |
} | |
for(pos = 180; pos >= 1; pos -= 1) { | |
servo.write(pos); | |
delay(20); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo servo; | |
int servoPin = 9; | |
void setup() { | |
Serial.begin(9600); | |
servo.attach(servoPin); | |
} | |
int deg = 0; | |
void loop(){ | |
if(Serial.available()) { | |
deg = Serial.parseInt(); | |
} | |
if(deg >= 0 && deg <= 180) { | |
servo.write(deg); | |
delay(20); | |
} else { | |
Serial.write("bad request"); | |
} | |
delay(100); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Connet JY-MCU Bluetooth with arduino | |
* Rx -> Tx | |
* Tx -> Rx | |
* 5v -> 5v | |
* Gnd -> Gnd | |
*/ | |
int value; | |
int led = 13; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(led, OUTPUT); | |
} | |
void loop(){ | |
if(Serial.available()) { | |
value = Serial.read(); | |
} | |
if(value == 'H') { | |
digitalWrite(led, HIGH); | |
} else { | |
digitalWrite(led, LOW); | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment