Speed control

This function will update the duty cycle of the enable pin of both the motors and vary the speed of rotation:

module.exports.motor_speed = function(pwm,callback){  console.log(pwm)  enable_1.pwmWrite(pwm);   enable_2.pwmWrite(pwm);   console.log ("speed change")   callback("speed change")}

An indicator function is required which will make indicator LEDs on the left front and right front of the car blink whenever car makes a turn:

indicatorLeft = function(){ leftIndicatorHandler = setInterval(function() {  if(front_left_LED.digitalRead()==1){        front_left_LED.digitalWrite(0)    }    else{       front_left_LED.digitalWrite(1)    }  },250)} 

Now we will create an MQTT client for the car which will receive the commands from the MQTT broker. Here we are ...

Get Internet of Things with Raspberry Pi 3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.