簡體   English   中英

Arduino(C / C ++)代碼在LCD上顯示陣列的內容

[英]Arduino (C/C++) Code To Display Contents of Array on LCD

在發布本文之前,我已經盡力進行了盡可能多的研究,但是我是編程的新手,因此我的總體無知使我無法真正知道如何提出正確的問題。

當前目標:

  1. 構建一個存儲50個以上英語單詞/短語的數組;
  2. 在我的Arduino上訪問數組,並在LCD上顯示各個單詞/短語;
  3. 通過單擊Arduino上的按鈕來切換單詞/短語。

硬件規格:SainSmart UnoR3,基於HD44780的LCD

問題:編寫代碼,當我按下按鈕時將顯示一個新單詞。

代碼為“你好,世界!” 液晶屏

void setup() {
 // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

數組中隨機字符串的代碼

#include <stdio.h>
#include <stdlib.h>

int main() {
    const char *messages[] = {
        "Hello!",
        "How are you?",
        "Good stuff!"
    };
    const size_t messages_count = sizeof(messages) / sizeof(messages[0]);
    char input[64];
    while (1) {
        scanf("%63s", input);
        printf("%s\n", messages[rand() % messages_count]);
    }
    return 0;
}

我也有一個Arduino Uno和一個LCD顯示器。 您的任務將是調試硬件和軟件。 所以,讓我問一些問題。

在代碼清單中,運行草圖時,您會得到一個“ hello world!” 在液晶顯示屏上顯示?

您提供的main()與這個問題有什么關系。 具體來說, main()在哪里運行? 我希望它屬於您的草圖!!

在您的loop()沒有延遲。 對於剛開始的程序員來說...通常在顯示某些內容時需要暫停幾秒鍾,否則您將以每秒數千次的變化來驅動LCD。

因此添加一個delay(3000); 該語句在LCD更新之間要延遲3秒(3,000毫秒)。

接下來,在“ loop()”中,您需要測試按鈕是否按下,但現在僅顯示LCD。

請做這些事情並相應地更新您的問題,我將跟進更多的建議/問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM