Robofun 機器人論壇
標題:
Ardunio Wi-Fi 控制自走車
[打印本頁]
作者:
guadiandehao
時間:
2014-10-28 22:40
標題:
Ardunio Wi-Fi 控制自走車
請問為甚麼燒以下這個程式碼 輸入IP之後可以正常顯示[attach]7753[/attach]
#include <WiShield.h>
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
const int moto1PinA = 7;
const int moto1PinB = 8;
const int speedPinA = 6;
const int moto2PinA = 4;
const int moto2PinB = 3;
const int speedPinB = 5;
unsigned char local_ip[] = {192,168,0,120};
unsigned char gateway_ip[] = {192,168,0,1};
unsigned char subnet_mask[] = {255,255,255,0};
const prog_char ssid[] PROGMEM = {"dirtyboy"};
unsigned char security_type = 0;
const prog_char security_passphrase[] PROGMEM = {""};
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // 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
};
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
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=\"1\" cellspacing=\"1\" 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("</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( speedPinA, 0);
analogWrite( speedPinB, 0);
Serial.println("stop : ");
}
void forward(byte flag, byte numOfValues){
digitalWrite( moto1PinA, HIGH);
digitalWrite( moto1PinB, LOW);
digitalWrite( moto2PinA, HIGH);
digitalWrite( moto2PinB, LOW);
analogWrite( speedPinA, 255);
analogWrite( speedPinB, 255);
Serial.println("forward : ");
}
void back(byte flag, byte numOfValues){
digitalWrite( moto1PinA, LOW);
digitalWrite( moto1PinB, HIGH);
digitalWrite( moto2PinA, LOW);
digitalWrite( moto2PinB, HIGH);
analogWrite( speedPinA, 255);
analogWrite( speedPinB, 255);
Serial.println("back : ");
}
void right(byte flag, byte numOfValues){
digitalWrite( moto1PinA, LOW);
digitalWrite( moto1PinB, HIGH);
digitalWrite( moto2PinA, HIGH);
digitalWrite( moto2PinB, LOW);
analogWrite( speedPinA, 255);
analogWrite( speedPinB, 255);
Serial.println("right : ");
}
void left(byte flag, byte numOfValues){
digitalWrite( moto1PinA, HIGH);
digitalWrite( moto1PinB, LOW);
digitalWrite( moto2PinA, LOW);
digitalWrite( moto2PinB, HIGH);
analogWrite( speedPinA, 255);
analogWrite( speedPinB, 255);
Serial.println("left : ");
}
void setup() {
Serial.begin(9600);
pinMode( moto1PinA, OUTPUT);
pinMode( moto1PinB, OUTPUT);
pinMode( moto2PinA, OUTPUT);
pinMode( moto2PinB, OUTPUT);
pinMode( speedPinA, OUTPUT);
pinMode( speedPinB, OUTPUT);
WiServer.init(controlpage);
WiServer.enableVerboseMode(true);
}
void loop(){
WiServer.server_task();
delay(10);
}
複製代碼
但是改成這樣之後 就無法開啟網頁呢?我只是修改了網頁的部分而已
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=\"1\" cellspacing=\"1\" 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("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
WiServer.println("<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>");
WiServer.println("<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>");
WiServer.println("<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>");
WiServer.println("<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>");
WiServer.println("</table>");
WiServer.println("</body>");
WiServer.println("</html>");
return true;
}
複製代碼
網頁部分同樣的程式碼 我用TXT檔改成HTML檔去試
可以顯示出[attach]7752[/attach]
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2