Jak začít
LCD
Zapojení
PALTERMINAL | ARDUINO |
---|---|
+5V | 5V |
GND | GND |
SDA | A4 |
SCL | A5 |
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x38, 16, 2);
void setup()
{
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello, world!");
}
void loop()
{
// Do nothing here...
}
Klávesnice
Zapojení
PALTERMINAL | ARDUINO |
---|---|
KEYBOARD-C | 4 |
KEYBOARD-B | ~5 |
KEYBOARD-A | ~6 |
KEYBOARD-4 | 7 |
KEYBOARD-3 | 8 |
KEYBOARD-2 | ~9 |
KEYBOARD-1 | ~10 |
Code
#include <Arduino.h>
#include "ButtonMatrix.h" /** Include this header in order to work with the button matrix */
using namespace RSys;
static const uint32_t c_uiMonitorBaud = 115200; // USB monitoring baud rate
const uint16_t longPressDuration = 1000; /** Minimum duration of a long press */
const uint8_t COLS = 4; /** Number of button matrix columns */
const uint8_t ROWS = 3; /** Number of button matrix rows */
uint8_t colPins[COLS] = {7, 8,9,10}; /** Button matrix column pins */
uint8_t rowPins[ROWS] = {4,5,6}; /** Button matrix row pins */
Button buttons[ROWS][COLS] = {
{ ('#'), (1), (4) , (7)},
{ (0), (2), (5), (8)},
{ ('*'), (3), (6) , (9)},
};
ButtonMatrix matrix((Button*)buttons, rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(c_uiMonitorBaud);
matrix.init(); /** Initialize the ButtonMatrix*/
}
void loop()
{
Button* pButton = NULL;
const uint16_t numButtons = matrix.getNumButtons();
if (matrix.update())
{
for (uint16_t idx = 0; idx < numButtons; idx++)
{
pButton = matrix.getButton(idx);
if (pButton->isPressed())
{
Serial.print("Button pressed: ");Serial.println(pButton->getNumber());
}
}
}
}