“(SKU:RB-05L007)LCD4884液晶搖桿擴展板”的版本間的差異

來自ALSROBOT WiKi
跳轉(zhuǎn)至: 導(dǎo)航搜索
?例子程序
?例子程序
 
(未顯示1個用戶的1個中間版本)
第28行: 第28行:
 
* USB數(shù)據(jù)通信線×1
 
* USB數(shù)據(jù)通信線×1
 
===例子程序===
 
===例子程序===
?
程序上傳前需要先[http://pan.baidu.com/s/1gdg4omv 點此下載]LCD4884 程序使用到的庫文件,將它放到Arduino安裝目錄下的libraries文件夾下.<br/>
+
程序上傳前需要先下載鏈接:https://pan.baidu.com/s/1rZRC6a2eQGpZs_oCbAPEuw?pwd=n7yp
?
<big><big>'''注意:LCD4884液晶顯示模塊不能與1.6以上版本的IDE兼容,需要使用老版本的IDE進行編譯,例如:1.0.4、1.0.5<br/>
+
提取碼:n7yp LCD4884 程序使用到的庫文件,將它放到Arduino安裝目錄下的libraries文件夾下<br/>
?
老版本IDE下載地址:http://www.arduino.cc/en/Main/OldSoftwareReleases'''</big></big>
+
 
<pre style='color:blue'>
 
<pre style='color:blue'>
?
#include "LCD4884.h"
+
/* YourDuinoStarter Example: LCD SHIELD with 'Joystick' button
?
#include "Robotbase_bmp.h"
+
- WHAT IT DOES Displays on LCD4884, reads button
?
#include "Robotbase.h"
+
- SEE the comments after "//" on each line below
?
//keypad debounce parameter
+
  - CONNECTIONS:
?
#define DEBOUNCE_MAX 15
+
  - LCD 4884 Shield has all connections
?
#define DEBOUNCE_ON 10
+
  -
?
#define DEBOUNCE_OFF 3
+
  NOTE: Start Serial Monitor to see switch voltage values
?
#define NUM_KEYS 5
+
  - V1.00 02/08/2016
?
#define NUM_MENU_ITEM 4
+
  Questions: terry@yourduino.com */
?
// joystick number
+
?
#define LEFT_KEY 0
+
?
#define CENTER_KEY 1
+
?
#define DOWN_KEY 2
+
?
#define RIGHT_KEY 3
+
?
#define UP_KEY 4
+
?
// menu starting points
+
?
#define MENU_X 10 // 0-83
+
?
#define MENU_Y 1 // 0-5
+
?
int analogPin = 1;
+
?
int ADC_result = 0;
+
?
char qian = 0,bai = 0,shi = 0,ge = 0;
+
?
int adc_key_val[5] ={ 50, 200, 400, 600, 800 };
+
?
// debounce counters
+
?
byte button_count[NUM_KEYS];
+
?
// button status - pressed/released
+
?
byte button_status[NUM_KEYS];
+
?
// button on flags for user program
+
?
byte button_flag[NUM_KEYS];
+
  
?
// menu definition
+
/*-----( Import needed libraries )-----*/
?
char menu_items[NUM_MENU_ITEM][12]={
+
#include <LCD4884.h>  // UPDATED version 2/16 Yourduino
?
  "Temperature",
+
/*-----( Declare Constants and Pin Numbers )-----*/
?
  " Char Map ",
+
#define LCD_BACKLIGHT_PIN 7
?
  "  Picture  ",
+
 
?
  "  About  "
+
/*-----( Declare objects )-----*/
?
};
+
//None: Included in library
?
void (*menu_funcs[NUM_MENU_ITEM])(void) = {
+
/*-----( Declare Variables )-----*/
?
  temperature,
+
int displayDelay = 1000;
?
  charmap,
+
int switchDelay  = 100; // Switch scanning delay
?
  bitmap,
+
int switchVoltage ;   // From Analog read of the button resistors
?
  about
+
 
?
};
+
void setup()   /****** SETUP: RUNS ONCE ******/
?
char current_menu_item;
+
?
void setup()
+
 
{
 
{
?
   // setup interrupt-driven keypad arrays 
+
   Serial.begin(115200);
?
   // reset button arrays
+
  pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
?
   for(byte i=0; i<NUM_KEYS; i++){
+
  lcd.LCD_init(); // creates instance of LCD
?
     button_count[i]=0;
+
   lcd.LCD_clear(); // blanks the display
?
     button_status[i]=0;
+
   for (int a = 0; a < 5; a++)
?
     button_flag[i]=0;
+
  {
 +
     digitalWrite(LCD_BACKLIGHT_PIN, LOW);
 +
     delay(300);
 +
     digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
 +
    delay(300);
 
   }
 
   }
?
   // Setup timer2 -- Prescaler/256
+
   for (int a = 0; a < 6; a++)
?
  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
+
   {
?
  TCCR2B &= ~(1<<WGM22);
+
     lcd.LCD_write_string(0, a, "01234567980123", MENU_NORMAL); // ignore MENU_NORMAL for now
?
  TCCR2B = (1<<CS22)|(1<<CS21);     
+
    delay(displayDelay);
?
  ASSR |=(0<<AS2);
+
?
  // Use normal mode 
+
?
  TCCR2A =0;   
+
?
  //Timer2 Overflow Interrupt Enable 
+
?
  TIMSK2 |= (0<<OCIE2A);
+
?
  TCNT2=0x6;  // counting starts from 6;
+
?
  TIMSK2 = (1<<TOIE2);   
+
?
   SREG|=1<<SREG_I;
+
?
  lcd.LCD_init();
+
?
  lcd.LCD_clear();
+
?
  //menu initialization
+
?
  init_MENU();
+
?
  current_menu_item = 0;
+
?
  lcd.backlight(ON);//Turn on the backlight
+
?
  //lcd.backlight(OFF); // Turn off the backlight 
+
?
}
+
?
/* loop */
+
?
void loop()
+
?
{
+
?
  byte i;
+
?
  for(i=0; i<NUM_KEYS; i++){
+
?
     if(button_flag[i] !=0){
+
?
      button_flag[i]=0;  // reset button flag
+
?
      switch(i){
+
?
      case UP_KEY:
+
?
        // current item to normal display
+
?
        lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
+
?
        current_menu_item -=1;
+
?
        if(current_menu_item <0)  current_menu_item = NUM_MENU_ITEM -1;
+
?
        // next item to highlight display
+
?
        lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
+
?
        break;
+
?
      case DOWN_KEY:
+
?
        // current item to normal display
+
?
        lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
+
?
        current_menu_item +=1;
+
?
        if(current_menu_item >(NUM_MENU_ITEM-1))  current_menu_item = 0;
+
?
        // next item to highlight display
+
?
        lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
+
?
        break;
+
?
      case LEFT_KEY:
+
?
        init_MENU();
+
?
        current_menu_item = 0;
+
?
        break; 
+
?
      case CENTER_KEY:
+
?
        lcd.LCD_clear();
+
?
        (*menu_funcs[current_menu_item])();
+
?
        lcd.LCD_clear();
+
?
        init_MENU();
+
?
        current_menu_item = 0;         
+
?
        break;
+
?
      }
+
?
    }
+
 
   }
 
   }
?
}
+
  delay(displayDelay);
?
/* menu functions */
+
   lcd.LCD_clear();   // blanks the display
?
void init_MENU(void){
+
   delay(500);
?
  byte i;
+
   // Show the BIG characters (0..9, + - only)
?
   lcd.LCD_clear();
+
  lcd.LCD_write_string_big(0, 0, "012345", MENU_NORMAL);
?
   lcd.LCD_write_string(MENU_X, MENU_Y, menu_items[0], MENU_HIGHLIGHT );
+
   lcd.LCD_write_string_big(0, 3, "-+-+-+", MENU_NORMAL);
?
   for (i=1; i<NUM_MENU_ITEM; i++){
+
   delay(1000);
?
    lcd.LCD_write_string(MENU_X, MENU_Y+i, menu_items[i], MENU_NORMAL);
+
  lcd.LCD_clear();  // now  read the joystick using analogRead(0
?
   }
+
 
?
}
+
}//--(end setup )---
?
// waiting for center key press
+
 
?
void waitfor_OKkey(){
+
 
?
  byte i;
+
void loop()   /****** LOOP: RUNS CONSTANTLY ******/
?
   byte key = 0xFF;
+
?
  while (key!= CENTER_KEY){
+
?
    for(i=0; i<NUM_KEYS; i++){
+
?
      if(button_flag[i] !=0){
+
?
        button_flag[i]=0;  // reset button flag
+
?
        if(i== CENTER_KEY) key=CENTER_KEY;
+
?
      }
+
?
    }
+
?
  }
+
?
}
+
?
void temperature()
+
 
{
 
{
?
   byte i;
+
   lcd.LCD_write_string(1, 1, "PUSH A BUTTON", MENU_NORMAL);
?
  byte key = 0xFF;
+
  switchVoltage = analogRead(0);
?
  while (key!= CENTER_KEY){
+
  Serial.print("Switch analog value = ");
?
    ADC_result = analogRead(analogPin);
+
  Serial.println(switchDelay);
?
    qian = ADC_result / 1000;
+
 
?
    bai = ADC_result % 1000 / 100;
+
  if (switchVoltage == 0)
?
    shi = ADC_result % 1000 % 100 / 10;
+
  {
?
    ge = ADC_result % 10;
+
     lcd.LCD_write_string(2, 2, "LEFT ", MENU_NORMAL);
?
    lcd.LCD_write_char_big(10, 1, '+', MENU_NORMAL);
+
?
    lcd.LCD_write_char_big(22, 1, qian-48, MENU_NORMAL);
+
?
    lcd.LCD_write_char_big(35, 1, bai-48, MENU_NORMAL);
+
?
    lcd.LCD_write_char_big(48, 1, '.', MENU_NORMAL);
+
?
    lcd.LCD_write_char_big(51, 1, shi-48, MENU_NORMAL);
+
?
    lcd.LCD_write_char_big(64, 1, ge-48, MENU_NORMAL);
+
?
     lcd.LCD_write_string(78, 2, "C", MENU_NORMAL);
+
?
    lcd.LCD_write_string(36, 5, "OK", MENU_HIGHLIGHT );
+
?
    for(i=0; i<NUM_KEYS; i++){
+
?
      if(button_flag[i] !=0){
+
?
        button_flag[i]=0;  // reset button flag
+
?
        if(i== CENTER_KEY) key=CENTER_KEY;
+
?
      }
+
?
    }
+
 
   }
 
   }
?
}
+
   else if (switchVoltage > 0 && switchVoltage < 180)
?
void charmap(){
+
  {
?
  char i,j;
+
     lcd.LCD_write_string(2, 2, "PUSH IN", MENU_NORMAL);
?
   for(i=0; i<5; i++){
+
    delay(switchDelay);
?
     for(j=0; j<14; j++){
+
?
      lcd.LCD_set_XY(j*6,i);
+
?
      lcd.LCD_write_char(i*14+j+32, MENU_NORMAL);
+
?
    }
+
 
   }
 
   }
?
   lcd.LCD_write_string(36, 5, "OK", MENU_HIGHLIGHT );
+
   else if (switchVoltage > 180 && switchVoltage < 400)
?
  waitfor_OKkey(); 
+
?
}
+
?
void bitmap(){
+
?
  lcd.LCD_draw_bmp_pixel(0,0, Robotbase_bmp, 84,24);
+
?
  lcd.LCD_write_chinese(12,3, Robotbase_chinese,12,5,0,0);
+
?
  lcd.LCD_write_string(36, 5, "OK", MENU_HIGHLIGHT );
+
?
  waitfor_OKkey();
+
?
}
+
?
void about(){
+
?
  lcd.LCD_write_string( 0, 0, "LCD4884 Shield", MENU_NORMAL);
+
?
  lcd.LCD_write_string( 32, 1, "www", MENU_NORMAL);
+
?
  lcd.LCD_write_string( 10, 2, ".robotbase.", MENU_NORMAL);
+
?
  lcd.LCD_write_string( 35, 3, "cn", MENU_NORMAL);
+
?
  lcd.LCD_write_string(36, 5, "OK", MENU_HIGHLIGHT );
+
?
  waitfor_OKkey();
+
?
}
+
?
// The followinging are interrupt-driven keypad reading functions
+
?
// which includes DEBOUNCE ON/OFF mechanism, and continuous pressing detection
+
?
// Convert ADC value to key number
+
?
char get_key(unsigned int input)
+
?
{
+
?
  char k;
+
?
  for (k = 0; k < NUM_KEYS; k++)
+
 
   {
 
   {
?
     if (input < adc_key_val[k])
+
     lcd.LCD_write_string(2, 2, "DOWN ", MENU_NORMAL);
?
    {
+
     delay(switchDelay);
?
      return k;
+
?
     }
+
 
   }
 
   }
?
   if (k >= NUM_KEYS)
+
   else if (switchVoltage > 400 && switchVoltage < 600)
?
    k = -1;    // No valid key pressed
+
?
  return k;
+
?
}
+
?
void update_adc_key(){
+
?
  int adc_key_in;
+
?
  char key_in;
+
?
  byte i;
+
?
  adc_key_in = analogRead(0);
+
?
  key_in = get_key(adc_key_in);
+
?
  for(i=0; i<NUM_KEYS; i++)
+
 
   {
 
   {
?
     if(key_in==i) //one key is pressed
+
     lcd.LCD_write_string(2, 2, "RIGHT", MENU_NORMAL);
?
    {
+
     delay(switchDelay);
?
      if(button_count[i]<DEBOUNCE_MAX)
+
?
      {
+
?
        button_count[i]++;
+
?
        if(button_count[i]>DEBOUNCE_ON)
+
?
        {
+
?
          if(button_status[i] == 0)
+
?
          {
+
?
            button_flag[i] = 1;
+
?
            button_status[i] = 1; //button debounced to 'pressed' status
+
?
          }
+
?
        }
+
?
      }
+
?
     }
+
?
    else // no button pressed
+
?
    {
+
?
      if (button_count[i] >0)
+
?
      { 
+
?
        button_flag[i] = 0;
+
?
        button_count[i]--;
+
?
        if(button_count[i]<DEBOUNCE_OFF){
+
?
          button_status[i]=0;  //button debounced to 'released' status
+
?
        }
+
?
      }
+
?
    }
+
 
   }
 
   }
?
}
+
  else if (switchVoltage > 600 && switchVoltage < 800)
?
// Timer2 interrupt routine -
+
  {
?
// 1/(160000000/256/(256-6)) = 4ms interval
+
    lcd.LCD_write_string(2, 2, "UP  ", MENU_NORMAL);
 +
    delay(switchDelay);
 +
  }
 +
  else if (switchVoltage > 800)              {
 +
    lcd.LCD_write_string(2, 2, "NONE    ", MENU_NORMAL);
 +
    delay(switchDelay);
 +
  }
 +
 
 +
//--(end main loop )---
 +
 
 +
/*-----( Declare User-written Functions )-----*/
 +
//NONE
  
?
ISR(TIMER2_OVF_vect)
+
//*********( THE END )***********
?
  TCNT2  = 6;
+
?
  update_adc_key();
+
?
}
+
 
</pre>
 
</pre>
  

2023年11月18日 (六) 13:27的最后版本


Faef1.jpg

目錄

產(chǎn)品概述

最新推出的LCD4884 LCD Joystick Shield v2.0 LCD4884液晶屏擴展板是哈爾濱奧松機器人科技有限公司研發(fā)的一款黑白屏液晶擴展板。此擴展板采用Nokia 5110液晶屏為顯示器件。SPI接口,最大限度的節(jié)省I/O資源。特別添加五向搖桿,方便實現(xiàn)搭建人機互動接口,剩余的模擬與數(shù)字接口全部用插針引出,便于安裝其它傳感器與模塊。本品適用于各種開發(fā)板和控制器,例如:Arduino控制器、STC單片機、AVR單片機等。

規(guī)格參數(shù)

  1. 產(chǎn)品名稱:LCD4884液晶搖桿擴展板
  2. 產(chǎn)品貨號:RB-05L007
  3. 工作電壓:DC5V
  4. 產(chǎn)品類型:Arduino擴展板
  5. 制作工藝:FR4雙面噴錫
  6. 人性化設(shè)計:具有可人機互動接口“五項搖桿”
  7. 工作溫度:10℃-30℃
  8. 重量:28g
  9. 產(chǎn)品尺寸:69.47mm x 53.34mm x 18mm
  10. 發(fā)貨清單:LCD4884液晶搖桿擴展板×1
  11. 包裝方式:靜電袋密封
  12. 選配配件:3PIN傳感器連接線、Arduino 328控制器等
  13. 板載資源:
  • 數(shù)字接口:8個
  • 模擬輸入借口:5個
  • 48×84液晶:1個
  • 無向搖桿按鍵:1個
  • 系統(tǒng)復(fù)位按鍵:1個

使用方法

使用硬件

  • Carduino UNO 控制器 * 1個
  • LCD4884 Joystick Shield ×1
  • USB數(shù)據(jù)通信線×1

例子程序

程序上傳前需要先下載鏈接:https://pan.baidu.com/s/1rZRC6a2eQGpZs_oCbAPEuw?pwd=n7yp 提取碼:n7yp LCD4884 程序使用到的庫文件,將它放到Arduino安裝目錄下的libraries文件夾下

/* YourDuinoStarter Example: LCD SHIELD with 'Joystick' button
 - WHAT IT DOES Displays on LCD4884, reads button
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
   - LCD 4884 Shield has all connections
   -
   NOTE: Start Serial Monitor to see switch voltage values
 - V1.00 02/08/2016
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <LCD4884.h>  // UPDATED version 2/16 Yourduino
/*-----( Declare Constants and Pin Numbers )-----*/
#define LCD_BACKLIGHT_PIN  7

/*-----( Declare objects )-----*/
//None: Included in library
/*-----( Declare Variables )-----*/
int displayDelay = 1000;
int switchDelay  = 100;  // Switch scanning delay
int switchVoltage ;   // From Analog read of the button resistors

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(115200);
  pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
  lcd.LCD_init(); // creates instance of LCD
  lcd.LCD_clear(); // blanks the display
  for (int a = 0; a < 5; a++)
  {
    digitalWrite(LCD_BACKLIGHT_PIN, LOW);
    delay(300);
    digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
    delay(300);
  }
  for (int a = 0; a < 6; a++)
  {
    lcd.LCD_write_string(0, a, "01234567980123", MENU_NORMAL); // ignore MENU_NORMAL for now
    delay(displayDelay);
  }
  delay(displayDelay);
  lcd.LCD_clear();   // blanks the display
  delay(500);
  // Show the BIG characters (0..9, + - only)
  lcd.LCD_write_string_big(0, 0, "012345", MENU_NORMAL);
  lcd.LCD_write_string_big(0, 3, "-+-+-+", MENU_NORMAL);
  delay(1000);
  lcd.LCD_clear();  // now  read the joystick using analogRead(0

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  lcd.LCD_write_string(1, 1, "PUSH A BUTTON", MENU_NORMAL);
  switchVoltage = analogRead(0);
  Serial.print("Switch analog value = ");
  Serial.println(switchDelay);

  if (switchVoltage == 0)
  {
    lcd.LCD_write_string(2, 2, "LEFT ", MENU_NORMAL);
  }
  else if (switchVoltage > 0 && switchVoltage < 180)
  {
    lcd.LCD_write_string(2, 2, "PUSH IN", MENU_NORMAL);
    delay(switchDelay);
  }
  else if (switchVoltage > 180 && switchVoltage < 400)
  {
    lcd.LCD_write_string(2, 2, "DOWN ", MENU_NORMAL);
    delay(switchDelay);
  }
  else if (switchVoltage > 400 && switchVoltage < 600)
  {
    lcd.LCD_write_string(2, 2, "RIGHT", MENU_NORMAL);
    delay(switchDelay);
  }
  else if (switchVoltage > 600 && switchVoltage < 800)
  {
    lcd.LCD_write_string(2, 2, "UP   ", MENU_NORMAL);
    delay(switchDelay);
  }
  else if (switchVoltage > 800)              {
    lcd.LCD_write_string(2, 2, "NONE    ", MENU_NORMAL);
    delay(switchDelay);
  }

}  //--(end main loop )---

/*-----( Declare User-written Functions )-----*/
//NONE

//*********( THE END )***********

程序效果

Faef2.jpg
Faef3.jpg
Faef4.jpg
Faef5.jpg

視頻演示

LCD4884 01.png


















產(chǎn)品相關(guān)推薦

Erweima.png

購買地址

LCD4884液晶搖桿擴展板

周邊產(chǎn)品推薦

1602液晶顯示器 藍白屏
Arduino IIC/I2C LCD1602 字符液晶顯示器

相關(guān)問題解答

LCD4884液晶搖桿擴展板顯示應(yīng)用
關(guān)于arduino的LCD4884的使用

相關(guān)學(xué)習(xí)資料

操作視頻
奧松機器人技術(shù)論壇