Pages: [1] 2   Go Down
Author Topic: Single shot  (Read 939 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24353
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is it possible to make a switch "Single Shot" with arduino..
Yes, just don't put an "else" clause in your "if" statement.
Logged

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

Scotland
Offline Offline
God Member
*****
Karma: 11
Posts: 988
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so could you apply your thery to this

 
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

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
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2929
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
}
« Last Edit: January 03, 2013, 10:27:55 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
}

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

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2929
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just replace switch == HIGH with sensorValue<400 and replace (do this if TRUE) with digitalWrite(13, HIGH) and likewise for (do this if false).

We only provide examples, the rest is up to you.
« Last Edit: January 03, 2013, 10:56:47 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

cheers david
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2929
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You want the led on just once? then this is not for you. You want


Code:
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;



"byte latch" must be moved and go up with sensorPin and sensorValue
« Last Edit: January 03, 2013, 11:33:10 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2929
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your missing a closing bracket somewhere in your loop()
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So close.. can't see the mistake ;-(
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2929
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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()
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)

Code:
!latch; // This detects whether the switch changed or not
       latch ? LED_Burst()  : ([b]/*Just smile and wave*/ [/b]);  //conditional statement,  compressed IF/ELSE statement

Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
latch ? LED_Burst()  : ([b]/*Just smile and wave*/ [/b]);  //conditional statement,  compressed IF/ELSE statement

That's a gross misuse of the ternary operator; it's much more simply written like this:

Code:
if (latch)
{
  LED_Burst();
}
Logged

Pages: [1] 2   Go Up
Jump to: