Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. /*** Included libraries ***/
  2. #include <Servo.h>
  3.  
  4.  
  5.  
  6.  
  7. /*** Global variables and function definition ***/
  8. const int BOTON_SEGUNDO = 8;
  9. const int BOTON_PRIMERO = 9;
  10. const int BOTON_BAJO = 10;
  11. const int IR_BAJO = 5;
  12. const int IR_PRIMERO = 4;
  13. const int IR_SEGUNDO = 3;
  14. Servo servoRC;
  15. const int led_bajo = 11;
  16. const int led_primero = 12;
  17. const int led_segundo = 13;
  18. const int zumbador = 6;
  19. const int led_bajo_azul = 7;
  20.  
  21. float estado = 6;
  22. void S0() {
  23. servoRC.write(90);
  24. ApagarLedsPisos();
  25. digitalWrite(led_bajo, HIGH);
  26. }
  27. void S1() {
  28. servoRC.write(90);
  29. ApagarLedsPisos();
  30. digitalWrite(led_primero, HIGH);
  31. }
  32. void S2() {
  33. servoRC.write(90);
  34. ApagarLedsPisos();
  35. digitalWrite(led_segundo, HIGH);
  36. }
  37. void S3() {
  38. servoRC.write(0);
  39. ApagarLedsPisos();
  40. while (digitalRead(IR_PRIMERO) == 0) {
  41. digitalWrite(led_primero, HIGH);
  42. delay(100);
  43. digitalWrite(led_primero, LOW);
  44. delay(100);
  45. }
  46. }
  47. void S4() {
  48. servoRC.write(0);
  49. ApagarLedsPisos();
  50. while (digitalRead(IR_SEGUNDO) == 0) {
  51. digitalWrite(led_segundo, HIGH);
  52. delay(100);
  53. digitalWrite(led_segundo, LOW);
  54. delay(100);
  55. }
  56. }
  57. void S5() {
  58. servoRC.write(180);
  59. ApagarLedsPisos();
  60. while (digitalRead(IR_PRIMERO) == 0) {
  61. digitalWrite(led_primero, HIGH);
  62. delay(100);
  63. digitalWrite(led_primero, LOW);
  64. delay(100);
  65. }
  66. }
  67. void S6() {
  68. servoRC.write(180);
  69. ApagarLedsPisos();
  70. while (digitalRead(IR_BAJO) == 0) {
  71. digitalWrite(led_bajo, HIGH);
  72. delay(100);
  73. digitalWrite(led_bajo, LOW);
  74. delay(100);
  75. }
  76. }
  77. void ApagarLedsPisos() {
  78. digitalWrite(led_bajo, LOW);
  79. digitalWrite(led_primero, LOW);
  80. digitalWrite(led_segundo, LOW);
  81. }
  82. void Parpadeo_Encender() {
  83. for (int bitbloqForCounter = 0; bitbloqForCounter < 3; bitbloqForCounter += 1) {
  84. digitalWrite(led_bajo_azul, HIGH);
  85. delay(70);
  86. digitalWrite(led_bajo_azul, LOW);
  87. delay(70);
  88. }
  89. }
  90. void SonidoLlegarPiso() {
  91. tone(zumbador, 370, 20);
  92. delay(20);
  93. tone(zumbador, 466, 40);
  94. delay(40);
  95. noTone(zumbador);
  96. }
  97. void SonidoEncender() {
  98. tone(zumbador, 261, 100);
  99. delay(100);
  100. tone(zumbador, 293, 100);
  101. delay(100);
  102. tone(zumbador, 329, 100);
  103. delay(100);
  104. tone(zumbador, 349, 100);
  105. delay(100);
  106. tone(zumbador, 392, 100);
  107. delay(100);
  108. tone(zumbador, 349, 100);
  109. delay(100);
  110. tone(zumbador, 329, 100);
  111. delay(100);
  112. tone(zumbador, 293, 100);
  113. delay(100);
  114. tone(zumbador, 261, 100);
  115. delay(100);
  116. noTone(zumbador);
  117. }
  118.  
  119.  
  120.  
  121. /*** Setup ***/
  122. void setup() {
  123. pinMode(BOTON_SEGUNDO, INPUT);
  124. pinMode(BOTON_PRIMERO, INPUT);
  125. pinMode(BOTON_BAJO, INPUT);
  126. pinMode(IR_BAJO, INPUT);
  127. pinMode(IR_PRIMERO, INPUT);
  128. pinMode(IR_SEGUNDO, INPUT);
  129. servoRC.attach(2);
  130. pinMode(led_bajo, OUTPUT);
  131. pinMode(led_primero, OUTPUT);
  132. pinMode(led_segundo, OUTPUT);
  133. pinMode(zumbador, OUTPUT);
  134. pinMode(led_bajo_azul, OUTPUT);
  135.  
  136. SonidoEncender();
  137. delay(1000);
  138. Parpadeo_Encender();
  139. }
  140.  
  141.  
  142. /*** Loop ***/
  143. void loop() {
  144. /*
  145. Cambio de Estados
  146. */
  147. if (estado == 0) {
  148. if (digitalRead(BOTON_PRIMERO) == 1) {
  149. estado = 3;
  150. delay(400);
  151. } else if (digitalRead(BOTON_SEGUNDO) == 1) {
  152. estado = 4;
  153. delay(400);
  154. }
  155. }
  156. if (estado == 1) {
  157. if (digitalRead(BOTON_SEGUNDO) == 1) {
  158. estado = 4;
  159. delay(400);
  160. }
  161. if (digitalRead(BOTON_BAJO) == 1) {
  162. estado = 6;
  163. delay(400);
  164. }
  165. }
  166. if (estado == 2) {
  167. if (digitalRead(BOTON_PRIMERO) == 1) {
  168. estado = 5;
  169. delay(400);
  170. }
  171. if (digitalRead(BOTON_BAJO) == 1) {
  172. estado = 6;
  173. delay(400);
  174. }
  175. }
  176. if (estado == 3) {
  177. if (digitalRead(IR_PRIMERO) == 1) {
  178. estado = 1;
  179. SonidoLlegarPiso();
  180. }
  181. }
  182. if (estado == 4) {
  183. if (digitalRead(IR_SEGUNDO) == 1) {
  184. estado = 2;
  185. }
  186. SonidoLlegarPiso();
  187. }
  188. if (estado == 5) {
  189. if (digitalRead(IR_PRIMERO) == 1) {
  190. estado = 1;
  191. }
  192. SonidoLlegarPiso();
  193. }
  194. if (estado == 6) {
  195. if (digitalRead(IR_BAJO) == 1) {
  196. estado = 0;
  197. }
  198. SonidoLlegarPiso();
  199. }
  200. /*
  201. Ejecución de Funciones
  202. */
  203. switch (int(estado)) {
  204. case 0:
  205. S0();
  206. break;
  207. case 1:
  208. S1();
  209. break;
  210. case 2:
  211. S2();
  212. break;
  213. case 3:
  214. S3();
  215. break;
  216. case 4:
  217. S4();
  218. break;
  219. case 5:
  220. S5();
  221. break;
  222. case 6:
  223. S6();
  224. break;
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement