本帖最後由 j82888 於 2014-8-25 22:24 編輯
這是我們學長WIFI操控Arduino自走車的程式碼,
他們設置一網頁設在C:\0913\資料夾內的網頁(.html) 設置按鈕,
點網頁按鈕利用wifi及wifi版控制車的行走,
但我們學長已經畢業,我們要延用他們的作一些更改,
但有很多對程式內不懂的地方。
我用學長同樣的電腦 同樣的ip 同樣的wifi(密碼) 那網頁設置的地方一樣,還是有錯。
第一、winserver was not declared in this scope 在跑時,我是不是Arduino內的libraries資料夾忘了安裝/放 什麼?
第二、它們怎知道按按鈕的網頁怎連結到那wifi版,我以為程式碼內會寫C:\0913\...html.之類的,結果沒有。
第三、我們老師希望我們能捨棄用網頁按按鈕的方式控制車子,
丟給我們kinect機器利用人的姿勢體感操控車,是不是只要把程式碼網頁部分(紅色)的做修改跟kinect連結就好?
至於馬達部份大概我們已經瞭解了,只是怎跟網頁互動不太懂,要懂才會改啊...。
/*
* A simple sketch that uses Web Server with Motoduino WiFi Shield.
*/
// Note: Please only define APP_WISERVER in apps-conf.h
//
#include <WiServer.h>
const int Motor_E1 = 5; // Pin 5 of Motoduino
const int Motor_E2 = 6; // Pin 6 of Motoduino
const int Motor_M1 = 7; // Pin 7 of Motoduino
const int Motor_M2 = 8; // Pin 8 of Motoduino
//1. SPI
//Slave select (SS) : Arduino pin 10 (port B, pin 2)
//Clock (SCK) : Arduino pin 13 (port B, pin 5)
//Master in, slave out (MISO) : Arduino pin 12 (port B, pin 4)
//Master out, slave in (MOSI) : Arduino pin 11 (port B, pin 3)
//2. Interrupt (Uses only one of the following, depending on jumper setting)
//INT0 : Arduino pin 2 (port D, pin 2)
//DIG8 : Arduino pin 8 (port B, pin 0)
//3. Interrupt selection jumper
//Do NOT leave it unconnected, you need select one.
//4. LED Indicator: Arduino pin 9 (port B, pin 1)
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,11,8}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,11,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
char ssid[] = {"S409"}; // max 32 bytes
unsigned char security_type = 1; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"abcde"}; // max 64 characters
byte sampledata=50;
char link[]="http://motoduino.com/"; //link data
// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {
0x61, 0x62, 0x63, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
boolean mainpage()
{
WiServer.println("<html>");
WiServer.println("<head>");
WiServer.println("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
WiServer.println("</head>");
WiServer.println("<body>");
WiServer.println("<table border=\"1\" cellpadding=\"3\" cellspacing=\"3\" align=\"center\">");
WiServer.println("<th> </th>");
WiServer.println("<th>");
WiServer.println("<form method=get>");
WiServer.println("<input type=hidden name=V value=F /><br />");
WiServer.println("<input type=submit value=前進>");
WiServer.println("</form>");
WiServer.println("</th><th> </th>");
WiServer.println("</tr>");
WiServer.println("<tr><th>");
WiServer.println("<form method=get >");
WiServer.println("<input type=hidden name=V value=L /><br />");
WiServer.println("<input type=submit value=左轉>");
WiServer.println("</form>");
WiServer.println("</th><th>");
WiServer.println("<form method=get >");
WiServer.println("<input type=hidden name=V value=S /><br />");
WiServer.println("<input type=submit value=停止>");
WiServer.println("</form>");
WiServer.println("</th><th> ");
WiServer.println("<form method=get >");
WiServer.println("<input type=hidden name=V value=R /><br />");
WiServer.println("<input type=submit value=右轉>");
WiServer.println("</form>");
WiServer.println("</th></tr> <tr> <th> </th> <th> ");
WiServer.println("<form method=get >");
WiServer.println("<input type=hidden name=V value=B /><br />");
WiServer.println("<input type=submit value=後退>");
WiServer.println("</form>");
WiServer.println(" </th> <th> </th> </tr>");
WiServer.println("</table>");
WiServer.println("<br/>");
WiServer.println("</body>");
WiServer.println("</html>");
return true;
}
boolean controlpage(char* URL)
{
// Serial.println(URL);
if (strcmp(URL, "/") == 0)
{
mainpage();
return true;
}
else
{
if(URL[1] == '?')
{
if((URL[2] == 'V') && (URL[3] == '='))
{
switch(URL[4])
{
case 'F':
forward(0, 0);
break;
case 'B':
back(0, 0);
break;
case 'L':
left(0, 0);
break;
case 'R':
right(0, 0);
break;
case 'S':
motorstop(0, 0);
break;
}
}
mainpage();
return true;
}
}
}
void motorstop(byte flag, byte numOfValues)
{
analogWrite( Motor_E1, 0);
analogWrite( Motor_E2, 0);
Serial.println("stop : ");
}
void forward(byte flag, byte numOfValues)
{
digitalWrite( Motor_M1, HIGH);
digitalWrite( Motor_M2, LOW);
analogWrite( Motor_E1, 255);
analogWrite( Motor_E2, 255);
Serial.println("forward : ");
}
void back(byte flag, byte numOfValues)
{
digitalWrite( Motor_M1, LOW);
digitalWrite( Motor_M2, HIGH);
analogWrite( Motor_E1, 255);
analogWrite( Motor_E2, 255);
Serial.println("back : ");
}
void right(byte flag, byte numOfValues)
{
digitalWrite( Motor_M1, HIGH);
digitalWrite( Motor_M2, LOW);
analogWrite( Motor_E1, 0);
analogWrite( Motor_E2, 255);
Serial.println("right : ");
}
void left(byte flag, byte numOfValues)
{
digitalWrite( Motor_M1, HIGH);
digitalWrite( Motor_M2, LOW);
analogWrite( Motor_E1, 255);
analogWrite( Motor_E2, 0);
Serial.println("left : ");
}
void setup() {
Serial.begin(9600);
// set all color leds as output pins
pinMode(Motor_M1, OUTPUT);
pinMode(Motor_M2, OUTPUT);
WiServer.init(controlpage);
// Enable Serial output and ask WiServer to generate log messages (optional)
WiServer.enableVerboseMode(true);
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
} |