Things used in this project

Code

RC_Car.inoC/C++
#include "SPI.h"
#include "Phpoc.h"

PhpocServer server(80);

char slideName;
int slideValue;

int pwm_a = 5;
int pwm_b = 6;
int dir_a = 4;
int dir_b = 7;

void setup() {
  
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_a, OUTPUT);
  pinMode(dir_b, OUTPUT);
  
  analogWrite(pwm_a, 0);  //set both motors to run at (100/255 = 39)% duty cycle (slow)
  analogWrite(pwm_b, 0);  
  
  Serial.begin(9600);
  while(!Serial)
    ;

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  //Phpoc.begin();

  server.beginWebSocket("remote_slide");

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

void loop() {
  // wait for a new client:
 PhpocClient client = server.available();

  if (client) {
    String slideStr = client.readLine();

    if(slideStr)
    {
      slideName = slideStr.charAt(0);
      slideValue = slideStr.substring(1).toInt();

      Serial.print(slideName);
      Serial.print('/');
      Serial.println(slideValue);
      
     if(slideName == 'A'){
        
          Serial.println(slideValue);
          
          if(slideValue < 0) {
            digitalWrite(dir_a, HIGH);            
            slideValue = slideValue * -1 * 255 / 100;
          } else {
            digitalWrite(dir_a, LOW);    
             slideValue = slideValue * 255 / 100;      
          }
              Serial.println(slideValue);          
              analogWrite(pwm_a, slideValue);          
      }    
      
     if(slideName == 'B'){
        
          Serial.println(slideValue);
          
          if(slideValue < 0) {
            digitalWrite(dir_b, HIGH);            
            slideValue = slideValue * -1 * 255 / 100;
          } else {
            digitalWrite(dir_b, LOW);    
             slideValue = slideValue * 255 / 100;      
          }          
             Serial.println(slideValue);          
             analogWrite(pwm_b, slideValue);            
      }    
    }
  } 

}

Credits

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Play a Song with Stepper Motor
Easy
  • 48
  • 6

Play a harmonized song with two stepper motors connected to a PHPoC blue or black and stepper motor smart expansion boards (PES-2403).

Laser Stuff
Easy
  • 452
  • 3

A laser module that makes light patterns.

LEDog Collar
Easy
  • 683
  • 9

Full instructions

The LEDog collar lights up when it gets dark, helping you locate your dog from far away.

Handheld Infinity Kaleidoscope Group Kit
Easy
  • 2,476
  • 30

Full instructions

Use the orientation sensor in your Arduino 101 to control a cool Petri dish infinity-mirror illusion. This project is great for groups.

A Tone Generator with LCD Display!
Easy
  • 209
  • 3

Full instructions

This is a tone selector with the ability to change the buzzer frequency by a potentiometer and to see the result on a 16x2 display.

SECURITY SYSTEM AND ACCESs CONTROL WITH ARDUINO AND RFID
Easy
  • 628
  • 8

Full instructions

To enter passwords and to allow access to a door or to drive an electronic device, now we will use a RFID device

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback