Jump to content
angel d

Interrupt on TivaLaunchpad

Recommended Posts

in the arduino you can use the attachInterrup in this form you can chenge the state of led quhe push a botton

int  bzero = 2, // El Pin 2  corresponde al botón(interrupcion)
int  ledPin = 4;
// La variable tipo volatile  que comunica entre la
// función de interrupción y bucle principal (loop)
volátile int etat = HIGH ;
void  setup () {
// El pin conectado al botón se abre en modo INPUT
pinMode (Bzero, INPUT)  // Pin en modo entrada
// Activación de la resistencia interna pull-up
digitalWrite (Bzero, HIGH );
// El pin está preparado para encender  el LED
pinMode (ledPin, OUTPUT );
// La interrupción  0 monitorea los cambios de estado del pin 2.
attachInterrupt(0, inter0, CHANGE);
} // fin de setup
void  loop () {
// No hacemos nada más que esperar …
delay (30000);
} // fin del bucle
void  inter0 ()   {  // Se ejecuta cuando se detecta un cambio de estado del Pin 2
etat =! etat  // Cambia el estado. De HIGH a LOW y de LOW a HIGH
igitalWrite (ledPin, etat)   / / encender o apagar el LED
} / / fin inter0

but in tiva how can do some similar? and where is the pins to iterrupt in Tiva launchpad?

Share this post


Link to post
Share on other sites

Any pin on the TivaC LaunchPad can serve as an external interrupt pin. The complete pin map for the TivaC and Stellaris LaunchPad can be found here: http://energia.nu/Guide_StellarisLaunchPad.html. The following Sketch should turn the LED on/off when pressing/releasing the PUSH2 button.

int pin = RED_LED;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(PUSH2, INPUT_PULLUP);
  attachInterrupt(PUSH2, blink, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
}

Share this post


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