-
Notifications
You must be signed in to change notification settings - Fork 0
/
exandounamano.ino
71 lines (60 loc) · 1.5 KB
/
exandounamano.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (C) 2015 Exando una mano
* Authors: Alejando G. Castro <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include <Servo.h>
int sensorPin = 0;
int servoPin = 9;
int inputReading;
int sensorHighThreshold = 30;
int sensorLowThreshold = 5;
Servo handServo;
// Servo position in degrees.
int position = 0;
void setup()
{
// Init the servo output.
pinMode(servoPin, OUTPUT);
handServo.attach(servoPin);
// Init sensor input.
inputReading = 0;
pinMode(sensorPin, INPUT);
}
void moveServo(int pos)
{
handServo.write(pos);
// Wait for the servo to move.
delay(300);
}
void loop()
{
// Read the input value.
inputReading = analogRead(sensorPin);
if (inputReading >= sensorHighThreshold) {
if (position != 180) {
position = 180;
moveServo(position);
}
} else {
if (inputReading < sensorLowThreshold) {
if (position != 0) {
position = 0;
moveServo(position);
}
}
}
delay(50);
}