Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // USE Arduino IDE 1.0.5-r2 or this will NOT WORK !!
- // Get older Arduino IDE's here -> https://www.arduino.cc/en/main/OldSoftwareReleases
- #define rcPin1 8 // Pin 8 Connected to CH1 of Transmitter;
- int ch1 = 0; // Receiver Channel 1 PPM value
- int speedValue = 511; // Set speed to zero at start
- int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
- int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)
- void setup() {
- pinMode(rcPin1, INPUT);
- Serial.begin(115200);
- pinMode(RPWM_Output, OUTPUT);
- pinMode(LPWM_Output, OUTPUT);
- }
- void loop() {
- // Read in the length of the signal in microseconds
- ch1 = pulseIn(rcPin1, HIGH, 20000); // (Pin, State, Timeout)
- speedValue = map(ch1, 1000,2000,200,1023);
- if (speedValue < 512)
- {
- // reverse rotation
- int reversePWM = -(speedValue - 511) / 2;
- analogWrite(LPWM_Output, 0);
- analogWrite(RPWM_Output, reversePWM);
- }
- else
- {
- // forward rotation
- int forwardPWM = (speedValue - 512) / 2;
- analogWrite(LPWM_Output, forwardPWM);
- analogWrite(RPWM_Output, 0);
- }
- // delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement