标题:
使用ardiuno检测16位旋转拨码开关方法(摇杆操作)
[打印本页]
作者:
produce
时间:
2024-6-7 16:02
标题:
使用ardiuno检测16位旋转拨码开关方法(摇杆操作)
使用摇杆操作1602显示屏检测16位旋转拨码盘指数是否正常
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x3F,16,2);
int type = 0 ;
void setup() {
// 初始化串口通信
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
pinMode(6,INPUT_PULLUP);
pinMode(7,OUTPUT);
}
void loop() {
// 读取X轴和Y轴的模拟值
int xValue = analogRead(A0);
int yValue = analogRead(A1);
bool value_in=digitalRead(2);
bool value8=digitalRead(3);
bool value2=digitalRead(4);
bool value1=digitalRead(5);
bool value4=digitalRead(6);
int level=0;
char* i[] ={"rest 1/4","6 digital 2/4","7 digital 3/4","8 digital 4/4"} ;
int t = value_in;
lcd.setCursor(0,0); //设置显示指针
lcd.print("bomapan ceshi");
if(yValue>900)
{
type--;
if(type<0)
{
type = 0;
}
delay(100);
}
if(yValue<20)
{
type++;
if(type>3)
{
type = 3;
}
delay(100);
}
lcd.setCursor(0,1); //设置显示指针
lcd.print(i[type]);
if(type==2 && value_in==0 && level==0 && t==0)
{
if(value1==0 && value2==0 && value4==0 && value8==1)
{
lcd.setCursor(13,1);
lcd.print("yes");
if(value_in!=t)
{
level = 1;
t=value_in;
}
}
else
{
lcd.setCursor(13,1); //设置显示指针
lcd.print(" no");
}
}
if(type==3 && value_in==0 && level==0 && t==0)
{
if(value1==1 && value2==1 && value4==1 && value8==0)
{
lcd.setCursor(13,1);
lcd.print("yes");
if(value_in!=t)
{
level = 1;
t=value_in;
}
}
else
{
lcd.setCursor(13,1); //设置显示指针
lcd.print(" no");
}
}
if(type==1 && value_in==0 && level==0 && t==0)
{
if(value1==1 && value2==0 && value4==0 && value8==1)
{
lcd.setCursor(13,1);
lcd.print("yes");
if(value_in!=t)
{
level = 1;
t=value_in;
}
}
else
{
lcd.setCursor(13,1); //设置显示指针
lcd.print(" no");
}
}
if(type==0 && value_in==0)
{
t=0;
level=0;
}
delay(200);
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1