Go Down

Topic: Single shot (Read 1 time) previous topic - next topic

Hackdub

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..

AWOL

Quote
is it possible to make a switch "Single Shot" with arduino..

Yes, just don't put an "else" clause in your "if" statement.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

spycatcher2k

Follow this logic :
if I read high - set (triggered=TRUE)
if I read low while triggered=TRUE set (triggered=FALSE)
if triggered=HIGH and done=FALSE - DO SOMETHING,then set done=TRUE
start again

Hope this helps
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Hackdub

Ok so could you apply your thery to this

Code: [Select]
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..

does this make any sense..

please help

david

HazardsMind

#4
Jan 03, 2013, 04:25 pm Last Edit: Jan 03, 2013, 04:27 pm by HazardsMind Reason: 1
Pseudo example:

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
}
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Go Up