- // Mohamadi & Abasi
- #include <SoftwareSerial.h>
- #define led1 13
- #define led2 12
- #define led3 11
- /* Create object named bt of the class SoftwareSerial */
- SoftwareSerial bt(2,3); /* (Rx,Tx) */
- void setup() {
- bt.begin(9600); /* Define baud rate for software serial communication */
- Serial.begin(9600); /* Define baud rate for serial communication */
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- }
- char flag1 = 0;
- char flag2 = 0;
- char flag3 = 0;
- void loop() {
- if (bt.available()) /* If data is available on serial port */
- {
- unsigned char a = bt.read();
- Serial.write(a); /* Print character received on to the serial monitor */
- if(a == '1'){
- if(flag1 == 0){
- Serial.print("karim");
- digitalWrite(11, HIGH);
- flag1 = 1;
- }
- else{
- digitalWrite(11, LOW);
- flag1 = 0;
- }
- }
- if(a == '2'){
- if(flag2 == 0){
- digitalWrite(12, HIGH);
- flag2 = 1;
- }
- else{
- digitalWrite(12, LOW);
- flag2 = 0;
- }
- }
- if(a == '3'){
- if(flag3 == 0){
- digitalWrite(13, HIGH);
- flag3 = 1;
- }
- else{
- digitalWrite(13, LOW);
- flag3 = 0;
- }
- }
- }
- }
Recent Pastes