Arcade PUB
  • Главная
  • Уроки
  • Датчики
  • Проекты
  • Справочник языка Ардуино
  • Справочник
  • Видео
  • Контакты
  • Поддержать
Уроки  /  27 января, 2021

Клавиатура. Урок 22. Ардуино

by valentino
Подключение клавиатуры к ардуино
Подключение клавиатуры к ардуино

Привет! Сегодня посмотрим как с Ардуино работает матричная клавиатура. Подключим клавиатуру, напишем небольшую программу и выведем данные на экран.

Содержание

  • 1 Для того, чтобы выполнить этот урок нам понадобиться.
  • 2 Клавиатура
  • 3 Экран
  • 4 Полный текст программы
  • 5 Заключение
  • 6 Где купить
  • 7 Похожее

В прошлый раз мы рассмотрели подключение дисплея для вывода информации. Посмотрите тот пост если уже забыли или пропустили. Сегодня мы используем экран в новом уроке.

OLED дисплей. Урок 21. Ардуино

Для того, чтобы выполнить этот урок нам понадобиться.

  • Ардуино UNO
  • Макетная плата
  • Перемычки
  • 0.91 Oled дисплей
  • Матричная клавиатура 4 на 4 кнопки
  • Кабель USB

Клавиатура

Матричная клавиатура — это набор кнопок. Подключается она к 8 контактам Ардуино. Каждый контакт считывает значения с определенных строк и столбцов. Используем цифровые контакты с 3 по 10.

Принципиальная схема подключения клавиатуры
Принципиальная схема подключения клавиатуры

Также нам нужна библиотека для использования клавиатуры. Найти ее можно на странице разработчика на официальном сайте arduino.cc

Откроем пример HelloKeypad.ino из библиотеки. Нам придется его немного изменить. Так как наша клавиатура имеет 4 строки и 4 столбца.

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};
byte rowPins[ROWS] = {6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10, 9, 8, 7}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
  }
}

Не забудьте поставить 9600 бод в мониторе последовательного порта.

После загрузки кода на плату в мониторе можно увидеть нажатые клавиши.

Вывод с клавиатуры в монитор последовательного порта
Вывод с клавиатуры в монитор последовательного порта

Экран

Теперь добавим в схему экран и будем выводить символы на него.

Принципиальная схема подключения клавиатуры и дисплея
Принципиальная схема подключения клавиатуры и дисплея

Чтобы символы отображались корректно используем функцию print из класса u8g2. Подробнее про доступные функции этого класса можно прочитать на странице в github.

void loop(){
  char key = keypad.getKey();
  
  if (key){
   u8g2.clearBuffer();
   u8g2.setFont(u8g2_font_ncenB14_tr);
   u8g2.setCursor(0, 15);
   u8g2.print(key);
   u8g2.sendBuffer();
   Serial.println(key);
  }
}
Вывод информации с клавиатуры на экран
Вывод информации с клавиатуры на экран

Полный текст программы

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
#include <Keypad.h>

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};
byte rowPins[ROWS] = {6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10, 9, 8, 7}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  u8g2.begin();
}
  
void loop(){
  char key = keypad.getKey();
  
  if (key){
   u8g2.clearBuffer();
   u8g2.setFont(u8g2_font_ncenB14_tr);
   u8g2.setCursor(0, 15);
   u8g2.print(key);
   u8g2.sendBuffer();
   Serial.println(key);
  }
}

Заключение

Таким образом мы можем подключить к нашим проектам на Ардуино клавиатуру и выводить информацию с нее на экран. Естественно, существует очень много вариантов проектов и устройств для реализации такой схемы. Мы попробуем использовать ее в будущем.

Где купить

  • Модуль KY-008
  • Arduino nano
  • Набор датчиков
  • Arduino Uno

Похожее

Tags

  • Основное

Навигация по записям

OLED дисплей. Урок 21. Ардуино
7 сегментный индикатор. Урок 23. Ардуино

Share your thoughts Отменить ответ

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Новое видео на канале

https://youtu.be/bvzX-edTdS0

Свежие записи

  • Четырехразрядный индикатор. Урок 24. Ардуино
  • 7 сегментный индикатор. Урок 23. Ардуино
  • Клавиатура. Урок 22. Ардуино
  • OLED дисплей. Урок 21. Ардуино
  • Много кнопок на одном пине. Урок 20. Ардуино

Метки

  • Bluetooth
  • RGB Светодиоды
  • WIFI
  • Двигатели
  • Звук
  • Игры
  • Интернет вещей
  • Лего
  • Основное
  • Программирование
  • Уроки

Купить стартовый набор Ардуино UNO на Aliexpress

Стартовый набор Ардуино Уно

Купить набор датчиков для Ардуино 45 штук на Aliexpress

набор датчиков для Ардуино

arcadepub

Do you know how this display works? It is pretty e Do you know how this display works? It is pretty easy to use it with #arduino.
#arduinouno #arduinoproject #arcadepub #ардуино #аркадныйпаб #ардуинопроект
How to use 7 segments indicator with #arduino its How to use 7 segments indicator with #arduino its pretty easy.
#arduinouno #arduinoproject #arcadepub
How to use 4x4 keypad with #arduino check it out. How to use 4x4 keypad with #arduino check it out. #arduinouno #arduinoproject #arcadepub
How to use oled display with #arduino it's pretty How to use oled display with #arduino it's pretty easy. #arcadepub #ардуино #ардуинопроект #arduinoproject #arduinouno
Hi there! How to control button debounce without c Hi there! How to control button debounce without code. Lets see.

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Hello there! Let's write a program to control ard Hello there!  Let's write a program to control arduino by ir.

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Hey! How are you doing? How do you think, we can c Hey! How are you doing? How do you think, we can control arduino program by ir? I bet we can. 

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Hello! There is a second video on my youtube chann Hello! There is a second video on my youtube channel. I've just added subtitles, so you can see how to use if and else structures and for() loop in arduino program. Enjoy, and do NOT forget to subscribe. 
https://youtu.be/8AHfAQyNAqU

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #youtube
Hi there! How is it going? Photo resistor and lase Hi there! How is it going? Photo resistor and laser are here. Look at graphics and try to understand how it works!

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Here is ky-039 heart beat arduino module. Do you l Here is ky-039 heart beat arduino module. Do you like it? Write in the comments below!

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Its Magic lights with ky-027 arduino module. Do yo Its Magic lights with ky-027 arduino module. Do you like it?  Write in the comments below!

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Arduino and #laser are together. Please subscribe Arduino and #laser are together.

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #arduinoproject
Do you know how gyroscope modul works with arduino Do you know how gyroscope modul works with arduino? 

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #rfid #arduinoproject
Do you know how you can use rfid module with ardui Do you know how you can use rfid module with arduino? 

Please subscribe to my instagram and youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #rfid #arduinoproject
It is almost done Please subscribe to my youtube It is almost done

Please subscribe to my youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #flower #autowatering #arduinoproject #robot #spiderbot
Begin to make a spider bot. Please subscribe to Begin to make a spider bot. 

Please subscribe to my youtube channel as well.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #flower #autowatering #arduinoproject #robot #spiderbot
Hello folks! There are 1000 of us on my instagram Hello folks! There are 1000 of us on my instagram account. And i want to tell thanks to each of you!
I'd like to tell more about this project. And that's why i made a video on youtube channel. 
It is in russian, but i have added english subtitles. 
I'm gonna tell you about many intriguing Arduino projects.
So, please, take a look at video. And subscribe to my youtube channel as well. 

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #flower #autowatering
How can we know that flower needs to be watered. L How can we know that flower needs to be watered. Like and Subscribe to know more.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit #flower #autowatering
How to turn light on by clapping. Like and Subscri How to turn light on by clapping. Like and Subscribe to know more.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit
Is it possible to turn light on over the internet? Is it possible to turn light on over the internet? Like and Subscribe to know more.

#arcadepub #diy #doityourself #learn #smarthome #ардуино #аркадныйпаб #сделайсам #умныйдом #arduino #circuit
Загрузи больше…

ArcadePUB @ 2020

arduino@arcadepub.ru

На сайте вы найдете уроки, проекты и обзоры всего, что связано с ардуино.

Аркадные игры и автоматы.

DIY проекты

Метки

  • Bluetooth
  • RGB Светодиоды
  • WIFI
  • Двигатели
  • Звук
  • Игры
  • Интернет вещей
  • Лего
  • Основное
  • Программирование
  • Уроки

Свежие записи

  • Четырехразрядный индикатор. Урок 24. Ардуино
  • 7 сегментный индикатор. Урок 23. Ардуино
  • Клавиатура. Урок 22. Ардуино
  • OLED дисплей. Урок 21. Ардуино
  • Много кнопок на одном пине. Урок 20. Ардуино

Навигация

  • Главная
  • Уроки
  • Датчики
  • Проекты
  • Справочник языка Ардуино
  • Справочник
  • Видео
  • Контакты
  • Поддержать

Дополнительно

Поддержать

Контакты

YouTube
Patreon
VK
Instagram
Twitter