Since interrupts are going to be a key in my upcoming controller - figured I it would be best to work them out now.
First run through with interrupts on the Tiva. Thanks to the pin guide it was really easy to map out what pin I wanted to use.
First round of code is using the buttons to simulate input from the external triggers and low and behold it worked on the first try. You really have to love Energia!!!
Button 1 triggers as soon as the button is pressed.
Button 2 triggers when the button is released.
int state1; // keeps track of current led status for button 1
int state2; // keeps track of current led status for button 2
void button1( void )
{
switch(state1)
{
case 0:
analogWrite(RED_LED,2);
state1 = 1;
break;
case 1:
analogWrite(RED_LED,0);
state1 = 0;
break;
}
}
void button2( void )
{
switch(state2)
{
case 0:
analogWrite(GREEN_LED,2);
state2 = 1;
break;
case 1:
analogWrite(GREEN_LED,0);
state2 = 0;
break;
}
}
void setup()
{
// put your setup code here, to run once:
// Set the IO Pin of the button 1 & 2 to be input
// Found that when using the push button the internal pull up is needed
pinMode(PF_4,INPUT_PULLUP);
pinMode(PF_0,INPUT_PULLUP);
// Get the LEDS ready to be the indicators
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(BLUE_LED, OUTPUT);
state1 = 0; // Red LED starts off
state2 = 0; // Green Led starts off
attachInterrupt(PF_4,button1,FALLING); // Set button 1's interrupt on falling edge
attachInterrupt(PF_0,button2,RISING); // Set button 2's interrupt on rising edge
}
void loop()
{
// put your main code here, to run repeatedly:
int t=1; // Toggle me
while( 1 )
{
if( t == -1 ) analogWrite(BLUE_LED,0); else analogWrite(BLUE_LED,1);
t = t * -1; // Flip that sign
delay(1000); // nice little delay to test interrupting the main loop.
}
}