Some problems..

Hello, a newbie here

I am creating a blinking led-alarm for a intercom system. The output voltage of the intercom while pushing the call button is 6v.

What i exactly want to archieve:

If the 6v pulse is high for less than 2/3 seconds, the led(s) need to blink for +/-10 seconds.

If the 6v pulse is high for more than 3/4 seconds, the led(s) need to blink continuous until the button is released.

i already measured the value via Serial.write, the max value is 438.

The (horrible) code i already wrote.. but it doesnt work..
I got this error: call_read:17: error: expected unqualified-id before 'if'

What am i doing wrong?!

/*
Intercom Led-blinker for Richard

Author: jediah
Date: February 24 2012
*/
const int pulseSource = A0; // +V from 6v source is connected to analog pin A0
const int ledBlinker = 8; // Output to led(s)

void setup()
{
pinMode(ledBlinker, OUTPUT);

}



if (analogRead(pulseSource) == LOW)
{
int val = analogRead(pulseSource); // realtime valure from powersource
time = millis();
delay(200); //debounce

if (val == > 420 && time - millis() >1000)
  {
  digitalWrite(ledBlinker, HIGH);   
  delay(100);              
  digitalWrite(ledBlinker, LOW);    
  delay(100);    
  }
else if (val == > 420 && time - millis() >2000)
 {
  digitalWrite(ledBlinker, HIGH);   
  delay(200);              
  digitalWrite(ledBlinker, LOW);    
  delay(200);  
 }
else
{
  digitalWrite(ledBlinker, LOW);
  digitalWrite(ledBlinker, LOW);
}
}

(Excuse me for my bad english)

It is complaining about this "== >". I presume you intended this to mean "greater than or equal" in which case what you need is ">=".

Pete

How can you use "time" before you declare it?

const int pulseSource = A0; // +V from 6v source is connected to analog pin A0

And probably a stupid question, but you didn't directly connect 6v to A0 did you? (10 Ways to Destroy an Arduino — Rugged CircuitsRugged Industrial Arduino Microcontrollers)

If so, you really don't want to do that :slight_smile:

Brad (KF7FER).

Good to mention, but i didnt do that :slight_smile:

I thought -seen from another code- that it was declared by doing this: time = millis();

el_supremo:
It is complaining about this "== >". I presume you intended this to mean "greater than or equal" in which case what you need is ">=".

Pete

Yes indeed, i wanted to get greater than or equal

I thought -seen from another code- that it was declared by doing this: time = millis();

That would assign the current millis() value to time, but you need to declare time first. Either as separate statement:

unsigned long time;

or including the assignment:

unsigned long time = millis();

The biggest problem you have though is a complete lack of a loop() function.

All of this:

if (analogRead(pulseSource) == LOW)
{
int val = analogRead(pulseSource); // realtime valure from powersource
unsigned long time = millis();
delay(200); //debounce

if (val >= 420 && time - millis() >1000)
  {
  digitalWrite(ledBlinker, HIGH);   
  delay(100);              
  digitalWrite(ledBlinker, LOW);    
  delay(100);    
  }
else if (val >= 420 && time - millis() >2000)
 {
  digitalWrite(ledBlinker, HIGH);   
  delay(200);              
  digitalWrite(ledBlinker, LOW);    
  delay(200);  
 }
else
{
  digitalWrite(ledBlinker, LOW);
  digitalWrite(ledBlinker, LOW);
}
}

is currently outside of any function, which is not allowed. It should be inside the loop() function.