Created
August 16, 2017 12:07
-
-
Save pol8139/ce180c674013304a88479b7241722c9e to your computer and use it in GitHub Desktop.
PSoC4でCapSense(CapSenseCSDではない)で端子触ってるかどうか見てUARTで送信するコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <project.h> | |
#include <stdlib.h> | |
#define STR_LENGTH 256 | |
#define TOUCH_NUM CapSenseP4_TOTAL_CSD_WIDGETS | |
void InitUART(void); | |
void InitCapSense(void); | |
void UpdateCapSense(void); | |
void DetectHandPosition(void); | |
char message[STR_LENGTH]; | |
int main() { | |
CyGlobalIntEnable; /* Enable global interrupts */ | |
InitUART(); | |
InitCapSense(); | |
while(1) { | |
UpdateCapSense(); | |
DetectHandPosition(); | |
UART_UartPutString("\r"); | |
} | |
} | |
void InitUART(void) { | |
UART_Start(); | |
UART_Enable(); | |
} | |
void InitCapSense(void) { | |
CapSenseP4_Start(); | |
CapSenseP4_InitializeAllBaselines(); | |
} | |
void UpdateCapSense(void) { | |
while(CapSenseP4_IsBusy() != 0); | |
//CapSenseP4_UpdateAllBaselines(); | |
CapSenseP4_ProcessAllWidgets(); | |
CapSenseP4_ScanAllWidgets(); | |
} | |
void DetectHandPosition(void) { | |
int touch_bool[TOUCH_NUM]; | |
int i; | |
for(i = 0; i < TOUCH_NUM; i++) { | |
touch_bool[i] = (CapSenseP4_IsWidgetActive(i) >> i); | |
itoa(touch_bool[i], message, 10); | |
UART_UartPutString(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment