I'm new in the C language and im trying to make a luck fortune with leds, it will "spin" blinking the 8 leds in order and then blink only the winner one but i dont know if i can do it in C without making a case switch for every P2OUT of the microcontroller (the interrupt is because it will interact with a bluetooth module across with a cellphone application )
#include <msp430g2553.h>
#include <stdlib.h> // libreria para el uso de rand()
#include<time.h>
int x;
int a;
int numero;
volatile int Counter=0;
/**
* main.c
*/
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void){
Counter--; //Disminuir el Contador en 1
LPM3_EXIT; //Salir del modo de bajo poder 3
}
void wait(int seconds){
Counter= seconds*2;
while(Counter){
LPM3;
}
}
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
BCSCTL1= CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1SEL=0x06;
P1SEL2=0x06;
P2SEL=0x0;
P2SEL2=0x0;
P2DIR=0xFF;
P2OUT=0x00;
UCA0CTL1=0x81;//Enabled USCI logic held in reset state
UCA0CTL0=0x0;//UART Mode, Odd Parity, 8bit Data, 1 bit de parada, asynchronous
UCA0BR0=0x68;//Baud rate 9600
UCA0BR1=0x0;//Baud rate (UCA0BR0+UCA0BR1x256=9600)
UCA0MCTL=0x2;
UCA0STAT=0x0;
UCA0CTL1 =0x80;//Disabled USCI logic held in reset state
IE2=1;
__enable_interrupt();
for (;;){
if (a==49){ // 1 recieved from bluetooth "49" in code ASCII
srand (time(NULL)); //seed of random number based on the time
numero = rand(1,9); //generated random number between 1 and 9
for(int i=0,i<9,i++){
P2OUT=BIT(i); //HELP HERE BLINKING THE LEDS WITH CYCLE FOR
wait(5) //function of delay
}
P2OUT=;
}
}
}
}
#pragma vector=USCIAB0RX_VECTOR //interruption for bluetooth module HC-05
__interrupt void uartbt(void)
{
a=UCA0RXBUF;//INTERRUPCION DONDE SE ALMACENA EL VALOR CUANDO HAY COMUNICACION EN EL BLUETOOTH
IFG2=0;//Limpiamos bandera de interrupción para salir
}