Go Down

Topic: 35/5000 Call functions with interrupts (Read 923 times) previous topic - next topic

sotodan

I am writing a program that calls a function with an external interrupt. The function should blink a led 5 times. This is the code:

int PULSADOR=2;
int LED=13;
int  estate=LOW;


void setup() {
  // put your setup code here, to run once:
pinMode(PULSADOR, INPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:

  if(digitalRead(PULSADOR)==HIGH){
 void Ledparpar();
 }
 else(digitalRead(PULSADOR)== LOW);
}
/////////////////////////////////////////////////////////////////////////////////

void Ledparpar(int pulsador, int led) {
  // put your main code here, to run repeatedly:
     for ( int i=0; i<8; i++)   {
    digitalWrite(LED, HIGH);
    delay(300);
    digitalWrite(LED, LOW);
    delay(300);

     

UKHeliBob

I don't see an interrupt in your program, nor is it complete.

What problem are you having ?

Code: [Select]
else(digitalRead(PULSADOR)== LOW);
What is this supposed to do ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Whandall

Code: [Select]
  if(digitalRead(PULSADOR)==HIGH){
 void Ledparpar();
 }
 else(digitalRead(PULSADOR)== LOW);


If pin reads high, declare a void function Ledparpar() and directly forget this declaration,
else compare the same pin with low and throw away the result (a true value).

That is not how you call a function, your if/else usage is strange.

The following should work better:

Code: [Select]
  if (digitalRead(PULSADOR) == HIGH) {
    Ledparpar();
  }
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

JaBa

Multiple Problems:

1) void is used when defining the function, not when calling it.
2) digitalRead(PULSADOR) is a read function and using == LOW will not Change the pin at all.
3) You mention Interrupts... I don't see any reference to Interrupts in the code. I assume you have pin PULSADOR implemented in Hardware but you don't seem to use it in any way related to Interrupts.
4) The Arduino language is case sensitive.  PULSADOR and pulsador are two totally different variables but are confusing. Please consider using separate names.
5) Why pass the pulsador Parameter to the function Ledparpar if it isn't used?
6) Case sensitive - Problem 4 applies to LED/led as well.
7) The function Ledparpar is defined as expecting two Parameters. You call it with None.

I doubt this sketch will even compile.

AWOL

Am I the only one who doesn't understand the topic title?
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

PaulS

The art of getting good answers lies in asking good questions.

AWOL

"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

sotodan

UKHeliBob, Whandall, JaBa
I have - and no joke - 4 days programming with arduino; This is my sixth program, thanks to uKHeliBob, Whandall, JaBa your comments have helped me a lot, the program already works. THANK YOU.

Regarding AWOL, which says his presentation is moderator, I just have to tell you that not everyone we started as experts, and if you did not understand the title of my post you have to be a beginner like me; There were those who understood and solved the problem. Thank you friends.

AWOL

#8
Jan 30, 2017, 09:19 pm Last Edit: Jan 30, 2017, 09:20 pm by AWOL
Well, that's put me in my place.
Would you deign to share the meaning of ...oh, wait, 0.007 - it's a James Bond reference (I think)
(If it's any help, I'm certainly not any kind of of Arduino expert)
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

PaulS

Quote
There were those who understood and solved the problem.
There are those that ignored the useless post title, and only looked at the code. The rest of use went WTF when reading the post title, and assumed that, since the thread topic was unrelated to the problem, that you were either an idiot or a troll, and didn't bother reading the code/typing a reply.

You REALLY don't want to foster that impression, do you?

If not, you can stop digging, and explain how the thread title relates to your problem.
The art of getting good answers lies in asking good questions.

Go Up