
#include <main.h>
#define LCD_ENABLE_PIN PIN_C0
#define LCD_RS_PIN PIN_C2
#define LCD_RW_PIN PIN_C1
#define LCD_DATA4 PIN_C4
#define LCD_DATA5 PIN_C5
#define LCD_DATA6 PIN_C6
#define LCD_DATA7 PIN_C7


void welcome (void);
unsigned int value1;
unsigned int value2;
unsigned int value3;
unsigned int read_pot1(void);
unsigned int read_pot2(void);
unsigned int read_pot3(void);
unsigned long press=0;
#include <lcd.c>

void main()
{
	setup_adc_ports(sAN0 | sAN1 | sAN2, VSS_VDD);
	setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0);

   lcd_init();
 
	while(TRUE)
	{

		//Example blinking LED program dont forget to remark out the following line
			welcome();					// display welcome message

		
				
		
	
	}
  
}

void welcome (void)
	{				
	 
	   	  printf(lcd_putc,"");		// clear the screenand print the wecome message.
					lcd_gotoxy(2,1);
					value1=read_pot1();  
					printf(lcd_putc,"  pot Value 1%4u",value1);
					lcd_gotoxy(4,2);
					value2=read_pot2();
					printf(lcd_putc,"pot value 2%4u",value2);
					lcd_gotoxy(24,1);
					value3=read_pot3();
					printf(lcd_putc,"pot value 3%4U",value3);
					lcd_gotoxy(23,2);
					printf(lcd_putc,"      ");
					output_B(0);
					output_low(PIN_A6);
					output_low(PIN_A7);
	    if(input(PIN_A5))
	    {
	       // button 2 code
	       printf(lcd_putc,"\f POT ON LEDS");
	       output_B(value1);
	       delay_ms(800);
	       output_B(value2);
	       delay_ms(800);
	       output_B(value3);
	       delay_ms(800);			
	    }
	    
	    
	     if(input(PIN_A4))
	   {
	      // button 1 code
	      // setup a counter whih meets the condtions for each statment so when the button is pressed it counts us and then meets the next condition allowing you to go to the next section
	      press = 0; 
	      lcd_gotoxy(2,1);
	      printf(lcd_putc,"\f  anti-clockwise");
	      output_high(PIN_A6);
	      output_low(PIN_A7);
	      delay_ms(200);
	      press ++ ;
	    
	   }  
	      //while(press=2;)
	   //   {
		 //button 1 code
		//printf(lcd_putc,"\f   STOP");
	    //  output_low(PIN_A6);
	    //  output_low(PIN_A7);
		// press = press+1;
		 
	     // }
	     /*
	     for(press=2)
		// button 1 code
	     {
		printf(lcd_putc,"\f clockwise");
		output_high(PIN_A7);
	        output_low(PIN_A6);
		 press = press+1;
		
	     }
		if(press==5)
		{
		   //button 1 code
		 printf(lcd_putc,"\f stop");
		  output_low(PIN_A7);
		  output_low(PIN_A6);
		   press = press+1;
		  */ 
		}
	    
					
	
	
	
unsigned int read_pot1(void)
	 {
	    unsigned int value1;
	    set_adc_channel(0);
	    delay_us(20);
	    value1=read_adc();
	    return(value1);
	 } 
	 
unsigned int read_pot2(void)
	 {
	    unsigned int value2;
	    set_adc_channel(1);
	    delay_us(20);
	    value2=read_adc();
	    return(value2);
	 } 

unsigned int read_pot3(void)
	 {
	    unsigned int value3;
	    set_adc_channel(2);
	    delay_us(20);
	    value3=read_adc();
	    return(value3);
	 } 
	 
