Hi,
My name is Daniel, i am a begginer in creating codes, i have a problem in my code, i think.
I turn on the led with my android and with a sensor a turn it off and send a number to turn on another, but i just want to send once and it keeps sending according to the conditions that i have,
HOW can i fix it
Here is the code:
char val;
int led = 8;
int sensor = 7;
int calibrationTime = 30;
void setup() {
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
void loop() {
int l= digitalRead(led);
int p= digitalRead(sensor);
if(Serial.available())
val = Serial.read();
if(val == '1')
{
digitalWrite(led,HIGH);
}
if( p == HIGH)
{digitalWrite(led,LOW);
delay(500);}
if (p==HIGH && l==LOW)
{
Serial.println("2");
}
if(val =='0')
{digitalWrite(led,LOW);
val=' ';
}
}
The led turns on with android, turns off with sensor, send a number to the android when sensor high and led low y android turns on the other led sending a differente number, i turn off the other led with sensor but if i pass my hand to the sensor, the condition that i hace P=high & l=low turns the second led again
Sorry for the bother, but there is something that i am doing wrong, i am still learning the codes.