๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[์๋์ฐจ ๋ทํธ์ LCDํ์ผ๋ก ์ํฉ ์ ๋ฌํ๊ธฐ 4] Joystick button ๋ง๋ค lcd ์ถ๋ ฅ ๋ณธ๋ฌธ
๐ฉ๐ป IoT (Embedded)/Arduino
[์๋์ฐจ ๋ทํธ์ LCDํ์ผ๋ก ์ํฉ ์ ๋ฌํ๊ธฐ 4] Joystick button ๋ง๋ค lcd ์ถ๋ ฅ
์ง์ง์ํ์นด 2023. 11. 10. 12:09728x90
๋ฐ์ํ
โญ Joystick button ๋ง๋ค lcd ์ถ๋ ฅ
โ Wire.h
I2C ํต์ ์ ํ๋๋ฐ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. ๋ง์คํฐ ํ๋์ ์ฌ๋ ์ด๋ธ ์ฌ๋ฌ๋๋ฅผ ํต์ ๊ฐ๋ฅํ๊ฒ ํ๋ค.
SDA๋ ๋ฐ์ดํฐ๋ฅผ ์ ์ก๊ณผ ์ก์ ์ ํ๋ ๋ฐ์ด์ค(์๋ฐฉํฅ ํต์ ์ด ๊ฐ๋ฅํ์ง๋ง ์ก์ ๊ณผ ์์ ์ค์ ํ๋์ฉ ์ฒ๋ฆฌํ๋ค.)
SCL์ ๊ธฐ์ค ํด๋ญ์ ์ฌ๋ ์ด๋ธ์๊ฒ ์ ๋ฌํ๋ค.
์ฌ๋ ์ด๋ธ์ ๊ตฌ๋ณ์ ์ฃผ์๋ก ํ๊ธฐ ๋๋ฌธ์ ๊ธด ๋ฐ์ดํฐ์ ๊ตํ์๋ ์ ํฉํ์ง ์๋ค.
ํด๋ญ์ ๊ฐ์ง๊ณ ํต์ ํ๋ฏ๋ก ๋๊ธฐ์ ํต์ ์ด ๊ฐ๋ฅํ๋ค.
arduino(uno๋ ์ ์ธ)์๋ I2C ํต์ ์ ํ ์ ์๋ ์นฉ์ด ๋ด์ฅ๋์ด์๋ค.
// mytest.ino
//#include "test2.h"
// LiquidCrystal ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "test2.h"
// ์กฐ์ด์คํฑ ์ด๋์ ๋ฒํผ์ด ๋๋ฅด๋ ๊ฑธ ์
๋ ฅ๋ฐ๊ธฐ ์ํด ์ ์ธ
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
// lcd ๊ฐ์ฒด ์ ์ธ
LiquidCrystal_I2C lcd(0x27, 16, 2); // ์ฃผ์, ์ด, ํ
void setup() {
Serial.begin(9600); // ์๋ฆฌ์ผ ํต์ ์ ์์ํ๋ฉฐ, ํต์ ์๋๋ 9600
pinMode(buttonPin2, INPUT_PULLUP );
pinMode(buttonPin3, INPUT_PULLUP );
pinMode(buttonPin4, INPUT_PULLUP );
pinMode(buttonPin5, INPUT_PULLUP );
lcd.init(); // LCD ์ด๊ธฐํ
// Print a message to the LCD
lcd.backlight(); // LCD ๋ฐฑ๋ผ์ดํธ ์ผ๊ธฐ
}
void loop() {
int X = analogRead(0); // ๋ณ์ X์ ์๋ ๋ก๊ทธ 0๋ฒํ์ ์
๋ ฅ๋๋ ์ ํธ๋ฅผ ๋์
int Y = analogRead(1); // ๋ณ์ Y์ ์๋ ๋ก๊ทธ 1๋ฒํ์ ์
๋ ฅ๋๋ ์ ํธ๋ฅผ ๋์
int buttonValue2 = digitalRead(2); // buttonValue๊ฐ ์ ์ธ
int buttonValue3 = digitalRead(3);
int buttonValue4 = digitalRead(4);
int buttonValue5 = digitalRead(5);
char data[16];
if (buttonValue2 == LOW) { // if๋ฌธ์ ์ด์ฉํ์ฌ ๊ฐ ๋ฒํผ์ด ๋๋ฆฌ๋ฉด ์ํ๋ฒณ์ด ์๋ฆฌ์ผ๋ชจ๋ํฐ์ ์ถ๋ ฅ๋๋๋ก ์ค์
String data = "front car!";
printCountTest1(data);
}
if (buttonValue3 == LOW) {
String data = "front animal!";
printCountTest1(data);
}
if (buttonValue4 == LOW) {
String data = "baby in car";
printCountTest1(data);
}
if (buttonValue5 == LOW) {
String data = "broken car";
printCountTest1(data);
}
delay(500); // 0.5์ด๋์ ์ง์
}
728x90
๋ฐ์ํ
'๐ฉโ๐ป IoT (Embedded) > Arduino' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments