cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Cl.1
Associate II

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!!!

10 REPLIES 10

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
Up vote any posts that you find helpful, it shows what's working..

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.

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
Up vote any posts that you find helpful, it shows what's working..

And the code to blink a LED works?

JW

Pavel A.
Evangelist III

@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
Associate II

I understand the theory about this assignment do u have any other related reference about it?

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

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,

I'm not going to do the assignment for you, if you want that level help I'd suggest discussing with your teacher/tutor

You could use if/then/else if that's easier to grasp.

I'd personally use switch/case, try this or pull a copy of the K&R C manual

https://docs.microsoft.com/en-us/cpp/c-language/switch-statement-c?view=vs-2019

Trying Googling "switch case state machine"

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..