is it possible to make a switch "Single Shot" with arduino... I.e it gives a high once.. even when the input is held high... it wont set an op high again until the switch is released and set high?
any ideas..
i want to make a soil meter which triggers an led once when the soil is dry. not latched.
i fully understand the analogue side, but not how to mke it single shot, other than use delays..
int sensorPin = A0; // select the input pin for the soil detector
unsigned int sensorValue = 0; // variable to store the value coming from the soil detector
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
}
void loop()
{
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
if(sensorValue<400) digitalWrite(13, HIGH); // set the LED on
else digitalWrite(13, LOW); // set the LED on
I want the led just to blink once say 1 second even if the input condition stays the same.. obviously if the input changed >400 then this should reset..
byte latch = 0; //initial variable
If(switch == HIGH) { //looks at the switch, if it is high for the first time, LED is ON. If the switch changes then goes high again, LED is OFF
!latch; // This detects whether the switch changed or not.
latch ? (do this if TRUE) : (do this if FALSE); //conditional statement, compressed IF/ELSE statement
}
byte latch = 0; //initial variable
If(switch == HIGH) { //looks at the switch, if it is high for the first time, LED is ON. If the switch changes then goes high again, LED is OFF
!latch; // This detects whether the switch changed or not.
latch ? (do this if TRUE) : (do this if FALSE); //conditional statement, compressed IF/ELSE statement
}
thankss for the quick reply "the penny is satrting to drop"
please could you modify my analogue code so I can see where this drops in..
Cheers david.
int sensorPin = A0; // select the input pin for the soil detector
unsigned int sensorValue = 0; // variable to store the value coming from the soil detector
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
}
void loop()
{
byte latch = 0; //initial variable
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
if(sensorValue<400)
!latch; // This detects whether the switch changed or not
latch ? (digitalwrite(13, HIGH) : (digitalWrite(13, LOW); //conditional statement, compressed IF/ELSE statement
}
is this correct.. not sure on the brackets?
so in thery the lED will come on oonce,, will it go off if the input is still high? as this is what i want just a blip from the led.. i.e not on continuous if the input is held in the <400 condition.
int sensorPin = A0; // select the input pin for the soil detector
unsigned int sensorValue = 0; // variable to store the value coming from the soil detector
byte latch = 0; //initial variable
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
}
void loop()
{
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
if(sensorValue<400)
{
!latch; // This detects whether the switch changed or not
latch ? LED_Burst() : (/*Just smile and wave*/ ); //conditional statement, compressed IF/ELSE statement
}
void LED_Burst() //outside of LOOP()
{
digitalwrite(13, HIGH);
delay(1000); // 1 second delay
digitalWrite(13, LOW);
return;
}
so is this correct? I do hope so.. sorry just learning the ropes
void loop()
{
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
if(sensorValue<400)
{
!latch; // This detects whether the switch changed or not
latch ? LED_Burst() : (/*Just smile and wave*/ ); //conditional statement, compressed IF/ELSE statement
}
} //problem was here, you needed this
If you tried to compile it in the arduino software, you would have gotten an error in the LOOP() telling you, you need a closing bracket " } " before void LED_Burst()
still getting an error
sketch_jan03a.ino: In function 'void loop()':
sketch_jan03a:18: error: expected primary-expression before ')' token
what needs to go here? (in BOLD)
!latch; // This detects whether the switch changed or not
latch ? LED_Burst() : ([b]/*Just smile and wave*/ [/b]); //conditional statement, compressed IF/ELSE statement
Ok thanks guys for you help... still no led though... if I pull A0 high or low
This is my full code
int sensorPin = A0; // select the input pin for the soil detector
unsigned int sensorValue = 0; // variable to store the value coming from the soil detector
byte latch = 0; //initial variable
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
}
void loop()
{
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
if(sensorValue<1000)
{
!latch; // This detects whether the switch changed or not
if (latch)
{
LED_Burst();
}
}
} //problem was here, you needed this
void LED_Burst() //outside of LOOP()
{
digitalWrite(13, HIGH);
delay(1000); // 1 second delay
digitalWrite(13, LOW);
return;
}
!latch; // This detects whether the switch changed or not
No, it doesn't. It applies the NOT operator to latch, but then you discard the result, so nothing happens. You might as well delete this statement.
byte latch = 0; //initial variable
Why are you using a byte variable for boolean operations? Make it clear that you MEAN boolean by using boolean. And initialize it to true or false correctly.
Again it was only meant to be pseudo code, not a working code! The OP sent me a personal message saying it wasn't working, so it tested it myself, and it DIDN'T work. (Obviously)
So I messaged him back the actual working code, and I got back "Thankyou it works!"