Monday, January 10, 2022

new program voice control

new program voice control

*new programing*
String voice;

#define DOOR 10
#define  LIGHT 11
#define FAN 9

void setup() 
{                                            // put your setup code here, to run once:
  Serial.begin(9600);
   pinMode(DOOR, OUTPUT);
  pinMode(LIGHT, OUTPUT);
  pinMode(FAN, OUTPUT);
   analogWrite(FAN,255); 
   analogWrite(DOOR,255);                    // Since LED must be off in the beginning
   analogWrite(LIGHT,255);
}

  int fanVal;
  int doorVal;
  int lightVal;


void loop() {
 
  while (Serial.available())   //Check if there is an available byte to read
  {                            
  delay(10);                   //Delay added to make thing stable
  char c = Serial.read();      //Conduct a serial read
  if (c == '#') {break;}       //Exit the loop when the # is detected after the word
  voice += c;                  //Shorthand for voice = voice + c
  } 

  if (voice.length() > 0) {
    Serial.println(voice);
  //----------Control Multiple Pins/ LEDs----------// 

       if(voice == "*red")//                                FOR RED COLOUR OF THE LED 
     {
     analogWrite(FAN,0); 
     analogWrite(DOOR,255);
     analogWrite(LIGHT,255);
     }  
  else if(voice == "*door")//                              FOR GREEN COLOUR OF THE LED !
     {
    analogWrite(DOOR,0);
    analogWrite(FAN,255);
    analogWrite(LIGHT,255);
     }
  else if(voice == "*LIGHT")//                                FOR BLUE COLOUR OF THE LED !
     {
    analogWrite(FAN,255);
    analogWrite(LIGHT,0);
    analogWrite(DOOR,255);
     }
  
  else if(voice == "*white")//                               FOR WHITE COLOUR OF THE LED !
     {
    analogWrite(FAN,0);
    analogWrite(DOOR,0);
    analogWrite(LIGHT,0);
     }
   else if(voice == "*good night")//                          FOR TURNING OFF LED !
     {
    analogWrite(FAN,255);
    analogWrite(DOOR,255);
    analogWrite(LIGHT,255);
     }
    
    else if(voice == "*chameleon") //                           FOR FADING/CHANGING COLOURS !
     {
     fanVal = 255; // choose a value between 1 and 255 to change the color. 
     lightVal = 0;
     doorVal = 0;
     for(int i = 0; i < 255; i += 1) // fades out of red and into full (i = 255) door
    {
    doorVal += 1;
    fanVal -= 1;
    analogWrite(DOOR, 255 - doorVal);
    analogWrite(FAN, 255 - fanVal);
    delay(10);
  }
 
  fanVal = 0;
  lightVal = 0;
  doorVal = 255;
  for(int i = 0; i < 255; i += 1)
  {
    lightVal += 1;
    doorVal -= 1;
    analogWrite(LIGHT, 255 - lightVal);
    analogWrite(DOOR, 255 - doorVal);
    delay(10);
  }
 
  fanVal = 0;
  lightVal = 255;
  doorVal = 0;
  for(int i = 0; i < 255; i += 1)
  {
    fanVal += 1;
    lightVal -= 1;
    analogWrite(FAN, 255 - fanVal);
    analogWrite(LIGHT, 255 - lightVal);
    delay(10);
  }
   }
voice="";                                                       //Reset the variable after initiating
}
}

No comments:

Post a Comment

माइक्रोटेक microtek इनवर्टर चार्जिंग फॉल्ट रिपेयर

  नमस्कार दोस्तों, आज की यह ब्लॉग माइक्रोटेक कंपनी के 24v इनवर्टर का है, इस इनवर्टर को आज हमने रिपेयर किया, इस इनवर्टर में प्रॉब्लमयह थी कि ...