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!

I made one

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

Give feedback

Comments

Similar projects you might like

Using CA and CC RGB LED by Current Sourcing and Sinking!
Easy
  • 618
  • 48

Protip

RGB LEDs are of two types, common cathode and common anode which behave differently with same Arduino code; how to resolve this.

Break your heart - The Arduino ON LED blinking
Easy
  • 16
  • 1

Full instructions

This is the project who don't know about Arduino and Arduino IDE yet. Now, break it!!!

Arduino Amiga Floppy Disk Reader
Easy
  • 6,101
  • 9

Work in progress

An Arduino powered floppy disk controller and reader for making disk images from old AmigaDOS floppy disks.

MKR FOX 1200 Movement Trigger
Easy
  • 1,076
  • 3

Full instructions

Use your MKR FOX 1200 as a movement trigger to keep an eye on your belongings.

How to use the accelerometer- gyroscope GY-521
Easy
  • 367
  • 2

Full instructions

Find out how the world turns. Read the values of the accelerometer and the gyroscope.

Simple Dark Sensor
Easy
  • 110
  • 2

A simple dark sensor with or without Arduino.

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog