-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolLed_01.txt
121 lines (111 loc) · 2.75 KB
/
solLed_01.txt
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//pantalla
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2);
//fin pantalla
//motorPasos
#include <Stepper.h>
const int stepsPerRevolution =20;
Stepper stepperA(stepsPerRevolution, A1, A2,A3, A4);
int stepperCounter =0;
//fin motor pasos
//botones y leds
int botonRojo = 2;//plastico
int ledRojo=3;
int botonAmarillo = 4;//metal
int ledAmarillo = 5;
int botonVerde = 7;//Carton
int ledVerde = 6;
int botonAzul = 8;//Vidrio
int ledAzul = 10;
//fin de botones y leds
//servo
#include <Servo.h>
Servo myservo;
int pos = 0;
//fin servo
//declaracion de funciones
void motorPasos();
void abrirCompuerta();
void setup() {
//
myservo.attach(9); //el servo
lcd.init(); // Pantalla
lcd.backlight();//pantalla
pinMode(botonRojo,INPUT);
digitalWrite(botonRojo,HIGH);
pinMode(botonAmarillo,INPUT);
digitalWrite(botonAmarillo,HIGH);
pinMode(botonVerde,INPUT);
digitalWrite(botonVerde,HIGH);
pinMode(botonAzul,INPUT);
digitalWrite(botonAzul,HIGH);
pinMode(ledRojo, OUTPUT);
pinMode(ledAmarillo, OUTPUT);
pinMode(ledVerde, OUTPUT);
pinMode(ledAzul, OUTPUT);
//motor a pasos
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
stepperA.setSpeed(60);
//fin motor a pasos
}
void loop() {
if(digitalRead(botonRojo)== LOW){
digitalWrite(ledRojo, HIGH);
lcd.clear();
lcd.print("Plastico");
motorPasos();
}else{
digitalWrite(ledRojo, LOW);
}
if(digitalRead(botonAmarillo)== LOW){
digitalWrite(ledAmarillo, HIGH);
lcd.clear();
lcd.print("Metal");
motorPasos();
}else{
digitalWrite(ledAmarillo, LOW);
}
//
if(digitalRead(botonVerde)== LOW){
digitalWrite(ledVerde, HIGH);
lcd.clear();
lcd.print("Carton");
motorPasos();
}else{
digitalWrite(ledVerde, LOW);
}
if(digitalRead(botonAzul)== LOW){
digitalWrite(ledAzul, HIGH);
lcd.clear();
lcd.print("Vidrio");
motorPasos();
}else{
digitalWrite(ledAzul, LOW);
}
}
void motorPasos(){
for(int i=0; i<1;i++){
stepperA.step(stepsPerRevolution);
}
delay(500);
abrirCompuerta();
for(int j=0; j<1; j++){
stepperA.step(-stepsPerRevolution);
}
delay(500);
}// cierra motorPasos
void abrirCompuerta(){
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}//cierra abrir compuerta