We take the circuit and the model from before and we add devices.
The Arduino circuit
For this step, we need 1 Seven Segment Display.
The objective is to increase or decrease the number displayed with the Y of the joystick. The number displayed is the altitude of the plane.
Plugs:
-
- a_pin to D7
- b_pin to D6
- c_pin to D9
- d_pin to D12
- e_pin to D13
- f_pin to D10
- g_pin to D11
- dp_pin to D8
- Plug the yJoystick into A1.
Image 21
The Ansys SCADE application model
Copy the PlanePackageStep2 in the project to have a PlanePackageStep3. We will update this package.
Design the Architecture operator, SystemPlane:
In this section, we will implement the following Ansys SCADE application operator:
Image 22
- Modify in the new package the Joystick4ButtonsCustom pins. Use the pin Uno::A1 for Ypos pin:
- Joystick4ButtonsCustom pin:
- Sel = arduino::UnusedPin
- RB = Uno::D3
- UB = Uno::D4
- DB = Uno::D5
- LB = arduino::UnusedPin
- Xpos = Uno::A0
- Ypos = Uno::A1
- Drag and drop in the model the Device Seven Segment Display for the arduino library. And enter its pins :
- Seven Segment Display pins:
- a_pin = Uno::D7
- b_pin = Uno::D6
- c_pin = Uno::D9
- d_pin = Uno::D12
- e_pin = Uno::D13
- f_pin = Uno::D10
- g_pin = Uno::D11
- dp_pin = Uno::D8
- Plug the new device Seven Segment Display to the ControllerPlane operator when you have done the ControllerPlane part.
Design the Controller operator, ControllerPlane:
In this section, we will implement the following state machine:
Image 23
- Add the state machine to control the Seven Segment Display.
- We can control the altitude with the Seven Segment Display only if the DC Motor is started.
- If the DC Motor is started (if we have pressed the right button)
- Up button decreases the altitude.
- Down button increases the altitude.
- We want to increase or decrease the altitude every 3 cycles. So we have an operator Count to know when we have passed 3 cycles.
- Create a new operator Count in the PlanePackageStep3
Image 24
- Open the operator Count and make a model to count one by one.
Image 25
- Open the ControllerPlane and add a step machine to control the Seven Display Digit.
Generate the code
- In settings, select the root operator in General and the Architecture in the Arduino Wrapper.
Image 26
- Now that your project is configured for the Arduino wrapper generation, you can click on the “Generate” button to generate the code and upload it on the board.
Now everything should work as expected. We control our LEDs with the xJoystick and the DC Motor with 3 buttons. And we have added the control of the Seven Segment Display with the yJoystick.