Stone-Paper-Scissors Game With Pinoo
Purpose of the Project: Creating a rock-paper-scissors game with a servo motor module, joystick module, module with lcd (I2c) and distance sensor using the Pinoo control card.
Materials Required for Design: Dekota, colored cardboard, cardboard in different colors, eva, silicone gun and silicone, pencil, screwdriver, scissors, knife, ruler.
- We draw the hand shapes of the stone, paper, scissors game on the colored cardboard and cut them with the help of scissors.
- Using a ruler and pencil, we draw two 36x30cm rectangles on the deco. We cut rectangles with the help of a knife.
- Using a ruler and pencil, we draw two 10x36cm rectangles on the decorate and cut them with the help of a curved knife.
- Using a ruler and pencil, we draw two rectangles of 10x30cm on the decorator and cut them with the help of a curved knife.
- We drill rectangular holes as far as the Pinoo control card can pass, to coincide with the back of the box we created.
- We draw a rectangle as far as the servo motor modules can pass, and cut it with the help of a knife.
- We draw the eyes of the sensor on the section we have set to place the distance sensor and cut it with the help of a knife.
- In order to place the module with LCD (I2C), we draw a rectangle as far as the module can pass into the section we have set and cut it with the help of a knife.
- In order to place the joystick module, we draw a square as far as the module can pass and cut it with the help of a knife.
- With the help of a silicon gun, we mount the servo motor modules and the distance sensor to the holes we drilled as shown in the figure.
- We assemble the stone, paper and scissors drawings we made at the very beginning of the design to the propellers of the servo motor modules with the help of a silicon gun as shown in the figure.
- We mount the joystick module to the square hole we drilled with the help of a silicone gun.
- We have completed the connections and the design, now we move on to the coding part. We will use Mblock-3 application for this.
- We connect our Pinoo control card to the computer with the help of a connection cable and enter the Mblock3 application. Then we introduce our Pinoo control card to the computer. For this, we first click on the serial port option from the Connect tab. Then we choose COM3. (The number may differ depending on the computer and the port.)
- After making the serial port connection, we select the card to be used from the Cards tab. We are working with Arduino Nano model.
- We come to the Extensions tab again and click on the Pinoo option. We will write our codes with the Pinoo extension.
- Come to the ‘Connect Again’ tab and click on the ‘Firmware Update’ option. After saying that the installation is finished, we press the ‘Close’ button.
- In the coding part; To start the application, we get the code when clicking the Green Flag from the Events menu.
- From the Robots menu, we get the code related to the servo motor modules and change the pin inputs one by one and set them all to 180 degrees.
- We click on the green flag and zoom in and out of the distance sensor. Here, when we bring our hand closer, we will take as a reference that it reads less than 10.
- We need to define a variable in order to see the values that the joystick module takes in x and y positions. For this, we come to the Data & Block menu and say create a variable.
- We write the variable name on the screen that appears.
- We define separate variables for X and Y positions.
- When the space key is pressed from the Events, we get the command. Since we will read the values continuously, we get the continuous repeat command from the Control menu. We take the codes "let x be 0, y get 0" from the Data & Block menu and put them into the ‘continuous repeat’ command.
- We synchronize the positions of the joystick module with the positions we have defined
- We press the spacebar and observe the values of the joystick module. When the joystick module is not moved, it takes around 500 values. When we pull it up, the y position approaches 0 and when we pull it down, it approaches 1022. When we pull it to the right, the x position approaches 1022 and when we pull it to the left it approaches 0.
- We need the library to be able to use the LCD (I2C) module. (You can find the library in the files.) We move the library of the LCD module to libraries by following the steps of program files- Mblock- Arduino-libraries from our computer.
- Right click on the code and click the ‘’Upload to Arduino’’ option. (We work with Arduino as a card.)
- In the window that opens, we click the ‘’Upload to Arduino’’ button again.
- We are waiting while our codes are being loaded to the card. After saying the installation is finished, we click on the close button. And we check whether the text we wrote is visible on the screen.
- We are disconnected because we loaded into the card. To write code, we choose Connect-Serial port-Com again and update the firmware.
- We define two variables called robot and opponent to keep track of the scores of the game. And we say that the scores are 0 when the game starts (that is, when the green flag is clicked) just below the green flag that we made the servo motors 180 degrees.
- We want the game to begin when we pull the joystick module up and the distance sensor is smaller than 10 (when we bring our hand closer). For this, we use the conditional commands, if any. We say if the Y axis is less than 300 because when we pull it up, the value is approaching 0.
- When we pull the joystick module up and the distance is less than 10, we say the servo motor modules should move up and down at 135 and 180 degrees three times.
- If the joystick module is not pulled up and the distance is greater than 10, we say that the servo motor modules remain at 180 degrees.
With the same logic, we also code the cases where the number is equal to 2 and 3.
- If the sign selected by the robot is the same as the sign we made, we want both sides not to gain points. We will define it as a draw when we pull down the joystick module. If the joystick module is pulled down, the LCD module display will be cleared. We print the robot's score on the 1st line and the opponent's score on the 2nd line. And we bring the hands back to their former position.
- We want the opponent to win 1 point if our sign beats the mark made by the robot. For this, when we pull the joystick module to the right, we determine the opponent as the winner. And if the opponent's score is equal to 3, we say victory should be written on the screen. And we end the game by resetting the scores.
- With the same logic, when we pull the joystick module to the left, we write the codes that will enable the robot to win.
- Then we repeat the process of loading into the card.
- If there is no problem, we disconnect our power cable from the computer. We power our Pinoo control board with the help of a 9v battery and a battery cap. We also turn the on / off button right next to the battery input to the ON position.
- Working Status of the Project:
When the joystick module is not pulled up and the value measured by the distance sensor is not less than 10, the servo motor modules will not move and will stop at 180 degrees.
When the joystick module is pulled up and we put our hand in front of the distance sensor, the servo motor modules will move up and down 3 times and then make a random movement.