#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] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad customKeypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
instance of class NewKeypad
int Kill = 0;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
void LiquidCrystal_I2C:begin
lcd.begin(0.1);
lcd.setBacklight(255);
lcd.print("Rungrod 11");
lcd.setCursor(0,2);
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(); customkey
if (customKey){
Serial.println(customKey);
}
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");
}
if(millis)(-Time)>pos){
Time = millis();
myservo.write(0);
delay(3000);
}
else{
myservo.write(45);
delay(3000);
}
}
มีใครพอช่วยได้ไหมครับ ผมเขียนArduinoR3เครื่องให้อาหารปลา มีคีย์แพต lcd16*2 motorservo แต่เขียนเท่าไหร่ก็ไม่ได้
#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] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad customKeypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
instance of class NewKeypad
int Kill = 0;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
void LiquidCrystal_I2C:begin
lcd.begin(0.1);
lcd.setBacklight(255);
lcd.print("Rungrod 11");
lcd.setCursor(0,2);
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(); customkey
if (customKey){
Serial.println(customKey);
}
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");
}
if(millis)(-Time)>pos){
Time = millis();
myservo.write(0);
delay(3000);
}
else{
myservo.write(45);
delay(3000);
}
}