Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <BTS7960.h>
- // Working with new pins 03/26/21 G Liebig. Note: you must modify Library to increase PWM from 255 to 1023
- /*
- Pinouts
- WeMos IDE Nano BTS7960
- D0 16
- D1 5 A5 SCL (Serial Clock)Reseve D1
- D2 4 A4 SDA (Serial Data)Reserve D1
- D3 0 8 R_EN (3)
- D4 2 9 L_PWM (2)
- D5 14 7 L_EN (4)
- D6 12 6 R_PWM (1)
- D7 13
- D8 15
- TX 1
- RX 3
- Pin Order Reference
- BTS7960(uint8_t RPWM,uint8_t LPWM,uint8_t R_EN,uint8_t L_EN);
- */
- BTS7960 m1(12,2,0,14); //Pins used for D1 Mini
- //BTS7960 m1(6,9,8,7); //Pins used for Nano
- int speed = 0;
- float dutyCycle;
- void setup()
- {
- Serial.begin(9600);
- Serial.println("Be sure to enable 'No line ending' in Monitor window");
- Serial.println("Enter Pump Speed Negative for Left, Positive for Right");
- Serial.println("between -1023 and 1023. Anything else to stop");
- }
- void loop()
- {
- while (Serial.available() == 0)
- {
- }
- speed = Serial.parseInt();
- dutyCycle=abs(float(speed)/1023*100);
- if (speed <0){
- Serial.print("Setting Motor Speed to left (CW) with Speed = ");
- }
- else {
- Serial.print("Setting Motor Speed to right (CCW) with Speed = ");
- }
- Serial.print(speed);
- Serial.print(" Duty Cycle % = ");
- Serial.print(dutyCycle);
- Serial.println();
- if (speed >= -1023 && speed <= 1023){
- m1.enable();
- m1.setSpeed(speed);
- }
- else
- {
- Serial.println("PUMP STOPPED");
- m1.stop();
- m1.disable();
- delay(2000);
- Serial.println();
- Serial.println("Enter Pump Speed Negative for Left, Positive for Right");
- Serial.println("between -1023 and 1023. Anything else to stop");
- }
- }
Add Comment
Please, Sign In to add comment