Advertisement
pippero

Untitled

Apr 15th, 2021
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. unsigned long TempoInizio = 0;
  2. int range = 99;
  3. bool old = HIGH;
  4. bool puls = LOW;
  5. void setup() {
  6. Serial.begin(9600);
  7. pinMode(8, OUTPUT);// buzzer
  8. pinMode(12, INPUT_PULLUP);
  9. }
  10.  
  11. void loop() {
  12. puls = digitalRead(12);
  13.  
  14. //serve per eseguire il comando
  15. //solo 1 volta quando premo
  16. if (digitalRead(12) == LOW && old == HIGH) {
  17. TempoInizio = millis();
  18. range = 0;
  19. old != puls;
  20. }
  21. switch (range) {
  22. case 0: { // your hand is on the sensor
  23. tone(8, 100);
  24. if ( millis() - TempoInizio > 500) {
  25. TempoInizio = millis();
  26. range = 1;
  27. }
  28. }
  29. break;
  30. case 1: { // your hand is close to the sensor
  31. tone(8, 500);
  32. if ( millis() - TempoInizio > 500) {
  33. TempoInizio = millis();
  34. range = 2;
  35. }
  36. }
  37. break;
  38. case 2: {
  39. tone(8, 800);
  40. if ( millis() - TempoInizio > 800) {
  41. TempoInizio = millis();
  42. range = 3;
  43. }
  44. }
  45. break;
  46. case 3: {
  47. tone(8, 1700);
  48. if ( millis() - TempoInizio > 1700) {
  49. TempoInizio = 0;
  50. range = 4;
  51. }
  52. }
  53. break;
  54. case 4: { // your hand is nowhere near the sensor
  55. noTone(8);
  56. break;
  57. }
  58. }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement