fork download
  1. //Please first, open new code page (new sketch) from Arduino IDE
  2. //Copy the following code and paste it into the new sketch
  3. //Then save and verify
  4.  
  5. int sound_sensor= 4;
  6. int relay= 5;
  7. int clap= 0;
  8. long detection_range_start = 0;
  9. long detection_range = 0;
  10. boolean status_lights = false;
  11.  
  12. const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
  13. const int motor2Pin = 6; // H-bridge leg 2 (pin 7, 2A)
  14.  
  15. void setup() {
  16. pinMode(sound_sensor, INPUT);
  17. pinMode(relay, OUTPUT);
  18. pinMode(motor1Pin, OUTPUT);
  19. pinMode(motor2Pin, OUTPUT);
  20. pinMode(12, OUTPUT);
  21. Serial.begin (9600);
  22. }
  23.  
  24. void loop() {
  25.  
  26. int status_sensor = digitalRead(sound_sensor);
  27.  
  28. if (status_sensor == 0)
  29. {
  30. if (clap == 0)
  31. {
  32. detection_range_start = detection_range = millis();
  33. clap++;
  34. }
  35. else if (clap > 0 && millis()-detection_range >= 50)
  36. {
  37. detection_range = millis();
  38. clap++;
  39. }
  40. }
  41.  
  42. if (millis()-detection_range_start >= 400)
  43. {
  44. if (clap == 1)
  45. {
  46. if (!status_lights)
  47. {
  48. status_lights = true;
  49. digitalWrite(relay, HIGH);
  50.  
  51. digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge low
  52. digitalWrite(motor2Pin, LOW);
  53. digitalWrite(12, HIGH);
  54. }
  55. else if (status_lights)
  56. {
  57. status_lights = false;
  58. digitalWrite(relay, LOW);
  59. digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
  60. digitalWrite(motor2Pin, LOW);
  61. digitalWrite(12, HIGH);
  62. }
  63. }
  64. clap = 0;
  65. }
  66. }
  67.  
  68. // end code
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:10:1: error: ‘boolean’ does not name a type
 boolean status_lights = false;
 ^~~~~~~
prog.cpp: In function ‘void setup()’:
prog.cpp:16:25: error: ‘INPUT’ was not declared in this scope
   pinMode(sound_sensor, INPUT);
                         ^~~~~
prog.cpp:16:30: error: ‘pinMode’ was not declared in this scope
   pinMode(sound_sensor, INPUT);
                              ^
prog.cpp:17:18: error: ‘OUTPUT’ was not declared in this scope
   pinMode(relay, OUTPUT);
                  ^~~~~~
prog.cpp:21:3: error: ‘Serial’ was not declared in this scope
   Serial.begin  (9600);
   ^~~~~~
prog.cpp: In function ‘void loop()’:
prog.cpp:26:47: error: ‘digitalRead’ was not declared in this scope
   int status_sensor = digitalRead(sound_sensor);
                                               ^
prog.cpp:32:56: error: ‘millis’ was not declared in this scope
       detection_range_start = detection_range = millis();
                                                        ^
prog.cpp:35:33: error: ‘millis’ was not declared in this scope
     else if (clap > 0 && millis()-detection_range >= 50)
                                 ^
prog.cpp:42:14: error: ‘millis’ was not declared in this scope
   if (millis()-detection_range_start >= 400)
              ^
prog.cpp:46:12: error: ‘status_lights’ was not declared in this scope
       if (!status_lights)
            ^~~~~~~~~~~~~
prog.cpp:49:31: error: ‘HIGH’ was not declared in this scope
           digitalWrite(relay, HIGH);
                               ^~~~
prog.cpp:49:35: error: ‘digitalWrite’ was not declared in this scope
           digitalWrite(relay, HIGH);
                                   ^
prog.cpp:52:35: error: ‘LOW’ was not declared in this scope
           digitalWrite(motor2Pin, LOW);
                                   ^~~
prog.cpp:58:31: error: ‘LOW’ was not declared in this scope
           digitalWrite(relay, LOW);
                               ^~~
prog.cpp:58:34: error: ‘digitalWrite’ was not declared in this scope
           digitalWrite(relay, LOW);
                                  ^
prog.cpp:61:27: error: ‘HIGH’ was not declared in this scope
          digitalWrite(12, HIGH);
                           ^~~~
stdout
Standard output is empty