Advertisement
Guest User

Untitled

a guest
May 5th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. int ch1 = 1; // chave 1
  2. int ch2 = 2; // chave 2
  3. int led1 = 3; // led 1
  4. int led2 = 4; // led 2
  5. int led13 = 13;// led 13 placa
  6. byte comando = 0;//tipo de comando dos leds
  7.  
  8.  
  9. void setup()
  10. {
  11. pinMode(ch1, INPUT);
  12. pinMode(ch2, INPUT);
  13. pinMode(led1, OUTPUT);
  14. pinMode(led2, OUTPUT);
  15. pinMode(led13, OUTPUT);
  16. }
  17.  
  18. void loop()
  19. {
  20. int leitura1 = digitalRead(ch1);
  21. int leitura2 = digitalRead(ch2);
  22.  
  23.  
  24. if (leitura1 == LOW && leitura2 == LOW) // 00
  25. {
  26. comando = 0;
  27. }
  28. else if (leitura1 == LOW && leitura2 == HIGH) // 01
  29. {
  30. comando = 1;
  31. }
  32. else if (leitura1 == HIGH && leitura2 == LOW) // 10
  33. {
  34. comando = 2;
  35. }
  36. else if (leitura1 == HIGH && leitura2 == HIGH) // 11
  37. {
  38. comando = 3;
  39. }
  40.  
  41. switch (comando)
  42. {
  43. case 0:
  44.  
  45. comando = 0;//comando=0
  46. delay(1000);
  47. digitalWrite(led1, LOW);
  48. digitalWrite(led2, LOW);
  49. digitalWrite(led13, HIGH);
  50. break;
  51.  
  52. case 1:
  53.  
  54. comando = 1;//comando=1
  55. delay(1000);
  56. digitalWrite(led1, LOW);
  57. digitalWrite(led2, HIGH);
  58. digitalWrite(led13, LOW);
  59. break;
  60.  
  61. case 2:
  62.  
  63. comando = 2;//comando=2
  64. delay(1000);
  65. digitalWrite(led1, HIGH);
  66. digitalWrite(led2, LOW);
  67. digitalWrite(led13, LOW);
  68. break;
  69.  
  70. case 3:
  71.  
  72. comando = 4;//comando=3
  73. delay(1000);
  74. digitalWrite(led1, HIGH);
  75. digitalWrite(led2, HIGH);
  76. digitalWrite(led13, LOW);
  77. break;
  78.  
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement