Соединить два скетча в один

Тема в разделе "Закажу проект", создана пользователем forfuckingsay9, 26 май 2019.

  1. Привет всем! помогите соединить два кода. первый для соединения
    Код (Text):

    #include <car_bluetooth.h>
    #include <SoftwareSerial.h>   //Software Serial Port
    #include <String.h>
    #include "MotorDriver.h"

    #define RxD 2//D2 of Arduino should connect to TX of the Serial Bluetooth module
    #define TxD 4//D4 of Arduino should connect to RX of the Serial Bluetooth module
    CarBluetooth bluetooth(RxD, TxD);
    #define CMD_INVALID     0XFF
    #define CMD_FORWARD     'F'
    #define CMD_RIGHT_FRONT 'R'

    #define CMD_BACKWARD    'B'

    #define CMD_LEFT_FRONT  'L'
    #define CMD_STOP        'S'

    #define SPEED_STEPS 20
    uint8_t speed0 = 100;

    void setup(){
      motordriver.init();  
      motordriver.setSpeed(100,MOTORA);
      motordriver.setSpeed(100,MOTORB);
      bluetooth.waitConnected();

    }
    uint8_t bt_command;

    #define CAR_STOP 0
    #define CAR_FORWARD 1
    #define CAR_BACK 2
    uint8_t car_status = CAR_STOP;
    uint8_t new_status = car_status;

    void loop(){
      bt_command = bluetooth.readByte();

      if(bt_command != CMD_INVALID){
      controlCar(bt_command);
      }

    }


    void controlCar(uint8_t cmd){
       switch(cmd)
      {
        case CMD_FORWARD:     motordriver.goForward();break;
      case CMD_RIGHT_FRONT:
      //  if(car_status != CAR_STOP)new_status = CAR_FORWARD;
        motordriver.goRight();
       // delay(200);
        break;
      case CMD_BACKWARD:    motordriver.goBackward(); break;
      case CMD_LEFT_FRONT:
        motordriver.goLeft();
       // delay(200);
        break;
      case CMD_STOP:        motordriver.stop();break;
      default: break;
      }
      if((cmd>='0')&&(cmd<='9'))
      {
          speed0 = cmd-0x30;
        Serial.print(speed0);
        Serial.print(">");
        speed0 = map(speed0, 0, 9, 0, 255);
        Serial.println(speed0);
        motordriver.setSpeed(speed0,MOTORA);
        motordriver.setSpeed(speed0,MOTORB);
      }
    }

    void speedUp(){
      if(speed0 < 236)speed0 += SPEED_STEPS;
      else speed0 = 255;
      motordriver.setSpeed(speed0,MOTORA);
      motordriver.setSpeed(speed0,MOTORB);
    }

    void speedDown(){
      if(speed0 > 70)speed0 -= SPEED_STEPS;
      else speed0 = 50;
       motordriver.setSpeed(speed0,MOTORA);
      motordriver.setSpeed(speed0,MOTORB);
    }

     
     
  2. Второй для дисплея
    Код (Text):

    //Demo for Ultrasonic Sensor and 4-Digit Display module
    //by Catalex
    //Demo Function: Use the Ultrasonic Sensor module to detect the distance and
    //               display it on the 4-digit Display module
    //Store: http://www.aliexpress.com/store/1199788
    //      http://dx.com
    #include <Ultrasonic.h>
    #include "TM1637.h"
    //module--- Arduino
    //VCC   --- 5V
    //GND   --- GND
    #define TRIGGER_PIN  5//connect Trip of the Ultrasonic Sensor moudle to D5 of Arduino
                          //and can be changed to other ports
    #define ECHO_PIN     3
    Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

    #define CLK A5//connect CLK of the 4-Digit Display to A5 of Arduino and can be changed to other ports  
    #define DIO A4//
    TM1637 disp(CLK,DIO);

    void setup()
      {
       disp.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
      disp.init();
      }

    void loop()
      {
      float cmMsec, inMsec;
      long microsec = ultrasonic.timing();

      cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
      inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
      disp.display((int16_t)cmMsec);//in centimeters
      delay(500);
      }
     
     
  3. Daniil

    Daniil Гуру

    Боюсь, вам тут не помогут.
     
    NikitOS нравится это.
  4. sser

    sser Гик

    А что это?
     
  5. Скетчи для мобильного робота. Первый это bluetooth соединение, а второй ультразвуковай датчик с дисплеем
     
  6. Onkel

    Onkel Гуру

    Конфликт по железу будет, конфликт библиотек по таймерам. Просто "соединить" не получится. Можно на основе 1го скетча написать фрагмент кода, который будет работать с дисплеем. Пишите ydom@mail.ru
     
  7. Developer-RU

    Developer-RU Гик

    Правильнее написать. А это уже совсем другое дело и цена вопроса.