Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Peter Cuellar
Created November 2, 2015

Econocar RC Testing

A blend between traditional mechanical systems and modern CNC techniques

Showcase (no instructions)40
Econocar RC Testing

Story

Read more

Code

RC Wired

C/C++
/* 

RC Controlled Vehicle 
by Peter Cuellar 
11/10/15
*/

#include <Servo.h>

Servo mydrive;  // create servo object to control a servo
Servo mysteering;

int potpin = 0;
int potst = 1; // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int steer;
void setup()
{
  mydrive.attach(6);
  mysteering.attach(5);
  // attaches the servo on pin 9 to the servo object
}

void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180) 
  mydrive.write(val);                  // sets the servo position according to the scaled value 
  delay(150);    
  
  steer = analogRead(potst);            // reads the value of the potentiometer (value between 0 and 1023) 
  steer = map(steer, 0, 1023, 55, 135);     // scale it to use it with the servo (value between 0 and 180) 
  mysteering.write(steer);                  // sets the servo position according to the scaled value 
  delay(150);  // waits for the servo to get there 
  Serial.print(steer,int);
} 

Credits

Peter Cuellar

Peter Cuellar

10 projects • 2 followers
Designer, Engineer, Environmentalist

Comments