phj's People
phj's Issues
I want to make an automatic feeder/자동급식기
#include <SoftwareSerial.h>
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspServer.h>
#include <WiFiEspUdp.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Servo.h>
#define GPIO2 0
Servo servo;
int GP0val = 0;
int value1 = 0;
const char* ssid = "??"; // wifi 이름 넣기
const char* password = "??"; // wifi 비밀번호 넣기
WiFiEspServer server(80);
Servo myservo;
void setup() // wifi로 ESP32 웹서버 실행
{
myservo.attach(9); // 서보모터 핀설정
Serial.begin(9600); // 시리얼 통신을 9600의 속도로 시작
setTime(14,12,0,7,9,23); //초기 시간을 16시35분0초로 세팅 뒤에는 일월년 순
Alarm.alarmRepeat(14,13,30,MoringAlarm); //시간 알람 설정
Alarm.alarmRepeat(14,14,00,EveningAlarm); //알람 설정
pinMode(7,INPUT_PULLUP); //버튼 핀번호
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.print("IP address : http://");
Serial.println(WiFi.localIP());
server.begin();
}
void loop() {
Alarm.delay(1000); //1초 단위로 표시
digitalCloockDisplay(); //디지털 시계를 표시
WiFiEspClient client = server.available();
String req = client.readStringUntil('\r'); // 앱에서 사용자가 보낸 신호 읽기
if(digitalRead(9)==LOW){ //버튼 눌렀을시 실행되는 코드
myservo.write(170);
delay(300);
}
else
{
myservo.write(0);
delay(300);
}
if (req.indexOf("/gpio2/1") != -1) {
GP0val = 1;
if (GP0val == 1) { // +90도 작동해서 사료 배출
value1 += 90;
delay(1000);
myservo.write(value1);
if (value1 == 90) { // -90도 뒤로 작동하여 사료 채우기
delay(2000);
value1 = 0;
myservo.write(value1);
GP0val = 0;
}
}
}
}
void MoringAlarm() {
Serial.println("OPEN"); // 첫번째 알람시간이 되면 구문 동작
myservo.write(90);
delay(1000);
}
void EveningAlarm() {
Serial.println("CLOSE "); //두번째 알람시간이 되면 구문 동작
myservo.write(-90);
delay(1000);
}
void digitalCloockDisplay() { //디지털 시계 표시
Serial.print(hour()); //시간표시
printDigits(minute()); // 분 표시
printDigits(second()); //초 표시
Serial.println(); //시리얼 모니터에 표시
}
void printDigits(int digits) { //시리얼 모니터에 시간을 띄우기 위해 필요한 부분
Serial.print(":");
if (digits < 10) {
Serial.print('0');
Serial.print(digits);
}
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.