Hi, I am developing smart curtain system with voice control using Arduino Uno and bluetooth sensor
Almost of codes is already written. but I have to fix error with delay function.
I am using timer0_millis for time control.
But the one thing I want to fix is that because of delay in timer1 function,
I cannot change the value of a. but it need to be changed when voice is coming.
can anybody help me to fix this?
extern volatile unsigned long timer0_millis;
#include <SoftwareSerial.h>
#include <Stepper.h>
#include <dht.h>
#include <SimpleTimer.h>
SoftwareSerial BT(2,3);
const int stepsPerRevolution = 64;
Stepper myStepper(stepsPerRevolution, 11,9,10,8);
dht DHT;
#define DHT11_PIN A1
SimpleTimer timer;
char a = BT.read();
void setup()
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission
pinMode(7, OUTPUT);
myStepper.setSpeed(300);
BT.begin(9600);//Sets digital pin 13 as output pin
}
void loop(){
if(BT.available()){
char a = BT.read();
if (a=='1'){
digitalWrite(7,HIGH);
myStepper.step(2048);
delay(500);
Serial.print('1');
}
if (a=='2'){
automode();
}
if (a=='3'){
digitalWrite (7,LOW);
myStepper.step(-2048);
Serial.print('2');
delay(500);
} if (a=='4'){
digitalWrite (7,LOW);
myStepper.step(-2048);
Serial.print('2');
delay(500);
}
}
}
void automode(){
int chk = DHT.read11(DHT11_PIN);
int AnalogValue;
AnalogValue = analogRead(A0);
if(DHT.temperature>30&&AnalogValue>600){
myStepper.step(-2048);
timer1();
}else if(DHT.temperature>30&&AnalogValue<600){
myStepper.step(2048);
timer1();
}else if (DHT.temperature<30&&AnalogValue>600){
myStepper.step(2048);
timer1();
}else if (DHT.temperature<30&&AnalogValue<600){
myStepper.step(-2048);
timer1();
}
return;}
void timer1(){
timer0_millis;
if (timer0_millis>=100000){
timer0_millis=0;}
do{delay(5);}
while(timer0_millis<100000);
return;}