Bharath Ram
Published © Apache-2.0

Tip Tap Game

Count the maximum number of Taps You can do in a minute

IntermediateFull instructions provided4 hours1,711
Tip Tap Game

Things used in this project

Hardware components

FRDM Board
NXP FRDM Board
×1

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015
NXP kinetis design studio

Story

Read more

Code

K82F code

C/C++
Program K82F with the below code for Tip Tap Game
#include "board.h"
#include "fsl_tsi_v4.h"
#include "fsl_debug_console.h"
#include "fsl_lptmr.h"

#include "clock_config.h"
#include "pin_mux.h"
/* Available PAD names on board */
#define PAD_TSI_ELECTRODE_1_NAME "D9"
#define LED1_INIT() LED_RED_INIT(LOGIC_LED_OFF)
#define LED1_ON() LED_RED_ON()
#define LED1_OFF() LED_RED_OFF()

/* Get source clock for LPTMR driver */
#define LPTMR_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_LpoClk)


tsi_calibration_data_t buffer;


int main(void)

{
	int a=0;
    tsi_config_t tsiConfig_normal = {0};
    lptmr_config_t lptmrConfig;
    memset((void *)&lptmrConfig, 0, sizeof(lptmrConfig));
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    LED1_INIT();

    LPTMR_GetDefaultConfig(&lptmrConfig);
    /* TSI default hardware configuration for normal mode */
    TSI_GetNormalModeDefaultConfig(&tsiConfig_normal);

    /* Initialize the LPTMR */
    LPTMR_Init(LPTMR0, &lptmrConfig);
    /* Initialize the TSI */
    TSI_Init(TSI0, &tsiConfig_normal);

    /* Set timer period */
    LPTMR_SetTimerPeriod(LPTMR0, USEC_TO_COUNT(5000U, LPTMR_SOURCE_CLOCK));

    NVIC_EnableIRQ(TSI0_IRQn);
    TSI_EnableModule(TSI0, true); /* Enable module */

       /*********  TEST CALIBRATION PROCESS ************/
    memset((void *)&buffer, 0, sizeof(buffer));
    TSI_Calibrate(TSI0, &buffer);


        /********** TEST HARDWARE TRIGGER SCAN ********/

  /*  TSI_EnableModule(TSI0, false);*/
    TSI_EnableHardwareTriggerScan(TSI0, true);
    TSI_SetMeasuredChannelNumber(TSI0, BOARD_TSI_ELECTRODE_1); /* Select TSI_CHANNEL_1 as detecting electrode. */
    TSI_EnableModule(TSI0, true);
    LPTMR_StartTimer(LPTMR0); /* Start LPTMR triggering */

    while (1)
    {
     	if (TSI_GetMeasuredChannelNumber(TSI0) == BOARD_TSI_ELECTRODE_1)
    {
        if (TSI_GetCounter(TSI0) > (buffer.calibratedData[BOARD_TSI_ELECTRODE_1] + 100U))
        {
        	while(TSI_GetCounter(TSI0) > (buffer.calibratedData[BOARD_TSI_ELECTRODE_1] + 100U));
        	a=a+1;
            LED1_ON();
            PRINTF("%d",a);

            }
    }

    LED1_OFF();

}
    }

Credits

Bharath Ram

Bharath Ram

6 projects • 22 followers

Comments