2020-04-02 01:49 AM - edited 2023-11-20 09:27 AM
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.
2nd picture whole part of board
3rd picture is STM32F407
4th picture is the part of the joystick
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!!!
2020-04-02 05:08 AM
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.
2020-04-02 06:12 AM
As i mention this is a assignment and i using the system workbench 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.
2020-04-02 08:59 AM
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.
2020-04-02 09:15 AM
And the code to blink a LED works?
JW
2020-04-02 09:16 AM
@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
2020-04-02 06:25 PM
I understand the theory about this assignment do u have any other related reference about it?
2020-04-02 06:28 PM
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
2020-04-02 06:32 PM
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,
2020-04-02 07:11 PM
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"