之前运用PS2实现遥控,这次通过自己设计并制作了一个原创遥控。
所需材料:STM32F103C8、摇杆、OLED 显示器、NRF24L01、电池、导线。
引脚使用:
附上代码:
#include "stm32f10x.h"
#include "adc.h"
#include "led.h"
#include "key.h"
#include "delay.h"
#include "sys.h"
#include "oled.h"
#include "spi.h"
#include "24l01.h"
int main(void)
{
u8 t0,t1,tmp_buf[3],i;
u16 adcx0,adcx1,adcx2,adcx3;
delay_init();
NVIC_Configuration();
SystemInit();
NRF24L01_Init();
Adc_Init();
LEDA_GPIO_Config();
KEY_Init();
OLED_Init();
t0=' ';
for(i=0;i<3;i++)
tmp_buf[i]=i;
while(NRF24L01_Check())
{
OLED_Clear();
OLED_ShowString(6,4,"0.96' OLED TEST",16);
OLED_ShowString(0,0,"Error",16);
}
OLED_Clear();
OLED_ShowString(0,0,"OK",16);
NRF24L01_TX_Mode();
delay_ms(1000);
while (1)
{
t1=KEY_Scan(0);
switch(t1)
{
case KEY0_PRES:
GPIO_ResetBits(GPIOC, GPIO_Pin_13);
break;
case KEY1_PRES:
GPIO_SetBits(GPIOC, GPIO_Pin_13);
break;
default:
delay_ms(10);
}
adcx0=Get_Adc_Average(ADC_Channel_0,10);
adcx1=Get_Adc_Average(ADC_Channel_1,10);
adcx2=Get_Adc_Average(ADC_Channel_2,10);
adcx3=Get_Adc_Average(ADC_Channel_3,10);
if(adcx1>=3000)
tmp_buf[0]=128;
else
tmp_buf[0]=0;
OLED_ShowNum(32,0,adcx0,4,16);//显示ASCII字符的码值
OLED_ShowNum(72,0,adcx1,4,16);//显示ASCII字符的码值
OLED_ShowNum(0,2,adcx2,4,16);//显示ASCII字符的码值
OLED_ShowNum(64,2,adcx3,4,16);//显示ASCII字符的码值
// OLED_ShowChar(48,6,t0,16);//显示ASCII字符
// t0++;
// if(t0>'~')t=' ';
while(NRF24L01_TxPacket(tmp_buf)!=TX_OK)
{
OLED_ShowString(0,6,"Failed",16);
}
OLED_ShowString(0,6,"Succeed",16);
}
}