Merhaba, arduino devre elemanlarını tanımaya ve onların bağlantı şekillerini öğrenmeye devam ediyoruz. Bugün Arduino – LCD 16×2 Devresi kuracağız.
Görselde gösterildiği gibi bir devre kuracak olursanız devrenin tamamlanmış olduğunu göreceksiniz.
Test Kodu
// Include Libraries #include "Arduino.h" #include "LiquidCrystal.h" // Pin Definitions #define LCD_PIN_RS 7 #define LCD_PIN_E 6 #define LCD_PIN_DB4 2 #define LCD_PIN_DB5 3 #define LCD_PIN_DB6 4 #define LCD_PIN_DB7 5 // Global variables and defines // object initialization LiquidCrystal lcd(LCD_PIN_RS,LCD_PIN_E,LCD_PIN_DB4,LCD_PIN_DB5,LCD_PIN_DB6,LCD_PIN_DB7); // define vars for testing menu const int timeout = 10000; //define timeout of 10 sec char menuOption = 0; long time0; // Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. void setup() { // Setup Serial which is useful for debugging // Use the Serial Monitor to view printed messages Serial.begin(9600); while (!Serial) ; // wait for serial port to connect. Needed for native USB Serial.println("start"); // set up the LCD's number of columns and rows lcd.begin(16, 2); menuOption = menu(); } // Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. void loop() { if(menuOption == '1') { // LCD 16x2 - Test Code // Print a message to the LCD. lcd.setCursor(0, 0); lcd.print("Circuito Rocks !"); // Turn off the display: lcd.noDisplay(); delay(500); // Turn on the display: lcd.display(); delay(500); } if (millis() - time0 > timeout) { menuOption = menu(); } } // Menu function for selecting the components to be tested // Follow serial monitor for instrcutions char menu() { Serial.println(F("\nWhich component would you like to test?")); Serial.println(F("(1) LCD 16x2")); Serial.println(F("(menu) send anything else or press on board reset button\n")); while (!Serial.available()); // Read data from serial monitor if received while (Serial.available()) { char c = Serial.read(); if (isAlphaNumeric(c)) { if(c == '1') Serial.println(F("Now Testing LCD 16x2")); else { Serial.println(F("illegal input!")); return 0; } time0 = millis(); return c; } } }