#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Servo myservo;
int pos = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {8, 7, 6};
Keypad customKeypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//instance of class NewKeypad
int Kill = 0;
void setup()
{
myservo.attach(13);
Serial.begin(9600);
//void LiquidCrystal_I2C:begin
lcd.init();
lcd.backlight();
lcd.print("Rungrod 11");
lcd.setCursor(0, 1);
lcd.print("Anurak 15");
delay(3000);
lcd.clear();
pos = 8000;
lcd.setCursor(5,0);
lcd.print("Mode 1");
lcd.setCursor(5, 1);
lcd.print("5 ms");
}
void loop()
{
static unsigned long Time = millis();
customKey = customKeypad.getKey();
if (customKey = '1'){
pos = 8000;
Kill = 1;
lcd.setCursor(5,0);
lcd.print("Mode 1");
lcd.setCursor(5, 1);
lcd.print("5 ms");
}
if (customKey = '2'){
pos = 13000;
Kill = 2;
lcd.setCursor(5, 0);
lcd.print("Mode 2");
lcd.setCursor(5, 1);
lcd.print("5 ms");
}
if (customKey = '3'){
pos = 23000;
Kill = 3;
lcd.setCursor(5, 0);
lcd.print("Mode 3");
lcd.setCursor(5, 1);
lcd.print("20 ms");
}
else{
myservo.write(90);
}
}
ช่วยหน่อยครับ รู้สึกติดหลายที่มากเลยครับ มอเตอร์ไม่หมุน หน้าจอ lcd รันเร็วไปครับ
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Servo myservo;
int pos = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {8, 7, 6};
Keypad customKeypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//instance of class NewKeypad
int Kill = 0;
void setup()
{
myservo.attach(13);
Serial.begin(9600);
//void LiquidCrystal_I2C:begin
lcd.init();
lcd.backlight();
lcd.print("Rungrod 11");
lcd.setCursor(0, 1);
lcd.print("Anurak 15");
delay(3000);
lcd.clear();
pos = 8000;
lcd.setCursor(5,0);
lcd.print("Mode 1");
lcd.setCursor(5, 1);
lcd.print("5 ms");
}
void loop()
{
static unsigned long Time = millis();
customKey = customKeypad.getKey();
if (customKey = '1'){
pos = 8000;
Kill = 1;
lcd.setCursor(5,0);
lcd.print("Mode 1");
lcd.setCursor(5, 1);
lcd.print("5 ms");
}
if (customKey = '2'){
pos = 13000;
Kill = 2;
lcd.setCursor(5, 0);
lcd.print("Mode 2");
lcd.setCursor(5, 1);
lcd.print("5 ms");
}
if (customKey = '3'){
pos = 23000;
Kill = 3;
lcd.setCursor(5, 0);
lcd.print("Mode 3");
lcd.setCursor(5, 1);
lcd.print("20 ms");
}
else{
myservo.write(90);
}
}