pwm method

Future<bool> pwm(
  1. int pwmOutput
)

Assigns the analog (PWM) output value. (BITalino 2 only) Returns true if the command is sent successfully, false otherwise.

Throws BITalinoException(BITalinoErrorType.NOT_IMPLEMENTED_IOS) if this method is called on IOS devices. Throws BITalinoException(BITalinoErrorType.NOT_BITALINO2) if the device is not BITalino2. Throws BITalinoException(BITalinoErrorType.TIMEOUT) if the timeout limit is reached. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED) if a device is not connected. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_CANNOT_BE_RECORDING) if the device is recording. Throws BITalinoException(BITalinoErrorType.CUSTOM) if a native exception was raised.

Implementation

Future<bool> pwm(int pwmOutput) async {
  if (Platform.isIOS)
    throw BITalinoException(BITalinoErrorType.NOT_IMPLEMENTED_IOS);
  if (Platform.isAndroid && !(await isBITalino2()))
    throw BITalinoException(BITalinoErrorType.NOT_BITALINO2);
  if (!connected)
    throw BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED);
  if (recording)
    throw BITalinoException(BITalinoErrorType.BT_DEVICE_CANNOT_BE_RECORDING);

  try {
    return await (_channel.invokeMethod("pwm", <String, dynamic>{
      "pwmOutput": pwmOutput,
    }).timeout(timeout) as FutureOr<bool>);
  } on TimeoutException {
    throw BITalinoException(BITalinoErrorType.TIMEOUT);
  } catch (e) {
    throw BITalinoException(BITalinoErrorType.CUSTOM, e.toString());
  }
}