Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <EEPROM.h> #include <LiquidCrystal.h> #define _R digitalRead //định nghĩa chân ngoại vi #define ok A1 #define up A2 #define down A0 LiquidCrystal lcd(12, 11, 7, 6, 5, 4); unsigned int do_sau,muc_can,muc_day; unsigned int home_setting=1,sel; int muc_nuoc; unsigned int key; // home_setting: home=1,setting=0 //sel: 1: phone_num, 2: do_sau, 3: muc_day, 4: muc_can, 5: info,6: exit; char phone_num[20],phone[20]; /* EEPROM: |---1---2---|---3--4---|---5--6---| |-độ-sâu-hồ-|--hồ-cạn--|--hồ-đầy--| |-------| */ void setup() { //chế độ I/O pinMode(up, INPUT); pinMode(ok, INPUT); pinMode(down, INPUT); pinMode(13,OUTPUT); lcd.begin(20,4); } /* in chuoi ra man hinh lcd */ void lcd_string(unsigned int cot, unsigned int dong, String chuoi) { // đặt con trỏ vào cột, dòng lcd.setCursor(cot,dong); // In ra dong chu lcd.print(chuoi); } //đọc phím int read_key() { if(_R(ok)) { while(_R(ok)); return(1); } if(_R(up)) { while(_R(up)); return(2); } if(_R(down)) { while(_R(down)); return(3); } return(0); } unsigned int delay_read_key() { // delay 1s for(int i=0; i< 100;i++) { key=read_key(); if(key==1) { return(0); i=100; } else {delay(10);} } return(1); } /* cai dat */ void setting() { lcd.clear(); lcd_string(0,0," SETTING "); lcd_string(0,3,"Down:- Ok:sel Up:+"); sel=0; int sel_term=1; int sel_last; while(home_setting==0) { key=read_key(); if(key==1) //ok { sel_last=sel_term; lcd_string(0,1," "); lcd_string(0,2," "); sel_term=0; } if(key==2) //up { sel_term+=1; if(sel_term> 6) {sel_term=1;} } if(key==3) //down { sel_term -=1; if(sel_term==0) {sel_term=6;} } switch(sel_term) { case 1: lcd_string(0,1,"=> Cai dat sdt "); lcd_string(0,2," Do sau ho "); break; case 2: lcd_string(0,1,"=> Do sau ho "); lcd_string(0,2," Muc canh bao tren"); break; case 3: lcd_string(0,1,"=> Muc canh bao tren"); lcd_string(0,2," Muc canh bao duoi"); break; case 4: lcd_string(0,1,"=> Muc canh bao duoi"); lcd_string(0,2," Thong tin "); break; case 5: lcd_string(0,1,"=> Thong tin "); lcd_string(0,2," Exit "); break; case 6: lcd_string(0,1,"=> Exit "); lcd_string(0,2," Cai dat sdt "); break; } /* chọn chế độ */ if(sel != sel_last) { sel=sel_last; switch(sel) { case 1: set_phone(10); sel_term=sel_last; sel= sel_last=0; break; case 2: set_do_sau(); sel_term=sel_last; sel= sel_last=0; break; case 3: set_muc_day(); sel_term=sel_last; sel= sel_last=0; break; case 4: set_muc_can(); sel_term=sel_last; sel= sel_last=0; break; case 5: sel_term=sel_last ; sel= sel_last=0; info(); break; case 6: lcd_string(0,1," THOAT CAI DAT "); delay(2000); sel_term=1; sel= sel_last=0; home_setting=1; break; } } } if(home_setting==1) { eep_read_all(); lcd.clear(); lcd_string(0,0," HOME "); } } void set_do_sau() { //lcd.clear(); lcd_string(0,1,"Do sau cua ho: (cm) "); lcd_string(0,2," "); //lcd_string(0,3,"Down:- Ok:sel Up:+"); nhap_luu_so(1); } void set_muc_can() { //lcd.clear(); lcd_string(0,1,"Muc canh bao can(cm)"); lcd_string(0,2," "); //lcd_string(0,3,"Down:- Ok:sel Up:+"); nhap_luu_so(3); } void set_muc_day() { //lcd.clear(); lcd_string(0,1,"Muc canh bao day(cm)"); lcd_string(0,2," "); //lcd_string(0,3,"Down:- Ok:sel Up:+"); nhap_luu_so(5); } void nhap_luu_so(unsigned int vitri) { unsigned int term=0; int x=1; while(x) { lcd.setCursor(0,2); lcd.print(term); if(_R(ok)) { while(_R(ok)); int term1 = term; eep_write_16b(term1,vitri); lcd_string(0,2," Da luu "); delay(1000); x=0; break; } if(_R(up)) { term++; delay(200); } if(_R(down)) { term--; delay(200); } if(term > 400) {term=0;} } } //chương trình con với EEPROM: /*ghi dữ liệu 16bit vào vị trí bất kì trong EEPROM */ void eep_write_16b(unsigned int dulieu,unsigned int vitri) { unsigned int h,l; h=int(dulieu/256); l=int(dulieu%256); delay(5); EEPROM.write(vitri,h); delay(5); EEPROM.write(vitri+1,l); delay(5); } /*đọc dữ liệu 16bit từ vị trí bất kì trong EEPROM */ unsigned int eep_read_16(unsigned int vitri) { unsigned int h,l,dulieu; delay(5); h=EEPROM.read(vitri); delay(5); l=EEPROM.read(vitri+1); delay(5); dulieu=h*256+l; return(dulieu); } /* Infomation */ void info() { lcd.clear(); lcd_string(0,0," THONG TIN "); lcd_string(0,1," Thiet bi canh bao "); lcd_string(0,2," muc nuoc "); lcd_string(0,3," Version 2.0.1 "); delay(2000); } void loop() { if(home_setting==0) { setting(); } if(home_setting==1) { lcd.clear(); lcd_string(0,0," HOME "); while(home_setting) { muc_nuoc=water_lever(); lcd_muc_nuoc(muc_nuoc); home_setting=delay_read_key(); } } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत