UVC Camera Servo Motor Control [P006.1]
https://www.youtube.com/watch?v=pAshFXld2N0
*GitHub : https://github.com/rdiot/rdiot-p006.1.git
* Parts
- Arduino Yun (ARDUINO-YUN) [B015]
- Logitech HD WebCam C310 (C310) [S084]
- Tower Pro SG90 Micro Servo (SG90) [D018]
* Contents
- Control Interface
- Source
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#include <Servo.h>
YunServer server;
Servo myservo1;
Servo myservo2;
int servoPin_leftright = 9;
int servoPin_updown = 10;
int pos_updown_min = 100;
int pos_updown_max = 150;
int pos_leftright_min = 0;
int pos_leftright_max = 90;
int pos_updown;
int pos_leftright;
int pos_cnt = 5;
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
server.listenOnLocalhost();
server.begin();
myservo1.attach(servoPin_leftright);
myservo2.attach(servoPin_updown);
for(int pos = 0; pos < 65; pos += 1)
{
myservo1.write(pos);
pos_leftright = pos;
delay(100);
}
for(int pos = 150; pos>=100; pos-=1)
{
myservo2.write(pos);
pos_updown = pos;
delay(100);
}
}
void loop() {
YunClient client = server.accept();
if (client) {
process(client);
client.stop();
}
delay(50);
}
void process(YunClient client) {
String command = client.readStringUntil('/');
if (command == "control") {
controlCommand(client);
}
}
void digitalCommand(YunClient client) {
int pin, value;
pin = client.parseInt();
if (client.read() == '/') {
value = client.parseInt();
digitalWrite(pin, value);
}
else {
value = digitalRead(pin);
}
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to "));
client.println(value);
String key = "D";
key += pin;
Bridge.put(key, String(value));
}
void controlCommand(YunClient client) {
String mode = client.readStringUntil('/');
if(mode == "up")
{
int temp = pos_updown + pos_cnt;
if(temp < pos_updown_max)
{
myservo2.write(temp);
pos_updown = temp;
}
}
if(mode == "down")
{
int temp = pos_updown - pos_cnt;
if(temp > pos_updown_min)
{
myservo2.write(temp);
pos_updown = temp;
}
}
if(mode == "right")
{
int temp = pos_leftright - pos_cnt;
if(temp > pos_leftright_min)
{
myservo1.write(temp);
pos_leftright = temp;
}
}
if(mode == "left")
{
int temp = pos_leftright + pos_cnt;
if(temp < pos_leftright_max)
{
myservo1.write(temp);
pos_leftright = temp;
}
}
client.print(F("Camera "));
client.print(mode);
client.print(F(" Current Point X = "));
client.print(pos_leftright);
client.print(F(", Current Point Y = "));
client.print(pos_updown);
}
'2) Sensor > Camera' 카테고리의 다른 글
Raspberry Pi Camera 5MP Night Version (SEN0184) [S280] (0) | 2018.04.02 |
---|---|
UVC Camera Movie Monitoring [P006] (0) | 2017.03.03 |
Logitech HD WebCam C310 (C310) [S084] (0) | 2016.09.13 |
Samsung ARTIK 10 USB Camera [P010.7] (0) | 2016.08.31 |