【C】MSP432P401R手动实现呼吸灯斗艳
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
//设定用于斗艳的LED灯的端口和管脚
#define led1 GPIO_PORT_P1,GPIO_PIN0
#define led2 GPIO_PORT_P2,GPIO_PIN2
void light(int );
void delay(int );
void main(void)
{
GPIO_setAsOutputPin(led1);
GPIO_setAsOutputPin(led2);
//设置七种明暗等级,共13种状态转换
int level[]={24,20,16,12,8,4,0,4,8,12,16,20,24};
int i=0,j,len=13;
while(1)
{
for(i=0;i<len;i++)
for(j=0;j<10;j++)//使变化流畅
light(level[i]);
}
}
//通过控制延时长度不同产生明暗差异
void light(int level){
GPIO_setOutputHighOnPin(led1);
GPIO_setOutputLowOnPin(led2);
delay(level);
GPIO_setOutputLowOnPin(led1);
GPIO_setOutputHighOnPin(led2);
delay(24-level);
}
void delay(int time){
int i=320*time;
while(i--) ;
}