/*
 * File:   BikeLight2023.c
 * Author: User
 *
 * Created on 22 August 2023, 12:01
 */

// CONFIG
#pragma config FOSC = 0       // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF         // FLASH Program Memory Code Protection bit (Code protection off)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#define _XTAL_FREQ 4000000

#include <xc.h>

void main(void) {
TRISA=0x00;
PORTA=0x00;
int i = 6;
int n = 3;
    
        
while(1)
	
    {
    while(n>0)
    {
    while(i>0) // Do the following statement repeatedly while i is greater than 0. Flashes LED 1 6 Times.
        {
            RA0 = 1;		//Turn on LED 1
       
            __delay_ms(60);  // 60 milli-second time delay
      
            RA0 = 0;		//Turn off LED 1
            
            __delay_ms(60);  // 60 milli-second time delay   
            
            i = i-1;        // Decrement i by 1
        } 
    i = 6;  // Reset i back to 6
    
    while(i>0)  // Do the following statement repeatedly while i is greater than 0. Flashes LED 2 6 Times.
        {
            RA1 = 1;		//Turn on LED 2
       
            __delay_ms(60);
      
            RA1 = 0;		//Turn off LED 2
            
            __delay_ms(60);
            
            i = i-1;        // Decrement i by 1
        } 
    i = 6;  // Reset i back to 6
    
    while(i>0)  // Do the following statement repeatedly while i is greater than 0. Flashes LED 3 6 Times.
        {
            RA2 = 1;		//Turn on LED 3
       
            __delay_ms(60);
      
            RA2 = 0;		//Turn off LED 3
            
            __delay_ms(60);
            
            i = i-1;        // Decrement i by 1
        } 
    i = 6;  // Reset i back to 6
    
       
     __delay_ms(800);   // 0.8 Second Time Delay.
     
    if(n > 2)   
    {
            RA2 = 1;		//Turn on LED 3
       
            __delay_ms(300);
    }
           
    else if(n > 1)
    {        
            RA1 = 1;		//Turn on LED 2
       
            __delay_ms(300);
    }
    
    else
    {
            RA0 = 1;		//Turn on LED 1
       
            __delay_ms(300);
    }
           
            RA2 = 0;		//Turn off LED 3
            RA1 = 0;		//Turn off LED 2
            RA0 = 0;		//Turn off LED 1
            __delay_ms(300);
            n = n-1;
	}	
    n= 3;
}
    
    return;
}