今天接着对遥控器打码进行完善。
目前已经可以实现遥控器的显示及选择,其中用到了旋转编码器选择;
操作界面设计如下:
通过代码完善不断实现以下功能:
操作方法为:
1 按键 SW1 和 SW2为确认键;
2 F键为返回键,E键为回主页;
3 电动时,DB控制左右,AC控制上下,EF控住旋转;同时摇杆也可控,值越大速度越快;
4 旋钮和按键控制光标上下。
接收器如下图所示:
代码如下:
// RF24 - Version: 1.3.4
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
#include <Arduino.h>
#include <A4988.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//无线需要的头文件
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#define clk A2
#define data A3
#define sw 8
//无线接口定义如下:
/*nRF24L01 Arduino UNO
VCC <-> 3.3V
GND <-> GND
CE <-> D9
CSN <-> D10
MOSI<-> D11
MISO<-> D12
SCK <-> D13
IRQ <-> 不接
*/
volatile boolean TurnDetected;
volatile boolean up;
int dir;
int arrow;
int mode;
int rpm;
int minutes;
int minrpm;
int State;
int counter;
int LastState;
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte customChar1[8] = {
0b10000,
0b11000,
0b11100,
0b11110,
0b11110,
0b11100,
0b11000,
0b10000
};
byte customChar2[8] = {
0b00100,
0b01110,
0b11111,
0b00000,
0b00000,
0b11111,
0b01110,
0b00100,
};
void setup() {
lcd.init();
lcd.backlight();
lcd.begin(16, 2);
lcd.createChar(0, customChar1);
lcd.createChar(1,