#include <SPI.h>
#include "WizFi250.h"
#include <Servo.h>
char ssid[] = "AndroidHotspot7725"; // your network SSID (name)
char pass[] = "20150521"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
Servo myservo;
int sensor = A2;
int servo = 11;
int val =0;
char server[] = "192.168.43.145";
// Initialize the Ethernet client object
WiFiClient client;
void printWifiStatus();
void setup()
{
Serial.begin(115200);
//Serial.begin(9600);
myservo.attach(servo);
WiFi.init();
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connect(server, 3001)) {
Serial.println("Connected to server");
// Make a HTTP request
//client.println(value);
client.println(val);
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them
val = analogRead(sensor);
int angle = map(val, 0, 1023, 0, 180);
Serial.println(angle);
myservo.write(angle);
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
압력센서 val값은 시리얼모니터에 제대로 뜨는데
연결해놓은 서보모터가 작동을 하지 않네요ㅠ
무슨코드문제일까요ㅠ
|