i want to merge tf mini lidar sensor code, dc motor code and accelerometer code
#include <DFRobot_TFmini.h>
SoftwareSerial mySerial(8, 7); // RX, TX
DFRobot_TFmini TFmini;
uint16_t distance,strength;
void setup(){
Serial.begin(115200);
TFmini.begin(mySerial);
}
void loop(){
if(TFmini.measure()){ //Measure Distance and get signal strength
distance = TFmini.getDistance(); //Get distance data
strength = TFmini.getStrength(); //Get signal strength data
Serial.print("Distance = ");
Serial.print(distance);
Serial.println("mm");
Serial.print("Strength = ");
Serial.println(strength);
delay(500);
}
delay(500);
}
#include <MMA_7455.h>
#include <Wire.h> //Include the Wire library
#include <MMA_7455.h> //Include the MMA_7455 library
MMA_7455 accel = MMA_7455(); // Make MMA7455 object
char xVal, yVal, zVal; // Return value variables
void setup() {
Serial.begin(9600); // Use the Serial Monitor window at 9600 baud
// Set the g force sensitivity: 2=2g, 4=4g, 8-8g
accel.initSensitivity(2);
}
void loop() {
// Get the X, Y, anx Z axis values from the device
zVal = accel.readAxis('z'); // Read Z Axis
Serial.print(" Z: = ");
Serial.println(zVal, DEC);
delay(1000);
//and a dc motor code
/*
L298N Motor Demonstration
L298N-Motor-Demo.ino
Demonstrates functions of L298N Motor Controller
DroneBot Workshop 2017
*/
// Motor A
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B
int enB = 3;
int in3 = 5;
int in4 = 4;
void setup()
{
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void demoOne()
{
// This function will run the motors in both directions at a fixed speed
// Turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set speed to 200 out of possible range 0~255
analogWrite(enA, 200);
// Turn on motor B
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Set speed to 200 out of possible range 0~255
analogWrite(enB, 200);
delay(2000);
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void demoTwo()
{
// This function will run the motors across the range of possible speeds
// Note that maximum speed is determined by the motor itself and the operating voltage
// Turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Accelerate from zero to maximum speed
for (int i = 0; i < 256; i++)
{
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Decelerate from maximum speed to zero
for (int i = 255; i >= 0; --i)
{
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop()
{
demoOne();
delay(1000);
demoTwo();
delay(1000);
}