Skip to main content
Cl.1
Associate III
April 2, 2020
Question

I am a totally new in code also totally new in use STM32F407 and now i doing the assignment for implementation of a state machine that will be driven by the joystick input.

  • April 2, 2020
  • 10 replies
  • 3486 views

The question including in the 1st picture i want to ask that is that any material allow me to learn for coding and solve assignment question.
_legacyfs_online_stmicro_images_0693W000000VCg6.png2nd picture whole part of board
_legacyfs_online_stmicro_images_0693W000000VClB.png3rd picture is STM32F407
_legacyfs_online_stmicro_images_0693W000000VCkw.png4th picture is the part of the joystick
_legacyfs_online_stmicro_images_0693W000000VCkh.png

This is my currency code :

#include "***-02.h"

uint8_t

GetJoystick ()

{

 // REPLACE THE FOLLOW CODE WITH YOUR SOLUTION

 // This code just to generate some input from the joystick

 static uint8_t PreviousJoystick='L';

 uint8_t Joystick;

 Joystick = ReadJoystick ();

 if (Joystick != 0)

 {

  PreviousJoystick = Joystick;

 }

 HAL_Delay(1000);

 return PreviousJoystick;

}

void

StateMachine ()

{

 // REPLACE THE FOLLOW CODE WITH YOUR SOLUTION

 // This code just toggles top LED and set left or right LED.

 //

 // Solution.

 uint8_t Joystick;

 uint8_t Toggle = 0;

 while (1)

 {

  Joystick = GetJoystick();

  if (Joystick == 'L')

  {

   WriteLED ('L', LED_ON);

   WriteLED ('R', LED_OFF);

  }

  else if (Joystick == 'R')

  {

   WriteLED ('L', LED_OFF);

   WriteLED ('R', LED_ON);

  }

  if (Toggle == 0)

  {

   WriteLED ('T', LED_ON);

   Toggle = 1;

  }

  else

  {

   WriteLED ('T', LED_OFF);

   Toggle = 0;

  }

 }

}

Thanks for any help in advance!!!

This topic has been closed for replies.

10 replies

Tesla DeLorean
Guru
April 2, 2020

Looks like homework. What books were assigned to the course, and what prerequisites?

If coding in C the classic K&R book on the language would be a good start.

What other languages are you familiar with, presuming this is college level assignment.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Cl.1
Cl.1Author
Associate III
April 2, 2020

As i mention this is a assignment and i using the system work​bench for STM32 for programming.

I totally new in the coding so more prefer and book that about coding in System Workbench STM32 thus i able learn for the assignment.

Thanks you so much for taking time to reply me.

Tesla DeLorean
Guru
April 2, 2020

The "State Machine" is really a mechanism where you advanced based on where you are currently and the next path you take base on input.

You want a switch/case statement to separate the current state, and then in each case change the next state based on the joystick input.

Following that you want a second switch/case statement which takes the state and translates that into the LED on/off desired to represent it.

How the tool chain works seems secondary to the underlying need to apply the logic the assignment asks for.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
waclawek.jan
Super User
April 2, 2020

And the code to blink a LED works?

JW

Cl.1
Cl.1Author
Associate III
April 3, 2020

Definitely correct i need to coding to control the LED work following by the step in the 1st picture i inlcuding in my question.

CS

Pavel A.
April 2, 2020

@Cl.1​ The key to implement the code is table 2: it explains what to do when you move from one state to another.

So, whenever you get the joystick input and change state according to it, just set all LEDs at once, as required for the new state, per table 2.

So the flow is like this:

START: state = AllLedOff

NEXT: set_all_leds(state)

input = wait_input()

state = find_new_state(input)

goto NEXT

Good luck.

-- pa

Cl.1
Cl.1Author
Associate III
April 3, 2020

Yes, what you understand is what bothers me.

Do u have any similar reference about the coding?

At this moment i clearly understanding the theory but ​at a totally loss about coding.

Thanks,