Skip to content

The analog Joystick code doesn't work on the STM32F4 #155

Description

@chihoonl

First, I'd like to thank Luni64 for letting me use this awesome library.
Sorry about that I don't know whether this is an issue with the library or a minor mistake in my code. But the code is fully tested on Teensy 3.xx. But it doesn't work on STM32F4(Nucleo F446re, Nucleo F429zi. I tried on F411, F401 also.)
Unfortunately, I'm a newbie to STM32, so I don't know what I'm missing. (Oddly enough, when I tested simply Teensystep's classes on STM32F4 without using the joystick, most of it worked.)
Teensy 3.xx is discontinued, and I have no choice except to port my longtime projects with Teensystep to STM32. Would anyone please advise me?

#include "Arduino.h"
#include "TeensyStep.h"

const int JOY_X_PIN = A0;
const int MOTOR_STEP_PIN = 3;
const int MOTOR_DIR_PIN = 2;
const int MAX_SPEED = 18000;
const int ACCELERATION = 9000;

Stepper motor(MOTOR_STEP_PIN, MOTOR_DIR_PIN);
RotateControl rotateControl;

void setup() {
  motor.setMaxSpeed(MAX_SPEED);
  motor.setAcceleration(ACCELERATION);
  rotateControl.rotateAsync(motor);
  rotateControl.overrideSpeed(0);
}

float transformPot(float analogVal) {
  if (analogVal > 550) {
    return map(analogVal, 550, 1023, 0.0f, 1.0f);
  } else if (analogVal < 420) {
    return map(analogVal, 0, 420, -1.0f, 0.0f);
  } else {
    return 0.0f;
  }
}

void loop() {
  static float oldOvrX = 0.0f;
  float ovrX = transformPot(analogRead(JOY_X_PIN));
  if (oldOvrX != ovrX) {
    oldOvrX = ovrX;
    rotateControl.overrideSpeed(ovrX);
  }
} 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions