Hi Richard, sorry to be a pest but I just can’t get float variables past the compiler (#define SPEED33 3.5f)
I have a working sketch but it it somewhat brutal haha! I am not calling the speed externally, instead it’s part of the loop. The motor.disable and motor.enable are keepers via momentary buttons, but not sure about having constantly sent out motor.move messages using a toggle switch. Buttons are now LOW for pullup and connected to ground. So, it works really well but not sure if this a proper way to do it. Thanks!
Just added a funny vid.
// Open loop motor control example
#include <SimpleFOC.h>
bool doonce = 1;
int debouncetime = 10000;
const int BUTTON_PIN = 7;
int input4Pin = 7;
int input3Pin = 4;
int input2Pin = 3;
int input1Pin = 2;
// this declares each of our buttons and their pins
// make sure that you use the pins your buttons are wired to
// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor (7, 5, 255);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
// Stepper motor & driver instance
//StepperMotor motor = StepperMotor(50);
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
void setup() {
pinMode(input4Pin, INPUT_PULLUP);
pinMode(input3Pin, INPUT_PULLUP);
pinMode(input2Pin, INPUT_PULLUP);
pinMode(input1Pin, INPUT_PULLUP); // these lines declare each of the buttons as an input
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
// limit the maximal dc voltage the driver can set
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor.voltage_limit = 4
; // [V]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
Serial.begin(115200);
Serial.println(“Motor ready!”);
Serial.println(“Set target velocity [rad/s]”);
_delay(1000);
}
void loop() {
// read the state of the switch/button:
int buttonState = digitalRead(BUTTON_PIN);
// print out the button’s state
Serial.println(buttonState);
// button on pin 2
if (digitalRead(2)==LOW) { // high state means on
motor.disable(); // stops motor
}
// button on pin 3
if (digitalRead(3)==LOW) { // high state means on
motor.move(29.12); // this button sets the speed to 33.3rpm
}
// button on pin 4
if (digitalRead(4)==LOW) { // high state means on
motor.move(39.3); // this button sets the speed to 45rpm
}
// button on pin 7
if (digitalRead(7)==LOW) { // high state means on
motor.enable(); // starts motor
doonce = 1;
delay(debouncetime);
}
}