Roy LEE
Published © GPL3+

Web-Based Servo Control with PHPoC Shield for Arduino

Control servo by web.

BeginnerShowcase (no instructions)1 hour6,354
Web-Based Servo Control with PHPoC Shield for Arduino

Things used in this project

Code

Web-based Servo Control with PHPoC Shield for Arduino

C/C++
Web-based Servo Control with PHPoC Shield for Arduino
#include "SPI.h"
#include "Phpoc.h"
#include "Servo.h"

PhpocServer server(80);
Servo myservo;
char slideName;
int slideValue;

void setup() {

  myservo.attach(9);
  
  Serial.begin(115200);
  while(!Serial)
    ;

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  server.beginWebSocket("remote_slide");

  Serial.print("WebSocket server address : ");
  Serial.println(Phpoc.localIP());  
}

void loop() {
  PhpocClient client = server.available();
  
  if (client) {
    String slideStr = client.readLine();
    
    if(slideStr) {
      slideName = slideStr.charAt(0);
      slideValue = slideStr.substring(1).toInt();
      
      if(slideName == 'A'){
        int pos = map(slideValue, -100, 100, 0, 180);
        myservo.write(pos);
        Serial.println(pos);
      }
    }
  }
}

Credits

Roy LEE

Roy LEE

1 project • 5 followers

Comments