CPP 153
HC05 Arduino LED Guest on 3rd February 2024 08:54:43 AM
  1. // Mohamadi & Abasi
  2. #include <SoftwareSerial.h>
  3. #define led1 13
  4. #define led2 12
  5. #define led3 11
  6. /* Create object named bt of the class SoftwareSerial */
  7. SoftwareSerial bt(2,3); /* (Rx,Tx) */  
  8.  
  9. void setup() {
  10.   bt.begin(9600);  /* Define baud rate for software serial communication */
  11.   Serial.begin(9600);  /* Define baud rate for serial communication */
  12.   pinMode(led1, OUTPUT);
  13.   pinMode(led2, OUTPUT);
  14.   pinMode(led3, OUTPUT);
  15.  
  16. }
  17. char flag1 = 0;
  18. char flag2 = 0;
  19. char flag3 = 0;
  20. void loop() {
  21.     if (bt.available())  /* If data is available on serial port */
  22.     {
  23.       unsigned char a = bt.read();
  24.       Serial.write(a);  /* Print character received on to the serial monitor */
  25.       if(a == '1'){
  26.         if(flag1 == 0){
  27.           Serial.print("karim");
  28.           digitalWrite(11, HIGH);
  29.           flag1 = 1;
  30.         }
  31.         else{
  32.           digitalWrite(11, LOW);
  33.           flag1 = 0;
  34.         }
  35.       }
  36.       if(a == '2'){
  37.         if(flag2 == 0){
  38.           digitalWrite(12, HIGH);
  39.           flag2 = 1;
  40.         }
  41.         else{
  42.           digitalWrite(12, LOW);
  43.           flag2 = 0;
  44.         }
  45.       }
  46.       if(a == '3'){
  47.         if(flag3 == 0){
  48.           digitalWrite(13, HIGH);
  49.           flag3 = 1;
  50.         }
  51.         else{
  52.           digitalWrite(13, LOW);
  53.           flag3 = 0;
  54.         }
  55.       }
  56.     }
  57. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

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