CPP-QT   33

safe box code

Guest on 1st November 2021 10:42:54 AM

  1. int LDR=0;
  2. int laser =4;
  3. int SOUND =7;
  4. int swich=8;
  5. int alarm=0 , b=0;
  6. char check[1];
  7.  
  8. #include <SoftwareSerial.h>
  9. char str [1];
  10. char str_1 [1];
  11. //const int echo=10;
  12. //const int trige=9;
  13. //int LedPin=4;
  14. SoftwareSerial MYSerial(2 , 3);
  15.  
  16.  
  17.  
  18.  
  19. void setup() {
  20.   pinMode(laser , OUTPUT);
  21.     pinMode(SOUND , OUTPUT);
  22.     digitalWrite(laser , HIGH);
  23.     digitalWrite(swich , INPUT);
  24.     MYSerial.begin(9600);
  25.     Serial.begin(9600);
  26.     delay(1000);
  27.  
  28. }
  29.  
  30. void loop()
  31. {
  32.  
  33.   LDR=analogRead(A1);
  34.  
  35.   //delay(100);
  36. if(b==0){
  37.     if(LDR<900 || digitalRead(swich) )
  38.   {
  39.   alarm=1;
  40.  
  41.   }}
  42.  
  43.   if(MYSerial.available())
  44. {
  45. check[0]=MYSerial.read();  
  46. Serial.println(check[0]);
  47. }
  48. if(check[0]=='O')
  49. {
  50. alarm=0;
  51. b=1;
  52. }
  53. else if(check[0]=='F')
  54. {
  55. b=0;
  56.  
  57. }
  58.  
  59. if(alarm==1 )
  60. {
  61.  // alarm=5;
  62.   //MYSerial.println("alarm is on");
  63. digitalWrite(laser , LOW);
  64. digitalWrite(SOUND , HIGH);
  65. }
  66.  
  67. else if(alarm==0)
  68. {
  69. //alarm=5;
  70.  // MYSerial.println("alarm is off");
  71. digitalWrite(laser , HIGH);
  72. digitalWrite(SOUND , LOW);
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79. //else
  80. //{
  81. //digitalWrite(laser , HIGH);
  82. //
  83. //}
  84.  
  85.  
  86.  
  87. }

Raw Paste


Login or Register to edit or fork this paste. It's free.