//定义按键的值
#define RAW 11
#define SINE_FM 1
#define SINE_AM 2
#define PWM 3
#define SQUARE_WAVE_FM 4
#define SQUARE_WAVE_AM 5
int g_key_val=RAW;
int g_keyIndex=0;
int sin_table[512];int index_sinTable=0;
//int pwm_table[256],index_pwmTable=0;
int square_table[256],index_squareTable;
int numTimeFreq=1;
int samplePoint=512;
int g_value=0;
int g_analog=0;
unsigned lastTime=0;
int lastTime1=0;
int g_pwmValue=100;
int halfCycleTime=0;
int totalPoints=0;
int highPoints=0;
int g_index_points=0;
int m1=0;
int m2=0;
int time2_count_my=0;
unsigned long currentTime=0;
int key[]={RAW,SINE_FM,SINE_AM,
PWM,SQUARE_WAVE_FM,SQUARE_WAVE_AM
};
/* 产生正弦波表 放入m_table,表中有n个元素*/
void createSinTable(int sin_table[],int samplePoint){
for(int i=0; i=samplePoint){
index_sinTable=0;
}
sendToSerial(g_value); //发送数据到串口
break;
case SINE_AM:
//table中的值(0,200)-->(0,200)内其它值
//用固定freq,
g_value=(cos(2*PI/512*index_sinTable)+1)*g_analog/2;
index_sinTable+=numTimeFreq; //numTimeFreq=1
if(index_sinTable>=512){
index_sinTable=0;
}
//Serial.println(g_value); //调试之用
sendToSerial(g_value); //发送数据到串口
break;
case PWM:
//固定g_value
//固定freq
//L+H=600;
for(int i=0; i