-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCefiroCodeV2.ino
67 lines (59 loc) · 1.39 KB
/
CefiroCodeV2.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
// For: Humanos3D-Enable Medellin
// By: Mauricio Cano Bedoya June 2020
// Control Céfiro V2
// Este código es para el control básico del servomotor con
// un botón táctil para el dispositivo "Céfiro"
// Declaraciones
#include <Servo.h>
#include <avr/sleep.h>
#define PinBoton 11
#define PinServo 10
Servo servo;
// Variables
int Estado = 0;
const int POS1 = 165;
const int POS2 = 20;
const int TIME_OUT1 = 100;
const int TIME_OUT2 = 1000;
const int TIME_SLEEP = 30000;
int band = 1;
bool FLAG = false;
unsigned long time;
// Configuración
void setup() {
//Serial.begin(9600);
servo.attach(PinServo);
pinMode(PinBoton, INPUT);
}
void loop() {
// Modo de bajo consumo luego de 30 segundos
time = millis();
if (time > TIME_SLEEP) sleep_mode();
// Lectura estado del botón
Estado = digitalRead(PinBoton);
if (Estado == HIGH)
{
FLAG = !FLAG;
band = 1;
delay(TIME_OUT2);
}
// Condiciones que activan el servomotor en las diferentes posiciones
if (FLAG && band)
{
//Serial.println("Posicion 1");
band = 0;
servo.attach(PinServo);
servo.write(POS1);
delay(TIME_OUT1);
servo.detach();
}
else if (FLAG == 0 && band)
{
//Serial.println("Posicion 2");
band = 0;
servo.attach(PinServo);
servo.write(POS2);
delay(TIME_OUT1);
servo.detach();
}
}