Jump to content
43oh

Recommended Posts

Hey there, there is an error on the site in the example of attachInterrupt function.

the page: http://energia.nu/AttachInterrupt.html

 

Tested the code on my MSP430G2 Launchpad.

The correct code should be:

 

volatile int state = HIGH;
volatile int flag = HIGH;
int count = 0;
 
void setup()
{
  Serial.begin(9600);
 
  pinMode(GREEN_LED, OUTPUT);
  digitalWrite(GREEN_LED, state);
    pinMode(PUSH2, INPUT_PULLUP);    //The correction 
  attachInterrupt(PUSH2, blink, FALLING); // Interrupt is fired whenever button is pressed
}
 
void loop()
{
  digitalWrite(GREEN_LED, state); //LED starts ON
  if(flag) {
    count++;
    Serial.println(count);
    flag = LOW;
  }
}
 
void blink()
{
  state = !state;
  flag = HIGH;
}
Link to post
Share on other sites

It was corrected on energia.nu but the reference page that ships with Energia has not been corrected. This page was probably missed when syncing things. Will get it synced for the next release.

Yeah! I was using the reference docs when I noticed it. Did not notice on the site. Thanks!

Link to post
Share on other sites
  • 2 years later...

I just posted this reply to the issue on github:

 

@@petesoper thanks for the report. I thought about this and from a h/w point of view the example is correct. The assumption is that an external pull-up resistor is provided. I think the real issue is that the documentation does not mention a pull-up at all. What I will do is to fix the documentation mentioning an external/internal pull-up and then also add the pinMode(, INPUT_PULLUP); call to the Sketch but comment out with the comment that it should be uncommented IF there is no external pull-up.
 
Robert
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...