這個板塊沒有51熱鬧,但是編程簡單,可以有更多的精力去創意,其實沒有創意和靈魂的東西永遠不會成為經典。
制作出來的實物圖如下:
20181124_213554.jpg (281.98 KB, 下載次數: 56)
下載附件
2018-11-24 21:46 上傳
20181124_213814.jpg (342.19 KB, 下載次數: 57)
下載附件
2018-11-24 21:46 上傳
20181124_213840.jpg (319.6 KB, 下載次數: 53)
下載附件
2018-11-24 21:46 上傳
20181124_213625.jpg (315.56 KB, 下載次數: 61)
下載附件
2018-11-24 21:46 上傳
20181124_213857.jpg (302.4 KB, 下載次數: 65)
下載附件
2018-11-24 21:46 上傳
Arduino程序源碼:
- #define ENCODER_A_PIN 2
- #define ENCODER_B_PIN 3
- #define SWITCH_PIN 4
- long position;//
- int latchPin = 8;//RS
- int dataPin = 9;//RW
- int clockPin =10;//EN
- unsigned char tabe[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//查表法//0-9數字
- void setup()
- {
- //setup our pins 初始化我們的需要的引腳
- pinMode(ENCODER_A_PIN, INPUT);
- pinMode(ENCODER_B_PIN, INPUT);
- pinMode(SWITCH_PIN, INPUT);
- attachInterrupt(0, read_quadrature, CHANGE);
- pinMode(latchPin, OUTPUT); //設置引腳為輸出
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- Lcdint( );//lcd
- }
- ////////////////////////////寫SPI時序,具體參考shiftout 命令使用/////////////////////////////
- void WriteByte(int dat)
- {
- digitalWrite(latchPin, HIGH);
- shiftOut(dataPin, clockPin, MSBFIRST, dat);
- digitalWrite(latchPin, LOW);
- }
- ///////////////////寫命令/////////////////////////////////////
- void LcdCommandWrite(int value) {
- int H_data,L_data;
- H_data = value;
- H_data &= 0xf0; //屏蔽低4位的數據
- L_data = value; //xxxx0000格式
- L_data &= 0x0f; //屏蔽高4位的數據
- L_data <<= 4; //xxxx0000格式
- WriteByte(0xf8); //RS=0,寫入的是指令;
- WriteByte(H_data);
- WriteByte(L_data);
- }
- //////////////////////寫數據/////////////////////////////////////
- void LcdDataWrite(int value) {
- int H_data,L_data;
- H_data = value;
- H_data &= 0xf0; //屏蔽低4位的數據
- L_data = value; //xxxx0000格式
- L_data &= 0x0f; //屏蔽高4位的數據
- L_data <<= 4; //xxxx0000格式
- WriteByte(0xfa); //RS=1,寫入的是數據
- WriteByte(H_data);
- WriteByte(L_data);
- }
- ////////////////////// /////////////////////////////////////
- void Lcdint(void)
- {
- LcdCommandWrite(0x30); // 設定為基本指令
- delay(5);
- LcdCommandWrite(0x03); // //允許輸入卷動位址
- delay(5);
- LcdCommandWrite(0x0c); // //脫離隨眠狀態,顯示打開,關光標,反白關.
- delay(5);
- LcdCommandWrite(0x01); // 清屏指令.
- delay(5);
- LcdCommandWrite(0x06); // AC自動加一,光標右移,整體顯示不移動
- delay(5);
- }
- void LCD_zfc(char *p)//定義一個帶指針的函數?(字符串)
- {
- while(*p!=0)//不能用";"
- LcdDataWrite(*p++);
- }
- <font style="font-size: 36.9444px"> /************************顯示1 *********************************/ </font>
- void display1(void)
- {
- int dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
- long temp ; //存放溫度值的10倍=12345678;
- temp=position;//旋轉
- //temp=12345678;
- dt1 = temp%10;//1位
- dt2 = temp%100/10;//2位
- dt3 = temp%1000/100;//3位
- dt4 = temp%10000/1000;//4位
- dt5 = temp%100000/10000;//5位
- dt6 = temp%1000000/100000;//6位
- dt7 = temp%10000000/1000000;//7位
- dt8 = temp/10000000;//8位 最高位
-
- LcdCommandWrite(0x98);//LCD12864_W ((0或1),****) 0寫指令 1寫數據
- // 0xCE,0xC2,0xB6,0xC8
- LcdDataWrite(0xd0 );
- LcdDataWrite(0xfd );
- LcdDataWrite(0xd7 );
- LcdDataWrite(0xaa );
- LcdDataWrite(0x3a);// .
- // LcdDataWrite(tabe[dt8]);//8位
- //LcdDataWrite(tabe[dt7]);//7位
- // LcdDataWrite(tabe[dt6]);//6位
- //LcdDataWrite(tabe[dt5]);//5位
- LcdDataWrite(tabe[dt4]);//4位
- LcdDataWrite(tabe[dt3]);//3位
- //LcdDataWrite(0x2e);// .....
- LcdDataWrite(tabe[dt2]);//2位
- LcdDataWrite(tabe[dt1]);//1位
- LCD_zfc(" R");
- }
- void read_quadrature()
- {
- if (digitalRead(ENCODER_A_PIN) == LOW)
- {
- if (digitalRead(ENCODER_B_PIN) == LOW)
- position++;
- if(position>1000)position=1000;
- }
- else
- {
- if (digitalRead(ENCODER_B_PIN) == LOW)
- position--;
- if(position<0)position=0;
- }
- if (digitalRead( SWITCH_PIN ) == LOW)
- {
- position=0;
- }
- }
- void loop()
- {
- display1();//旋轉
- read_quadrature();
- }
復制代碼
全部資料51hei下載地址:
128顯旋轉編碼器OK2.zip
(2.07 KB, 下載次數: 30)
2018-11-24 21:46 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|