手势

/*
  DHCP-based IP printer
 
 This sketch uses the DHCP extensions to the Ethernet library
 to get an IP address via DHCP and print the address obtained.
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 12 April 2011
 by Tom Igoe
 
 */

#include <SPI.h>
#include <Ethernet.h>
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
//
//define variables
//
int valread;
int valread1;
int temp=0;
int temp1=0;
String res="N" ;
 String flag ;
  String flag1;
  EthernetClient client; 
  byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
IPAddress serverIP(172,25,60,127); // IP Adress to our Server  
int serverPort=18000;


void setup() {
  

  Serial.begin(9600);
 pinMode(7, INPUT);
  pinMode(6, INPUT);
  
   if (Ethernet.begin(mac) == 0) {  
    Serial.println("Failed to configure Ethernet using DHCP");  
    // no point in carrying on, so do nothing forevermore:  
    for(;;)  
      ;  
  } 
  
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
}

void loop() {

        

  valread1=digitalRead(6);
  valread=digitalRead(7);

temp=valread;


     // Serial.println(valread1);
if( valread1==0){
 // Serial.println("left");
  flag1 ="Y";
  if(flag =="Y"){
       // Serial.println("RIGHT-left");
 res="RIGHT-left";
    flag =="N";

  }
}

  if( valread==0){
  //Serial.println("right");
  
   flag ="Y";
  if(flag1 =="Y"){
   //Serial.println("left-RIGHT");
 res="left-RIGHT";
     flag1 ="N";
  }
  
}

if(valread==1&&valread1==1&&res!="N"){

 Serial.println(res);
 if(res=="left-RIGHT"){
     if (client.connect(serverIP, serverPort)) {  
    Serial.println("connected");//report it to the Serial  
    String msg="right;";//Message to be sent  
    Serial.println("sending Message:"+msg);//log to serial  
    client.println(msg);//send the message  
  } 
 }
   if(res=="RIGHT-left"){
     if (client.connect(serverIP, serverPort)) {  
    Serial.println("connected");//report it to the Serial  
    String msg="left;";//Message to be sent  
    Serial.println("sending Message:"+msg);//log to serial  
    client.println(msg);//send the message  
  } 
 }
 res="N";
   client.stop();
}
  delay(10); 
    //  Serial.println(valread);





}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值