الكود البرمجي
قبل رفع الكود البرمجي على لوحة الاردوينو قم بفصل سلك tx و rx من لوحة الاردوينو ثم ارفع الكود البرمجي للوحة باستخدام برنامج Arduino IDE وبعد رفع الكود البرمجي أعد الدائرة الكهربائية كما كانت.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7); //create an object for LCD
String voice; //to store the command
char c; //to get characters from the command
void setup()
{
Serial.begin(9600); //for serial terminal
lcd.begin(16,2); //initialize LCD
}
void loop()
{
while(Serial.available())
{
delay(10); //delay added to make it stable
lcd.clear(); //clear LCD
c = Serial.read(); //get new command
voice += c; //to make a string of command
}
if(voice.length() > 0)
{
Serial.println(voice); //print the command in Serial Terminal
if(voice == "clear") //to clear the LCD send "clear" command
{
lcd.clear();
}
lcd.print(voice); //print the command on LCD
voice = ""; // to end the command
}
}
شرح الكود البرمجي
في هذا السطر تم استدعاء مكتبة الشاشة الكرستالية: <LiquidCrystal.h>.
نستطيع تحميلها بتتبع المسار التالي:
Sketch > Include libraries > Manage libraries
ثم نكتب بخانة البحث Liquid crystal by Arduino
ثم نضغط على Install.
#include <LiquidCrystal.h>
بعد ذلك أعلنا عن المتغيرات اللازمة مثل المتغيرات الخاصة بالشاشة الكرستالية.
LiquidCrystal lcd(2,3,4,5,6,7); //create an object for LCD
عرفنا المتغير voice والذي سيحمل المدخلات الصوتية من الجمل والعبارات وغيرها.
String voice; //to store the command
وعرفنا المتغير c لقراءة الأحرف من الأوامر.
char c; //to get characters from the command
في الدالة ()setup يتم تهيئة الشاشة الكرستالية لطباعة النصوص عليها.
void setup()
{
Serial.begin(9600); //for serial terminal
lcd.begin(16,2); //initialize LCD
}
في الدالة ()loop يتم قراءة الصوت من تطبيق Arduino Voice Control وبعد ذلك يتم تحويله إلى نصوص مطبوعة على الشاشة الكرستالية.
void loop()
{
while(Serial.available())
{
delay(10); //delay added to make it stable
lcd.clear(); //clear LCD
c = Serial.read(); //get new command
voice += c; //to make a string of command
}
if(voice.length() > 0)
{
Serial.println(voice); //print the command in Serial Terminal
if(voice == "clear") //to clear the LCD send "clear" command
{
lcd.clear();
}
lcd.print(voice); //print the command on LCD
voice = ""; // to end the command
}
}

