/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#include <project.h>
#include <stdio.h>
char rawCount1[4],rawCount2[4];
int8 pozycja=0,aktpozycja=0;
uint8 ctrl=0;
int main()
{
	LCD_Start();
	PWM_Start();
	PWM_Enable();
	CapSense_Start();
	CyGlobalIntEnable;
	CapSense_InitializeAllBaselines();
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
		LCD_ClearDisplay();
		CapSense_UpdateEnabledBaselines();
		CapSense_ScanEnabledWidgets();
		aktpozycja = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS); 
		sprintf(rawCount1, "%d", aktpozycja);
		LCD_Position(0u,5u);
		LCD_PrintString(rawCount1);
		sprintf(rawCount1, "%d", CapSense_ReadSensorRaw(CapSense_BUTTON0__BTN));
		LCD_Position(1u,5u);
		LCD_PrintString(rawCount1);
		CyDelay(20);
		if (CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN))
		{
			ctrl|=0b00000001;
			ctrl&=0b11111011;
		}
		else ctrl&=0b11111110;
		if (CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN))
		{
			ctrl|=0b00000010;
			ctrl&=0b11111011;
		}
		else ctrl&=0b11111101;		
		CONTROL_Write(ctrl);
		LCD_Position(8u,1u);
		LCD_PrintNumber(ctrl);
		if (aktpozycja>=0) 
		{
			pozycja=aktpozycja;
			ctrl=0b00000100;
		}
		PWM_WriteCompare(pozycja*2+1);
        /* Place your application code here. */
    }
}

/* [] END OF FILE */
