Pages: 1 [2]   Go Down
Author Topic: Single shot  (Read 1293 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

Ok thanks guys for you help... still no led though... if I pull A0 high or low :-(

This is my full code

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

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

I sent you what to change. Keep in mind that what I gave you before was only meant to be pseudocode, an example, not the actual working code.


I am now a GOD member!
« Last Edit: January 05, 2013, 01:45:43 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 644
Posts: 50477
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
       !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.

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

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

@everyone

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

@PaulS

I did and I did.
« Last Edit: January 05, 2013, 12:25:13 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Pages: 1 [2]   Go Up
Jump to: