Go Down

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

Hackdub

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

This is my full code

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

HazardsMind

#16
Jan 03, 2013, 10:24 pm Last Edit: Jan 05, 2013, 07:45 pm by HazardsMind Reason: 1
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!
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

PaulS

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

HazardsMind

#18
Jan 05, 2013, 06:20 pm Last Edit: Jan 05, 2013, 06:25 pm by HazardsMind Reason: 1
@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.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Go Up