Advertisement
RuiViana

Untitled

May 24th, 2015
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1.  
  2. // http://labdegaragem.com/forum/topics/comando-de-voz-com-ardu-no-e-bluetooth
  3.  
  4. String voz;
  5. int
  6. led1 = 9,
  7. led2 = 10,
  8. led3 = 11,
  9. led4 = 12,
  10. led5 = 13,
  11.  
  12. led6 = 4,
  13. led7 = 5,
  14. led8 = 6,
  15. led9 = 7,
  16. led10 = 8;
  17.  
  18. void allon(){
  19. digitalWrite(led1, HIGH);
  20. digitalWrite(led2, HIGH);
  21. digitalWrite(led3, HIGH);
  22. digitalWrite(led4, HIGH);
  23. digitalWrite(led5, HIGH);
  24.  
  25. digitalWrite(led6, HIGH);
  26. digitalWrite(led7, HIGH);
  27. digitalWrite(led8, HIGH);
  28. digitalWrite(led9, HIGH);
  29. digitalWrite(led10, HIGH);
  30.  
  31. }
  32. void alloff(){
  33. digitalWrite(led1, LOW);
  34. digitalWrite(led2, LOW);
  35. digitalWrite(led3, LOW);
  36. digitalWrite(led4, LOW);
  37. digitalWrite(led5, LOW);
  38.  
  39. digitalWrite(led6, LOW);
  40. digitalWrite(led7, LOW);
  41. digitalWrite(led8, LOW);
  42. digitalWrite(led9, LOW);
  43. digitalWrite(led10, LOW);
  44.  
  45. }
  46.  
  47. void setup() {
  48. Serial.begin(9600);
  49. pinMode(led1, OUTPUT);
  50. pinMode(led2, OUTPUT);
  51. pinMode(led3, OUTPUT);
  52. pinMode(led4, OUTPUT);
  53. pinMode(led5, OUTPUT);
  54.  
  55. pinMode(led6, OUTPUT);
  56. pinMode(led7, OUTPUT);
  57. pinMode(led8, OUTPUT);
  58. pinMode(led9, OUTPUT);
  59. pinMode(led10, OUTPUT);
  60.  
  61. }
  62.  
  63. void loop() {
  64. while (Serial.available()){
  65. delay(10);
  66. char c = Serial.read();
  67. voz += c;
  68. }
  69. if (voz.length() > 0) {
  70. Serial.println(voz);
  71.  
  72. if(voz == "ligar tudo" ) {allon();}
  73. else if(voz == "desligar tudo"){alloff();}
  74.  
  75.  
  76. else if(voz == "ligar lâmpada 1") {digitalWrite(led1, HIGH);}
  77. else if(voz == "ligar lâmpada 2") {digitalWrite(led2, HIGH);}
  78. else if(voz == "ligar lâmpada 3") {digitalWrite(led3, HIGH);}
  79. else if(voz == "ligar lâmpada 4") {digitalWrite(led4, HIGH);}
  80. else if(voz == "ligar lâmpada 5") {digitalWrite(led5, HIGH);}
  81.  
  82. else if(voz == "ligar lâmpada 6") {digitalWrite(led6, HIGH);}
  83. else if(voz == "ligar lâmpada 7") {digitalWrite(led7, HIGH);}
  84. else if(voz == "ligar lâmpada 8") {digitalWrite(led8, HIGH);}
  85. else if(voz == "ligar lâmpada 9") {digitalWrite(led9, HIGH);}
  86. else if(voz == "ligar lâmpada 10")
  87. {
  88. digitalWrite(led10, HIGH);
  89. delay(3000);
  90. digitalWrite(led10, LOW);
  91. }
  92.  
  93.  
  94. else if(voz == "desligar lâmpada 1") {digitalWrite(led1, LOW);}
  95. else if(voz == "desligar lâmpada 2") {digitalWrite(led2, LOW);}
  96. else if(voz == "desligar lâmpada 3") {digitalWrite(led3, LOW);}
  97. else if(voz == "desligar lâmpada 4") {digitalWrite(led4, LOW);}
  98. else if(voz == "desligar lâmpada 5") {digitalWrite(led5, LOW);}
  99.  
  100. else if(voz == "desligar lâmpada 6") {digitalWrite(led6, LOW);}
  101. else if(voz == "desligar lâmpada 7") {digitalWrite(led7, LOW);}
  102. else if(voz == "desligar lâmpada 8") {digitalWrite(led8, LOW);}
  103. else if(voz == "desligar lâmpada 9") {digitalWrite(led9, LOW);}
  104.  
  105.  
  106.  
  107. voz="";}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement