This is my make-through for the week's assignment. Grab a cup of coffee!
this project is a basic Game Controller acting as an input device for computer we used The Arduino Leonardo because it has a special microcontroller chip on its board the ATmega32u4,
that chip can control a PC through USB using HID Keyboard or Mouse as an input devices
our project will be controlling a simple game like SuperMario as an example it will have 2 modes :
buttons as arrows keys (up, down, left, right & fire or space )
2 Tilt Switches sensors controlling (left & right ) movements
a button dedicated to switching modes
.... so lets see what we will get to :)
our used Components is :
Arduino Leonardo.
6x Push Buttons.
2x Tilt Switch Module KY020.
wire jumpers.
m3 screws an nuts.
a small sheet of 3mm Plywood around ( 35 cm x 50 cm).
some basic knowledge of the followings :
Arduino C/C++ coding and ide.
Fusion360 for designing the enclosure box.
laser machine for making our prototype.
soldering iron.
i started with a rough sketch
i was looking actually for dimensions so i arranged my main big components which gave me width and height and depth of approximately what i need the box to be, and it looks like an Atari controller i remember them from my childhood :D
conclusion:
i wanted the box to be approximately :
Width 17 cm
Hight 5 cm
depth 9 cm
.................. according to my components Dimensions
Step 1: in fusion360 i started with a top sketch for the box , as i will use it again for the bottom too .
Step 2: went out for the walls of the box , i wanted to try the living hinge method, it was the first time i use it, in fusion there is an option called sheet metal, it basically draws a vertical plan of the wall and you keep extending and bending to the desired angels the sheet metal after you finish bending to desired angles ,have an option of flattening the pattern and it marks where to add the living hinge cutting lines,
Step 3: i then marked where to add some taps and T-slots on the top and bottom sketch , and extruded it and combined to the wall sheet metal part
Step 4: i started exporting sketches of each side and the walls and drew the ;living hinge patter on the flat part exported from sheet metal sketch , i did the pattern on every 1.5 mm, and it was a little too close so i redrew it on every 3 mm spacing
Step 5: and exported all the sketches one more time as a dxf for the laser fabrication phase
Step 2
Step 1
Step 3
Step 4
( 3mm Plywood Fabrication )
in LaserWork app > the laser machine software used at fablab
i rearranged the parts made.
made sure there is no overlapped duplicated lines.
assigned power and speed for cutting (15 speed , 75 power)
i made a layered colors to make sure the machine starts with the inside of the parts firstly , we learned about the kerf of the machine and how it vary from time to time .
uploaded the file to the machine .......
after uploading
we place the plywood sheet in place for starting
do a test run on the frame of the file uploaded
making check of focus distance of the laser
making sure of the air flow and
then hold your breath and click RUN . . . . . . . . .
laser machines burn materials to cut them,
so some of the parts get black burns on them, we can use a sandpaper to remove and scrape it away.
if it didn't clean the wood enough i have a plan B :D i will spray paint it all black ... lol :D
after sanding i assembled the box and made sure it all fits and yaaaay :D, it was all perrrrrfect.
i add the m3 screws and nuts
and then assembled the electronic components the Arduino, buttons and Tilt Switches :D
i tried to draw the circuit on tinkerCAD , it was not perfect solution , i did not fid Arduino Leonardo or even the tilt sensors but i am planning to download a free opensource fritzing version, ASAP
soldering part i soldered all buttons ground to each other and did the same with the tilt switches grounds and +ve terminals too then i got a signal for every button and switch to connect to the Arduino's pins
to use the usb input device on a pc
we have to include a library called Keyboard.h
this library make sure connection is established through the USB and PC as input devices
so ... after that we start adding variables for every button and for Tilt switches too and assign a pin for everyone of them
then i added another to empty variables that i will fill them with tilt switches reads,
i add a variable for delay time to not manually change every delay string in testing phase.
next three variables are for switching moods (buttonPushCounter, buttonState and lastButtonState )
in this part of coding its a loop that run only ones at the begining of the code :
i make sure the code know what to do with every variable or Assigned Pins : (inputs < for buttons in my case) and we add _PULLUP to it to activate the pullup resistor of that pin
switches also are inputs but we don't need _pullups it has a resistor on its board already
i also started the serial Port with a serial.begin(9600);
this for testing purpose
i also start Keyboard.begin();
this starts the USB Control over the PC
in this part of coding its a loop that run continuously and loops back over and over non stop
this part of the code i will put the mode selector part that will switch modes after pressing a button a count of times.
and it will call either of the next two functions or Modes
here is the link for it: https://docs.arduino.cc/built-in-examples/digital/StateChangeDetection
this function or Mode will assign a keyboard arrow key to every button
you can add a hex number of one of the keys on a pc keyboard or you can write down its reference modifiers. with a Keboard.press();
i found some of the (hex no and modifiers ) here is a link : https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers/
i add a Serial.println(); for testing purpose
and in the end of the function i add a Keboard.releaseAll(); this make sure you have some control over your own pc :D or you can end up with a ddddddddddddddddddddddddddddddd continuous for ever :D :D
and also don't forget to add a delay after keypress and test how many characters you get when you press a button once i made the delay about 100 but testing is the answer :\
this function or Mode will assign the tilt switches to press a key to click arrow left or right instead of the buttons.
i assigned the read variables of every tilt switch to each of its own variable.
this was made so i can do a differentiation larger than or equal to them 1 or 0
if the readings of the sensorRight > sensorLeft
1 > 0
it will Keboard.press(); to the right and if not (else) it will move to the other direction , i also add key release and delay time and serial prints as previous for testing.
What I learned this week is...
i learned a lot in this Project
sheet metal < fusion360
living hinge < pattern spacings with experimentation
learned about kerf of the laser machine
Arduino keyboard .press .release and .begin < coding