Возможно ли по коду определить монтажную схему?

NVN Plus
Offline
Зарегистрирован: 04.12.2017

Приветствую.

Предосталяю для анализа всю имеющуюся информацию по этому вопросу.

https://www.youtube.com/watch?v=OW-Bf3yjUyE

 

Wiring diagrams:

 

 

Код:

/* Start button is Digital Pin 7, SyRen S1 is connected to Arduino Digital Pin 1 (TX), Proximities are Digital Pins 2 and 3, Pots are Analog Pins 1 and 2 */
 
#include <SyRenSimplified.h>
const int StopButton = 7;
const int ForwardButton = 3;   
const int ReverseButton = 2;
const int ForwardSpeedPin = A1;
const int ReverseSpeedPin = A2;
 
int ForwardState = 0;
int ReverseState = 0;
int StopState = 0;
int ForwardSpeed = 0;
int ReverseSpeed = 0;
int CurrentState = 0;  // 0 is stopped, 1 is forward, 2 is reverse
 
SyRenSimplified ST; // Simplified Serial Mode. Baud rate of 9600. Arduino TX->1  ->  Sabertooth S1   Arduino GND    ->  Sabertooth 0V      [ST.motor(1, X);  X of 0 is full reverse, 128 is stop, 255 full forward] <--- WRONG!  -127 full reverse, 0 stop, 127 full forward
 
void setup()
  {
  SyRenTXPinSerial.begin(9600); // This is the baud rate you chose with the DIP switches.  
  ST.motor(1, 0);   
  
  ForwardState = digitalRead(ForwardButton);
  ReverseState = digitalRead(ReverseButton);
  ForwardSpeed = analogRead(ForwardSpeedPin);
  ReverseSpeed = analogRead(ReverseSpeedPin);
  ForwardSpeed = map(ForwardSpeed,0,1023,60,1);
  ReverseSpeed = map(ReverseSpeed,0,1023,-60,-1);
  }
 
void loop()
  {
    ForwardState = digitalRead(ForwardButton);
    ReverseState = digitalRead(ReverseButton);
    StopState = digitalRead(StopButton);
  
    //SET THREE DIFFERENT STATES (FORWARD, REVERSE, STOP)
      if (ForwardState == LOW) 
         {      //up state  
          CurrentState = 1; 
         }
   
      if (ReverseState == LOW) 
         {    // down state
          CurrentState = 2;
         }
   
      if (StopState == LOW)
        {
         CurrentState = 0;
         ST.motor(1, 0);
        }
        //FINISHED WITH "SET THREE DIFFERENT STATES (FORWARD, REVERSE, STOP)"
  
  
      if (CurrentState == 0)
         {
         ST.motor(1, 0);
         delay(2000);
         }
 
      if (CurrentState == 1)
         {  //Forward
         delay(2000);
         ST.motor(1,ForwardSpeed);
         ForwardSpeed = analogRead(ForwardSpeedPin);
         ForwardSpeed = map(ForwardSpeed,0,1023,60,1); 
         }
 
      if (CurrentState == 2)
         {  //Reverse
         delay(2000);
         ST.motor(1, ReverseSpeed);
         ReverseSpeed = analogRead(ReverseSpeedPin);
         ReverseSpeed = map(ReverseSpeed,0,1023,-60,-1);
         } 
 
 
  }
sadman41
Offline
Зарегистрирован: 19.10.2016

Да.

NVN Plus
Offline
Зарегистрирован: 04.12.2017

СПС