Jump to content


Photo

wifi shield v2 robot


  • Please log in to reply
1 reply to this topic

#1 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 15 September 2014 - 01:46 AM

i need the source code of this project http://v.youku.com/v...kwNTM0OTA0.html

where can i download? 


  • carpinteyrolkh likes this

#2 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 15 September 2014 - 02:56 AM

#include <WiShield.h>

 

#define WIRELESS_MODE_INFRA   1

#define WIRELESS_MODE_ADHOC 2

#define BUFFSIZ 90 // plenty big

unsigned char PWM = 150;

char incomingByte;

int TriacPin =13;

char buffer[BUFFSIZ];

char buffidx;

 

int RESET_IDX=1;

int CurrentPin = 0;    

int Current_val = 0; 

 

long Current_RMS, current=0, pre_current;

long count=0;

// Wireless configuration parameters ----------------------------------------

byte local_ip[]    = {192,168,5,4};    // IP address of WiShield

byte gateway_ip[]  = {192,168,5,1};   // router or gateway IP address

byte subnet_mask[] = {255,255,255,0};       // subnet mask for the local network

prog_char ssid[] PROGMEM    = {"only_test"};            // max 32 bytes

unsigned char security_type = 0;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

 

// WPA/WPA2 passphrase

const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters

 

// WEP 128-bit keys

// sample HEX keys

prog_uchar wep_keys[] PROGMEM = {     

  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,       0x00,  // Key 0

  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,  0x00,      // Key 1

  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00,      // Key 2

  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00       // Key 3

};

 

// setup the wireless mode

// infrastructure - connect to AP

// adhoc - connect to another WiFi device

unsigned char wireless_mode = WIRELESS_MODE_INFRA;

 

unsigned char ssid_len;

unsigned char security_passphrase_len;

//---------------------------------------------------------------------------

 

 

Server server(5000);

Client client;

 

unsigned long last_serial;

 

void setup()

{

  WiFi.begin(local_ip, gateway_ip, subnet_mask);

  server.begin();

  

  RESET_IDX=1;

 

  pinMode(TriacPin, OUTPUT);

  digitalWrite(TriacPin, LOW); 

  pinMode(3,OUTPUT);

  pinMode(4,OUTPUT);

 

  pinMode(5,OUTPUT);

  pinMode(6,OUTPUT);

 

  analogWrite(A0,PWM);

  analogWrite(A1,PWM);

 

}

 

void loop()

{

      

  if (RESET_IDX==1)

  {

   buffidx = 0; // start at begninning

   RESET_IDX=0;

  }

 

   if(!client.connected())

   {

   server.available(&client);

   }

   else

   {

      while(client.available())

      {

         incomingByte = client.read();

 

      }

   } //end if

  

 

    if (incomingByte=='f')

    {  

     forward();

     RESET_IDX=1;

    }

 

   if (incomingByte=='r')

  

   {

     turn_right();

     RESET_IDX=1;

    

   }

   if (incomingByte=='l')

   {

     turn_left();

     RESET_IDX=1;

   }

   if (incomingByte=='b')

   {

     back();

     RESET_IDX=1;

   }

    if (incomingByte=='s')

   {

     sotp();

     RESET_IDX=1;

    

   }

  

}//end loop

 

void turn_right(void)

{

  digitalWrite(3,HIGH);

  digitalWrite(4,LOW);

  digitalWrite(5,HIGH);

  digitalWrite(6,LOW);

 

 analogWrite(A0, PWM);

 analogWrite(A1, PWM/2);

}

void turn_left(void)

{

  digitalWrite(4,HIGH);

  digitalWrite(3,LOW);

  digitalWrite(6,HIGH);

  digitalWrite(5,LOW);

 

  analogWrite(A0, PWM/2);

  analogWrite(A1, PWM);

}

void forward(void)

{

  digitalWrite(3,HIGH);

  digitalWrite(4,LOW);

  digitalWrite(6,HIGH);

  digitalWrite(5,LOW);

 

  analogWrite(A0, PWM);

  analogWrite(A1, PWM);

}

void back(void)

{

  digitalWrite(4,HIGH);

  digitalWrite(3,LOW);

  digitalWrite(5,HIGH);

  digitalWrite(6,LOW);

 

 analogWrite(A0,PWM);

 analogWrite(A1,PWM);

}

 

void sotp(void)

{

  digitalWrite(4,HIGH);

  digitalWrite(3,LOW);

  digitalWrite(5,HIGH);

  digitalWrite(6,LOW);

 

 analogWrite(A0,0);

 analogWrite(A1,0);

}






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users