#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




//gobals
unsigned int value1;
unsigned int value2;
unsigned int value3;
unsigned int button1;
unsigned int ops;
//gobals
void welcome (void);
unsigned int select (void);
void task2 (void);

#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
	 {				   // wait

					//printf(lcd_putc,"\f");		// clear the screenand print the wecome message.
					set_adc_channel(0); // set pin A0 as adc channel
					delay_us(10); //delay to allow adc to change 
					value1=read_adc();//reads adc value into value1
					lcd_gotoxy(4,1);
					printf(lcd_putc,"pot1%4u",value1);//writes value1 to line
					set_adc_channel(1); // set pin A1 as adc channel
					delay_us(10);//delay to allow adc to change 
					value2=read_adc();//reads adc value into value2
					lcd_gotoxy(4,2);
					printf(lcd_putc,"pot2%4u",value2);//writes value2 to line
					lcd_gotoxy(24,1);
					set_adc_channel(2); // set pin A2 as adc channel
					delay_us(10);//delay to allow adc to change 
					value3=read_adc();//reads adc value into value3
					printf(lcd_putc,"pot3%4u",value3);//writes value3 to line
	    if(input(PIN_A4)==1)
	       button1=button1+1;
	    delay_ms(250);
	    switch(button1)
	    {
	    case 1: //motor clockwise
	    output_high(PIN_A6);
	    break;
	    case 2://motor stop
	    output_high(PIN_A7);
	    break;
	    case 3://motor anit clockwise
	    output_low(PIN_A6);
	    break;
	    case 4://motor stop
	    output_low(PIN_A7);
	    button1=0;
	    break;
	 }
	 if(input(PIN_A5)==1)
	 {
	    output_b(value1);//output to led
	    delay_ms(2000);//delay of 2 seconds
	    output_b(value2);//output to led
	    delay_ms(2000);//delay of 2 seconds
	    output_B(value3);//output to led
	    delay_ms(2000);//delay of 2 seconds
	 }
	   }
		
		
	}

}
/**
void task2 (void)
{
    printf(lcd_putc,"\f");//clears information
   while (input(PIN_A5)==0) //while loop to keep the selection up cancels if button two is pressed.
   {   if(input(PIN_A4)==1)
      output_high(PIN_A6);
      delay_ms(250);
      if(input(PIN_A4)==1)
	 output_high(PIN_A7);
      delay_ms(250);
	 if(input(PIN_A4)==1)
	    output_low(PIN_A6);
      delay_ms(250);
	    if(input(PIN_A4)==1)
	       output_low(PIN_A7);
      delay_ms(250);     
	 }
}
**/
/**
unsigned int select (void)
{
   unsigned int hold;
   unsigned int go;
   go=0;
   button1=0;
   while(input(PIN_A4)==0)
   {
      lcd_gotoxy(24,2);
      printf(lcd_putc,"%4u",button1);
      delay_ms(10);
      if(input(PIN_A5)==1)
	 button1=button1+1;
      delay_ms(250);
   }
   return button1;
 
   
}
*/
/**
void welcome (void)
	{					
	   printf(lcd_putc,"\f");//writes value1 to line
				while(input(PIN_A5)==0)
				{				   // wait

					//printf(lcd_putc,"\f");		// clear the screenand print the wecome message.
					set_adc_channel(0); // set pin A0 as adc channel
					delay_us(10); //delay to allow adc to change 
					value1=read_adc();//reads adc value into value1
					lcd_gotoxy(4,1);
					printf(lcd_putc,"pot1%4u",value1);//writes value1 to line
					set_adc_channel(1); // set pin A1 as adc channel
					delay_us(10);//delay to allow adc to change 
					value2=read_adc();//reads adc value into value2
					lcd_gotoxy(4,2);
					printf(lcd_putc,"pot2%4u",value2);//writes value2 to line
					lcd_gotoxy(24,1);
					set_adc_channel(2); // set pin A2 as adc channel
					delay_us(10);//delay to allow adc to change 
					value3=read_adc();//reads adc value into value3
					printf(lcd_putc,"pot3%4u",value3);//writes value3 to line
				}
					return;
					  
					
	}
	**/
	