Advertisement
MrLunk

Arduino IBT_2 Motor Driver & RC receiver code .ino

Aug 31st, 2019
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.14 KB | None | 0 0
  1. // USE Arduino IDE 1.0.5-r2 or this will NOT WORK !!
  2. // Get older Arduino IDE's here -> https://www.arduino.cc/en/main/OldSoftwareReleases
  3.  
  4. #define rcPin1 8   // Pin 8 Connected to CH1 of Transmitter;
  5.  
  6. int ch1 = 0;  // Receiver Channel 1 PPM value
  7. int speedValue = 511; // Set speed to zero at start
  8. int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
  9. int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)
  10.  
  11. void setup() {
  12.  pinMode(rcPin1, INPUT);
  13.  Serial.begin(115200);
  14.  pinMode(RPWM_Output, OUTPUT);
  15.  pinMode(LPWM_Output, OUTPUT);
  16. }
  17.  
  18. void loop() {
  19.  
  20. // Read in the length of the signal in microseconds
  21.  ch1 = pulseIn(rcPin1, HIGH, 20000);  // (Pin, State, Timeout)
  22.  speedValue = map(ch1, 1000,2000,200,1023);
  23.  
  24.   if (speedValue < 512)
  25.  {
  26.    // reverse rotation
  27.    int reversePWM = -(speedValue - 511) / 2;
  28.    analogWrite(LPWM_Output, 0);
  29.    analogWrite(RPWM_Output, reversePWM);
  30.  }
  31.  else
  32.  {
  33.    // forward rotation
  34.    int forwardPWM = (speedValue - 512) / 2;
  35.    analogWrite(LPWM_Output, forwardPWM);
  36.    analogWrite(RPWM_Output, 0);
  37.  }
  38.  
  39.  // delay(50);
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement