Loading...
Pages: 1 [2]   Go Down
Author Topic: Single shot  (Read 526 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
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
Edison Member
*
Karma: 28
Posts: 1563
"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

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 312
Posts: 35483
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
Edison Member
*
Karma: 28
Posts: 1563
"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

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Pages: 1 [2]   Go Up
Print
 
Jump to: