Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. //Sensor Magnético
  2.  
  3. int SM = 2;
  4. int LED = 13;
  5. int contador = 0;
  6. bool ativo = false;
  7. bool ultimo = false;
  8.  
  9. void setup() {
  10. // put your setup code here, to run once:
  11. pinMode(SM, INPUT);
  12. pinMode(LED, OUTPUT);
  13. }
  14.  
  15. void loop() {
  16. // put your main code here, to run repeatedly:
  17. char c = Serial.read();
  18. if (c == 'Q') {
  19. ativo = true;
  20. ultimo = false;
  21. contador = 0;
  22. Serial.println();
  23. }
  24. if ( c == 'W' ) {
  25. ativo = false;
  26. ultimo = true;
  27. }
  28. if (ativo == true) {
  29. ativarSensor();
  30. }
  31. if (ultimo == true) {
  32. imprimeUltimo();
  33. }
  34. }
  35.  
  36. void ativarSensor() {
  37. if (digitalRead(SM)) {
  38. contador = contador+1;
  39. digitalWrite(LED, HIGH);
  40. delay(100);
  41. digitalWrite(LED, LOW);
  42. delay(100);
  43. Serial.print(contador);
  44. }
  45. }
  46.  
  47. void imprimeUltimo() {
  48. Serial.println(contador);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement