人体感应模块控制LCD1602背景灯是否开启
/*
Web client This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield. Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen */
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h> #define ResetPIN 7 // 初始化引脚
LiquidCrystal lcd(, , , , , ); // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAA, 0xCE, 0xEA, 0xFF, 0xE1 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "192.168.9.6"; // name address for Google (using DNS)
String clientPwd="-1"; // Set the static IP address to use if the DHCP fails to assign
IPAddress ip(,,,);
IPAddress gateway(,,,);
IPAddress dns_server(,,,);
IPAddress subnet(,,,);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client; int errCount=; void setup() { //LCD
// 设置行列值
lcd.begin(, ); pinMode(ResetPIN,OUTPUT);
digitalWrite(ResetPIN,LOW); // Open serial communications and wait for port to open:
Serial.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// give the Ethernet shield a second to initialize:
if (Ethernet.begin(mac) == ) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip,dns_server,gateway,subnet);
} delay();
Serial.println("Ready");
} void loop()
{ Serial.println(clientPwd);
// 打印字符串
lcd.setCursor(,);
lcd.print(clientPwd); httpRequest();
delay(); } //================Http Request Code========================
void httpRequest(){
// if you get a connection, report back via serial: if(!client.connected()){
Serial.println("disconnecting.");
client.stop();
if (client.connect(server, )) {
Serial.println("connected");
}else{
// kf you didn't get a connection to the server:
Serial.println("connection failed");
errCount++;
if(errCount>=){
digitalWrite(ResetPIN,HIGH);
delay();
}
}
} else{ // Make a HTTP request:
client.println("GET /main.ashx?m=c&mil=" + String(millis()) + "&cpwd="+clientPwd+"&rf=0" +" HTTP/1.1");
client.println("Host:" +String(server));
//client.println("Connection: close"); client.println();
delay();
String reply="";
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
reply+=c; }
//Serial.print(reply);
int index=reply.indexOf("\"Model\":\"8888");
if(index>=){
index=index+;
clientPwd= reply.substring(index,index+);
Serial.println("Changed:" + clientPwd); } errCount=;
//wdt_reset();
} }
//================End Http Request Code===============
arduino网卡扩展板,会使用 2,10,11,12,13 i/o口,所以要调整lcd使用的接口
人体感应器信号输出连S9013三极管(来控制lcd背景灯的亮与灭(使用K编号的脚)
/*
Web client This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield. Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen */
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <avr/wdt.h> #define ResetPIN 7
#define HasManPIN 8
#define RebootPIN 6 // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAA, 0xCE, 0x3A, 0x6F, 0xE1 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "192.168.9.6"; // name address for Google (using DNS)
String clientPwd="-1";
int hasMan=;
LiquidCrystal_I2C lcd(0x27,,); // Set the static IP address to use if the DHCP fails to assign
IPAddress ip(,,,);
IPAddress gateway(,,,);
IPAddress dns_server(,,,);
IPAddress subnet(,,,);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client; int errCount=;
unsigned long lastRequest=; void setup() { pinMode(HasManPIN,INPUT);
pinMode(ResetPIN,OUTPUT);
pinMode(RebootPIN,OUTPUT); digitalWrite(ResetPIN,LOW);
digitalWrite(RebootPIN,LOW); // Open serial communications and wait for port to open:
Serial.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// give the Ethernet shield a second to initialize:
if (Ethernet.begin(mac) == ) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip,dns_server,gateway,subnet);
} lcd.init();
lcd.backlight();
lcd.print("-1");
delay();
Serial.println("Ready");
lastRequest=millis(); wdt_enable(WDTO_8S);
} void loop()
{
//digitalWrite(RebootPIN,LOW); if((millis()-lastRequest)>=){
Serial.println("reboot");
digitalWrite(ResetPIN,HIGH);
delay();
}
Serial.println("lcd...");
Serial.println(clientPwd);
// 打印字符串
lcd.setCursor(,);
lcd.print(clientPwd); //digitalWrite(RebootPIN,HIGH); hasMan=digitalRead(HasManPIN);
Serial.println(hasMan);
if(hasMan==){
lcd.backlight();
}else{
lcd.noBacklight();
} if( (millis() - lastRequest) >=)
{
httpRequest();
lastRequest=millis();
} delay();
Serial.println("lcd over!");
//
wdt_reset(); } //================Http Request Code========================
void httpRequest(){
// if you get a connection, report back via serial: if(!client.connected()){
Serial.println("disconnecting.");
client.stop();
if (client.connect(server, )) {
Serial.println("connected");
}else{
// kf you didn't get a connection to the server:
Serial.println("connection failed");
errCount++;
if(errCount>=){
digitalWrite(ResetPIN,HIGH);
delay();
}
}
} else{ // Make a HTTP request:
client.println("GET /main.ashx?m=c&mil=" + String(millis()) + "&cpwd="+clientPwd+"&rf="+String(hasMan) +" HTTP/1.1");
client.println("Host:" +String(server));
//client.println("Connection: close"); client.println();
delay();
String reply="";
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
reply+=c; }
//Serial.print(reply);
int index=reply.indexOf("\"Model\":\"8888");
if(index>=){
index=index+;
clientPwd= reply.substring(index,index+);
Serial.println("Changed:" + clientPwd); } errCount=;
//wdt_reset();
} }
//================End Http Request Code===============
人体感应模块控制LCD1602背景灯是否开启的更多相关文章
- 「雕爷学编程」Arduino动手做(17)---人体感应模块
37款传感器和模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器与模块,依照实践出真知(动手试试)的理念,以学习和交流为目的,这里准备 ...
- arduino 蓝牙控制RGB LED灯
/* 日期:2016.9.2 功能:arduino 蓝牙控制RGB LED灯 元件: 跳线公公头 * 8 rgbled, 220欧电阻 蓝牙模块 接线: 蓝牙模块VCC,GND分别接5V,GND;TX ...
- 使用按钮控制HTML5背景音乐开关
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name ...
- 89C51单片机定时器控制的流水灯
/***************************************************Copyright: 2014-02-11.version1.0File name: timer ...
- K1 K2作为中断源控制红色LED灯,实现任意键按一下LED灯亮或者灭
#include "stm32f10x.h" // 相当于51单片机中的 #include <reg51.h> #include "stm32f10x_gpi ...
- 用selenium 模块控制浏览器
11.8 用selenium 模块控制浏览器selenium 模块让Python 直接控制浏览器,实际点击链接,填写登录信息,几乎就像是有一个人类用户在与页面交互.与Requests 和Beautif ...
- selenium模块控制浏览器
利用selenium模块控制浏览器 导入selenium模块:from selenium import webdriver browserFirefox = webdriver.Firefox()#打 ...
- 【MM系列】SAP MM模块-控制采购订单中某些项目的输出显示
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-控制采购订单中某些 ...
- Arduino 各种模块篇 蓝牙模块 手机蓝牙控制Arduino LED灯
解决方案. 条件: 1.手机android 商店下载 blueTerm 2.向arduino中载入如下代码: char val; ; void setup() { Serial.begin(); pi ...
随机推荐
- 边框(border)宽度样式颜色 和基本属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Mysql 获取当天,昨天,本周,本月,上周,上月的起始时间
转自: http://www.cppblog.com/tx7do/archive/2017/07/19/215119.html -- 今天 SELECT DATE_FORMAT(NOW(),'%Y-% ...
- Qt 软件的发布
我们程序的Release版本正式发布需要将各种依赖的库文件一起打包. 有时候我们并不清楚具体依赖哪些库,这时,可以用Qt的一个工具"windeployqt" 比如,找到程序.exe ...
- 系统批量运维管理器pexpect的使用
# pip install pexpect 或 # easy_install pexpect 1 #!/usr/bin/env python 2 import pexpect 3 child = pe ...
- TCP/IP知识总结(TCP/IP协议族读书笔记二)
接下来,总结一下网络层的协议,IP,ARP,RARP,ICMP,IGMP.当我们在网络传输的过程中,把分组交付到主机或路由器需要两级地址:物理地址和逻辑地址.而且我们需要能够把物理地址映射成为相应的逻 ...
- Hibernate Annotation 设置字段的默认值
很简单,不过有点莫名其妙的意思 @Column(name="powerLoad",columnDefinition="bit(1) default 1 ") p ...
- 面向对象三大特性一一多态(polymorphism)
package com.bjsxt.oop.polymorphism; public class Animal { public void voice(){ System.out.println(&q ...
- FP-growth算法高效发现频繁项集(Python代码)
FP-growth算法高效发现频繁项集(Python代码) http://blog.csdn.net/leo_xu06/article/details/51332428
- memory management
1. 高端内存: 内存的物理寻址范围比虚拟寻址范围大的多,有一些内存页不能永久的映射到内核地址空间. 2. 高端内存和低端内存是内核对内存物理页的划分. 参考:http://ilinuxkernel. ...
- 基于Woodstox的StAX 2 (Streaming API for XML)解析XML
StAX (Streaming API for XML)面向流的拉式解析XML,速度快.占用资源少,非常合适处理大数据量的xml文件. 详细教程和说明可以参见以下几篇文章: 使用 StAX 解析 XM ...