标题:
基于stm32+fdc2214的手势识别例程
[打印本页]
作者:
malingchao
时间:
2019-9-6 17:38
标题:
基于stm32+fdc2214的手势识别例程
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "oled.h"
#include "fdc2214.h"
#include "key.h"
#include "stm32f10x.h"
#include "exti.h"
void Sys_Init(void);
int key;
int DATA1,DATA2,DATA3,DATA4,DATA5,DATA6,DATA7,DATA8;
int MOD;
float res0,res1,res2,res3;
float temp0,temp1,temp2,temp3;
double shu0,shu1,shu2;
double yi,er,san,si,wu;
int caiquan1,caiquan2=0,caiquan3,huaquan1,huaquan2,huaquan3,huaquan4,huaquan5;
int welcome(void);
int main(void)
{
int i=1;
KEY_Init();
Sys_Init();
KEY_Scan(0);
EXTIX_Init();
while(1)
{
if(MOD==1)//猜拳判决
{
delay_ms(250);
res0 = Cap_Calculate(0);//采集数据(原始数据)
res0 = res0-temp0;//电容接口空载减掉初始值
OLED_Show16x16(30,0,81,0);//猜
OLED_Show16x16(48,0,82,0);//拳
OLED_Show16x16(66,0,87,0);//判
OLED_Show16x16(84,0,88,0);//决
// OLED_Show16x16(0,2,45,0);//数
// OLED_Show16x16(18,2,46,0);//值
// OLED_Show16x16(36,2,18,0);//:
//
//清除上一屏显示内容
//
// OLED_Show16x16(72,4,0,0);//
// OLED_Show16x16(0,6,0,0);//
// OLED_Show16x16(18,6,0,0);//
// OLED_Show16x16(36,6,0,0);//
// OLED_Show16x16(54,6,0,0);//
// OLED_Show16x16(72,6,0,0);//
// OLED_Show16x16(90,6,0,0);//
// OLED_Show16x16(108,6,0,0);//
// OLED_Show16x16(116,6,0,0);//
//
// Oled_Printf_Float(60,3,res0,0);
//Oled_Printf_Float(32,5,res1,0);
printf("CH0:%3.3f \r\n",res0);
if(res0>5.5)
{
i=1; //布
}
if(res0>1.0&res0<4.0)
{
i=3; //剪刀
}
if(res0>4.70&res0<5.40)
{
i=2; //石头
}
if(res0<1.00)
{
i=4; //清空
}
switch(i)
{
case 1:led3=0;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //布
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,111,0);
OLED_Show16x16(61,2,112,0);
OLED_Show16x16(47,4,113,0); //布
OLED_Show16x16(61,4,114,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 2:led3=1;
led4=0;
led5=1;
OLED_Show16x16(31,2,95,0);
OLED_Show16x16(47,2,96,0);
OLED_Show16x16(31,4,97,0);
OLED_Show16x16(47,4,98,0);//石
OLED_Show16x16(61,2,99,0);
OLED_Show16x16(77,2,100,0);
OLED_Show16x16(61,4,101,0); //头
OLED_Show16x16(77,4,102,0);break;
case 3:led3=1;
led4=1;
led5=0;
OLED_Show16x16(31,2,103,0);
OLED_Show16x16(47,2,104,0);
OLED_Show16x16(31,4,105,0);
OLED_Show16x16(47,4,106,0);//剪
OLED_Show16x16(61,2,107,0);
OLED_Show16x16(77,2,108,0);
OLED_Show16x16(61,4,109,0); //刀
OLED_Show16x16(77,4,110,0);break;
case 4:led3=1;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //空
OLED_Show16x16(47,2,0,0);
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,4,0,0);
OLED_Show16x16(61,2,0,0); //空
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(61,4,0,0);
OLED_Show16x16(77,4,0,0);break;
}
}
if(MOD==2)//划拳判决
{
delay_ms(250);
res0 = Cap_Calculate(0);//采集数据(原始数据)
res0 = res0-temp0;//电容接口空载减掉初始值
OLED_Show16x16(30,0,83,0);//划
OLED_Show16x16(48,0,84,0);//拳
OLED_Show16x16(66,0,87,0);//判
OLED_Show16x16(84,0,88,0);//决
// OLED_Show16x16(0,2,45,0);//数
// OLED_Show16x16(18,2,46,0);//值
// OLED_Show16x16(36,2,18,0);//:
// Oled_Printf_Float(60,3,res0,0);
// OLED_Show16x16(36,4,56,0);//请
// OLED_Show16x16(54,4,57,0);//将
// OLED_Show16x16(72,4,58,0);//手
// OLED_Show16x16(0,6,59,0);//放
// OLED_Show16x16(18,6,60,0);//在
// OLED_Show16x16(36,6,61,0);//传
// OLED_Show16x16(54,6,62,0);//感
// OLED_Show16x16(72,6,63,0);//器
// OLED_Show16x16(90,6,64,0);//上
if(res0>2.00&res0<2.60)
{
i=1;
}
if(res0>3.00&res0<3.80)
{
i=2;
}
if(res0>3.90&res0<4.60)
{
i=3;
}
if(res0>5.00&res0<5.80)
{
i=4;
}
if(res0>6.00)
{
i=5;
}
if(res0<2.00)
{
i=6;
}
switch(i)
{
case 1:led3=0;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //一
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,121,0);
OLED_Show16x16(61,2,122,0);
OLED_Show16x16(47,4,123,0);
OLED_Show16x16(61,4,124,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 2:led3=1;
led4=0;
led5=1;
OLED_Show16x16(31,2,0,0); //二
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,125,0);
OLED_Show16x16(61,2,126,0);
OLED_Show16x16(47,4,127,0);
OLED_Show16x16(61,4,128,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 3:led3=1;
led4=1;
led5=0;
OLED_Show16x16(31,2,0,0); //三
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,129,0);
OLED_Show16x16(61,2,130,0);
OLED_Show16x16(47,4,131,0);
OLED_Show16x16(61,4,132,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 4:led3=0;
led4=0;
led5=1;
OLED_Show16x16(31,2,0,0); //四
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,133,0);
OLED_Show16x16(61,2,134,0);
OLED_Show16x16(47,4,135,0);
OLED_Show16x16(61,4,136,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 5:led3=0;
led4=1;
led5=0;
OLED_Show16x16(31,2,0,0); //五
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,137,0);
OLED_Show16x16(61,2,138,0);
OLED_Show16x16(47,4,139,0);
OLED_Show16x16(61,4,140,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 6:led3=1;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //清空
OLED_Show16x16(47,2,0,0);
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,4,0,0);
OLED_Show16x16(61,2,0,0); //清空
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(61,4,0,0);
OLED_Show16x16(77,4,0,0);break;
}
}
if(MOD==3)//猜拳训练
{
res0 = Cap_Calculate(0);//采集数据(原始数据)
res0 = res0-temp0;//电容接口空载减掉初始值
OLED_Show16x16(30,0,81,0);//猜
OLED_Show16x16(48,0,82,0);//拳
OLED_Show16x16(66,0,52,0);//训
OLED_Show16x16(84,0,53,0);//练
// OLED_Show16x16(0,2,45,0);//数
// OLED_Show16x16(18,2,46,0);//值
// OLED_Show16x16(36,2,18,0);//:
//
// OLED_Show16x16(0,6,0,0);//
// OLED_Show16x16(18,6,0,0);//
// OLED_Show16x16(36,6,0,0);
// OLED_Show16x16(54,6,0,0);
// OLED_Show16x16(72,6,0,0);//
// OLED_Show16x16(90,6,0,0);//
// OLED_Show16x16(108,6,0,0);//
// OLED_Show16x16(116,6,0,0);//
//
// Oled_Printf_Float(60,3,res0,0);
if(caiquan2>0&caiquan2<21) //石头
{ static int m=0;
m++;
if(m<21)
{
shu0=shu0+res0;
USART_SendData(USART1,caiquan2);
}
if(m>19)
{
shu0=shu0/20;
// caiquan1=0;
led3=0;
delay_ms(500);
led3=1;
// USART_SendData(USART1,shu0);
m=0;
caiquan2=22;
}
}
if(caiquan2>22&caiquan2<43) //剪刀
{ static int n=0;
n++;
if(n<21)
{
shu1=shu1+res0;
}
if(n>19)
{
shu1=shu1/20;
// caiquan2=0;
led4=0;
delay_ms(500);
led4=1;
// USART_SendData(USART1,shu1);
n=0;
caiquan2=44;
}
}
if(caiquan2>44&caiquan2<65) //布
{ static int p=0;
p++;
if(p<21)
{
shu2=shu2+res0;
// USART_SendData(USART1,shu2);
}
if(p>19)
{
shu2=shu2/20;
//caiquan3=0;
led5=0;
delay_ms(500);
led5=1;
// USART_SendData(USART1,shu2);
p=0;
caiquan2=0;
}
}
}
if(MOD==4)//划拳训练
{
res0 = Cap_Calculate(0);//采集数据(原始数据)
res0 = res0-temp0;//电容接口空载减掉初始值
OLED_Show16x16(30,0,70,0);//猜
OLED_Show16x16(48,0,71,0);//拳
OLED_Show16x16(66,0,52,0);//训
OLED_Show16x16(84,0,53,0);//练
//
// OLED_Show16x16(0,2,45,0);//数
// OLED_Show16x16(18,2,46,0);//值
// OLED_Show16x16(36,2,18,0);//:
//
//
// OLED_Show16x16(0,6,0,0);//
// OLED_Show16x16(18,6,0,0);//
// OLED_Show16x16(36,6,0,0);
// OLED_Show16x16(54,6,0,0);
// OLED_Show16x16(72,6,0,0);//
// OLED_Show16x16(90,6,0,0);//
// OLED_Show16x16(108,6,0,0);//
// OLED_Show16x16(116,6,0,0);//
//
// Oled_Printf_Float(60,3,res0,0);
if(caiquan3>0&caiquan3<21) //一
{ static int a=0;
a++;
if(a<21)
{
yi=yi+res0;
// USART_SendData(USART1,caiquan2);
}
if(a>19)
{
yi=yi/20;
// caiquan1=0;
led3=0;
delay_ms(500);
led3=1;
// USART_SendData(USART1,shu0);
a=0;
caiquan3=22;
}
}
if(caiquan3>22&caiquan3<43) //二
{ static int b=0;
b++;
if(b<21)
{
er=er+res0;
}
if(b>19)
{
er=er/20;
// caiquan2=0;
led4=0;
delay_ms(500);
led4=1;
// USART_SendData(USART1,shu1);
b=0;
caiquan3=44;
}
}
if(caiquan3>44&caiquan3<65) //三
{ static int c=0;
c++;
if(c<21)
{
san=san+res0;
// USART_SendData(USART1,shu2);
}
if(c>19)
{
san=san/20;
//caiquan3=0;
led5=0;
delay_ms(500);
led5=1;
// USART_SendData(USART1,shu2);
c=0;
caiquan3=66;
}
}
if(caiquan3>66&caiquan3<87) //四
{ static int d=0;
d++;
if(d<21)
{
si=si+res0;
// USART_SendData(USART1,shu2);
}
if(d>19)
{
si=si/20;
//caiquan3=0;
led5=0;
delay_ms(500);
led5=1;
// USART_SendData(USART1,shu2);
d=0;
caiquan3=88;
}
}
if(caiquan3>88&caiquan3<109) //五
{ static int e=0;
e++;
if(e<21)
{
wu=wu+res0;
// USART_SendData(USART1,shu2);
}
if(e>19)
{
wu=wu/20;
//caiquan3=0;
led5=0;
delay_ms(500);
led5=1;
// USART_SendData(USART1,shu2);
e=0;
caiquan3=0;
}
}
}
if(MOD==5)//猜拳判决
{
delay_ms(250);
res0 = Cap_Calculate(0);//采集数据(原始数据)
res0 =res0-temp0;//电容接口空载减掉初始值
OLED_Show16x16(30,0,81,0);//猜
OLED_Show16x16(48,0,82,0);//拳
OLED_Show16x16(66,0,87,0);//判
OLED_Show16x16(84,0,88,0);//决
//
// OLED_Show16x16(0,2,45,0);//数
// OLED_Show16x16(18,2,46,0);//值
// OLED_Show16x16(36,2,18,0);//:
//
//
// //清除上一屏显示内容
// //
// OLED_Show16x16(72,4,0,0);//
// OLED_Show16x16(0,6,0,0);//
// OLED_Show16x16(18,6,0,0);//
// OLED_Show16x16(36,6,0,0);//
// OLED_Show16x16(54,6,0,0);//
// OLED_Show16x16(72,6,0,0);//
// OLED_Show16x16(90,6,0,0);//
// OLED_Show16x16(108,6,0,0);//
// OLED_Show16x16(116,6,0,0);//
//
// Oled_Printf_Float(60,3,res0,0);
//Oled_Printf_Float(32,5,res1,0);
// printf("CH0:%3.3f CH1:%3.3f \r\n",res0,res1);
if(res0>shu2-0.50&res0<shu2+0.50)
{
i=1;
}
if(res0>shu1-0.50&res0<shu1+0.50)
{
i=3;
}
if(res0>shu0-0.50&res0<shu0+0.50)
{
i=2;
}
if(res0<0.50)
{
i=4;
}
switch(i)
{
case 1:led3=0;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //布
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,111,0);
OLED_Show16x16(61,2,112,0);
OLED_Show16x16(47,4,113,0); //布
OLED_Show16x16(61,4,114,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 2:led3=1;
led4=0;
led5=1;
OLED_Show16x16(31,2,95,0);
OLED_Show16x16(47,2,96,0);
OLED_Show16x16(31,4,97,0);
OLED_Show16x16(47,4,98,0);//石
OLED_Show16x16(61,2,99,0);
OLED_Show16x16(77,2,100,0);
OLED_Show16x16(61,4,101,0); //头
OLED_Show16x16(77,4,102,0);break;
case 3:led3=1;
led4=1;
led5=0;
OLED_Show16x16(31,2,103,0);
OLED_Show16x16(47,2,104,0);
OLED_Show16x16(31,4,105,0);
OLED_Show16x16(47,4,106,0);//剪
OLED_Show16x16(61,2,107,0);
OLED_Show16x16(77,2,108,0);
OLED_Show16x16(61,4,109,0); //刀
OLED_Show16x16(77,4,110,0);break;
case 4:led3=1;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //空
OLED_Show16x16(47,2,0,0);
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,4,0,0);
OLED_Show16x16(61,2,0,0); //空
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(61,4,0,0);
OLED_Show16x16(77,4,0,0);break;
}
}
if(MOD==6)//划拳判决
{
delay_ms(250);
res0 = Cap_Calculate(0);//采集数据(原始数据)
res0 = res0-temp0;//电容接口空载减掉初始值
OLED_Show16x16(30,0,83,0);//划
OLED_Show16x16(48,0,84,0);//拳
OLED_Show16x16(66,0,87,0);//判
OLED_Show16x16(84,0,88,0);//决
// OLED_Show16x16(0,2,45,0);//数
// OLED_Show16x16(18,2,46,0);//值
// OLED_Show16x16(36,2,18,0);//:
//
//
// //清除上一屏显示内容
// //
//
// OLED_Show16x16(0,6,0,0);//
// OLED_Show16x16(18,6,0,0);//
// OLED_Show16x16(36,6,0,0);//
// OLED_Show16x16(54,6,0,0);//
// OLED_Show16x16(72,6,0,0);//
// OLED_Show16x16(90,6,0,0);//
// OLED_Show16x16(108,6,0,0);//
// OLED_Show16x16(116,6,0,0);//
//
//
// Oled_Printf_Float(60,3,res0,0);
//Oled_Printf_Float(32,5,res1,0);
printf("CH0:%3.3f CH1:%3.3f \r\n",res0,res1);
if(res0>yi-0.3&res0<yi+0.3)//2.2 2.4
{
i=1;
}
if(res0>er-0.5&res0<er+0.3)//3.4 3.7
{
i=2;
}
if(res0>san-0.3&res0<san+0.3)//4 4.5
{
i=3;
}
if(res0>si-0.5&res0<si+0.5) // 5.8
{
i=4;
}
if(res0>wu-0.2)//5.8
{
i=5;
}
if(res0<1.0)
{
i=6;
}
switch(i)
{
case 1:led3=0;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //一
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,121,0);
OLED_Show16x16(61,2,122,0);
OLED_Show16x16(47,4,123,0);
OLED_Show16x16(61,4,124,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 2:led3=1;
led4=0;
led5=1;
OLED_Show16x16(31,2,0,0); //二
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,125,0);
OLED_Show16x16(61,2,126,0);
OLED_Show16x16(47,4,127,0);
OLED_Show16x16(61,4,128,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 3:led3=1;
led4=1;
led5=0;
OLED_Show16x16(31,2,0,0); //三
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,129,0);
OLED_Show16x16(61,2,130,0);
OLED_Show16x16(47,4,131,0);
OLED_Show16x16(61,4,132,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 4:led3=0;
led4=0;
led5=1;
OLED_Show16x16(31,2,0,0); //四
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,133,0);
OLED_Show16x16(61,2,134,0);
OLED_Show16x16(47,4,135,0);
OLED_Show16x16(61,4,136,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 5:led3=0;
led4=1;
led5=0;
OLED_Show16x16(31,2,0,0); //五
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,2,137,0);
OLED_Show16x16(61,2,138,0);
OLED_Show16x16(47,4,139,0);
OLED_Show16x16(61,4,140,0);
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(77,4,0,0);break;
case 6:led3=1;
led4=1;
led5=1;
OLED_Show16x16(31,2,0,0); //清空
OLED_Show16x16(47,2,0,0);
OLED_Show16x16(31,4,0,0);
OLED_Show16x16(47,4,0,0);
OLED_Show16x16(61,2,0,0); //清空
OLED_Show16x16(77,2,0,0);
OLED_Show16x16(61,4,0,0);
OLED_Show16x16(77,4,0,0);break;
}
}
}
}
void Sys_Init(void)
{
delay_init();
NVIC_Configuration();
uart_init(115200); //串口波特率115200
LED_Init();
OLED_Init();
// printf("OLED OK\r\n");
OLED_Show16x16(14,0,115,0);
OLED_Show16x16(31,0,116,0);
OLED_Show16x16(48,0,117,0);
OLED_Show16x16(65,0,118,0);
OLED_Show16x16(82,0,119,0);
OLED_Show16x16(99,0,120,0);
delay_ms(1000);
OLED_CLS();
while(FDC2214_Init());
led1=0;
delay_ms(100);
temp0 = Cap_Calculate(0);//读取初始值
temp1 = Cap_Calculate(1);
}
复制代码
简单队.7z
2019-9-6 19:16 上传
点击文件名下载附件
下载积分: 黑币 -5
212.16 KB, 下载次数: 21, 下载积分: 黑币 -5
作者:
爱电电子
时间:
2020-1-5 18:13
请问楼主实物咋接线
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1