Table of Contents
Example Description
Learn how to interface a joystick with Quarky, the versatile microcontroller, to control the movement of Quarky Robot in different directions.
Introduction

A joystick is an input device used to control the movement or actions of a computer, video game console, or other electronic device. In gaming, joysticks are often used to control the movement of characters or vehicles in a virtual environment. They provide analog input, meaning the degree of movement can vary based on how far the handle is pushed in a particular direction. In aviation and flight simulation, joysticks are commonly used to simulate the control of aircraft, providing pitch, roll, and yaw inputs. Some advanced joysticks also come with additional features such as throttle controls, programmable buttons, and force feedback to enhance the gaming or simulation experience. below is a simple animation of a joystick.

 

 

In this example, we’ll be interfacing a joystick with Quarky and try to find different directions for our robot by moving the joystick along the x and y axis let’s begin!!

Circuit Diagram

 

 

connection

JoyStick       Quarky

GND                          GND

5V                                  V

VarX                             A1

VarY                              A2

this is logic we will be using

Code

Remember that whenever we are moving the joystick in any direction, the value of both X and Y axis changes simultaneously, so we will be defining a range for both the X-axis and Y-axis so that when their values lie under this range our system must be able to decide the direction as forward,backward, left or right. based on the ranges and logic.

  1. Connect JoyStick as per the above connections.
  2. Open pictoblx and create a new file.
  3. Select Quarky from the board menu.
  4. Go to my blocks and create a new block as “forward”
  5. From controls palette, add if-than block with under forward block.
  6. From operators palette insert AND operator in if block.
  7. Again from operator palette, add grater then operator and first space of the AND block.
  8.  From Sensor palette of Quarky, choose the block “read analog sensor () at pin()” select joystick X from the dropdown and A1 from the dropdowns. change the value from 50 to 4000
  9. Again from the operator palette drag less then operator and insert in second space if the AND operator.
  10. From sensor palette of Quarky, insert read analog sensor () at pin (). in first space of the less than operator and change the value from 50 to 4100.
  11. Copy this if block and paste it inside the existing if block.
  12. this time change joystick X to joystick Y and pin from A1 to A2, as shown below.
  13. this time change the range for y from 1800  to 900 in first and second  space of grater than and less than operator respectively.
  14. From looks palette add say block in if block and inside the say block add join block from operators.
  15. replace apple with “forward >> ” and in place of banana add another join block.
  16.  This time in place of apple type “x = ” and again add join operator from operators palette in place of banana.
  17. In place of apple add “read analog sensor () at pin () ” from sensor palette. choose joystick X and A1 from dropdowns, Add another join block in place of banana.
  18.  this time in replace appl with “ y = ” and banana with “read analog  sensor () at () ”  block and choose joystick Y and A2 from the dropdowns.
  19. Now from display palette of Quarky,  drag “display matrix as ()” .
  20. Click on drop down and create a forward arrow on display.
  21. from Controls palette and wait for 0.25 seconds.
  22. create 3 more blocks for backwards, left and right prospectively. for backward.
  23.  Left
  24. Right
  25. Now let’s start writing the main script. from events palette add when flag clicked.
  26. From control palette add a forever block.
  27. finally, add all the blocks that you have created inside the forever block.

By following all the above steps, you will be able to control the robotic car in any direction you want.

Output