***Pong Game link***
Wednesday, January 18, 2017
To kick off Engineering Design Method 2, we're starting with a program called Scratch. You can think of Scratch as programming with training wheels. It teaches the fundamentals of programming and gets the student thinking like a programmer. Today, Mr. Dubick walked us through the menu of topics listed, and he showed us how they worked. First, we had to choose or create a sprite. Once the sprite was selected, we could drag the puzzle pieces into the script box, change its costume, or add sounds. Under script there are 10 tabs, each containing puzzle pieces that can do a variety of things. Our first task was to make the game "Pong" using Scratch. The ten tabs are motion, looks, sound, pen, data, events, controls, sensing, operations, and more blocks. One important thing we learned was if you know the sequencing, looping, if-then statements, and variables, you can program just about anything.
Thursday, January 19, 2017
The most basic command is moving a sprite x amount of steps. You cannot have a pong game without a moving ball, so by using a forever loop, we got the ball to move. But we wanted it to start from the top and drop down, so by placing a "go to __x and __y" and a "point in direction 180" in the initial steps, it will drop down from the coordinate chosen. An if-then statement is needed under the forever loop that says "if touching trampoline (or other sprite chosen to be paddle), then point in direction 0". This makes the ball bounce and change directions when it hits the paddle. Later, we added a "turn 15 degrees" underneath, but one of the important lessons Mr. Dubick taught us is to keep it simple at first, then you can make it more advanced. The next thing we needed to deal with was a consequence if you missed the ball. Therefore, we created an if-then statement that said "if touching dead zone, then hide, wait 2 seconds, show, go to __x and __y". The dead zone is a sprite that I made by just drawing a horizontal line. The last thing I added was a variable named score, and added "set score to 0" in the initial steps and "change score by 1"
Monday-Wednesday, January 23-25, 2017
To transition from Scratch to Arduino, we are using a program called mBlock. The format is almost identical to that of Scratch, but it can be uploaded to Arduino. It also displays the Arduino code, so we can start to see how Arduino works. Once we opened mBlock, there was no Arduino Program blocks. We figured out that at the top, under “extensions” Arduino needs to be selected and mBlock needs to be deselected. Also at the top, there is a tab called “connections”. To connect it to our board we had to click on “Serial port” then choose the USB port we were using. The last thing at the top that needs attention is the board. Choose Arduino Uno.
After we had set up, our challenge was to make 8 lights blink. My first code got the lights to turn on, but they didn’t blink nor were they very bright. However, my LED were not the only ones that were dim. Mr. Dubick stepped in and helped us figure out what was the problem. We discovered that using “set digital pin __ output as HIGH”, it made the Arduino go into a voltage saving mode. Instead we used “set pwm pin __ output as 255”, and all of the lights shined brighter. What a pwm pin is remains a mystery, but Mr. Dubick says that we will learn about it later. Now that I had bright lights that would turn on, I needed them to turn off in a blinking fashion. My second code did just that! The only problem was that after it went through all of them, it stopped. This was probably because 1 was added to the pin number every time, but there was no LED for pins greater than 13. I think what I needed to do to make it start again from pin 6 (my first pin) was have a “set pin to 6” after the repeat loop. An important note about programming is that it will do what you tell it to do unless you tell it otherwise. Therefore, it will keep adding 1 to the pin number until infinity unless I tell it to start over again.
The next challenge that was thrown at us was making the LEDs turn on one by one down the line and then turn off one by one going the other way. This would involve having two repeat loops. This time I changed the “repeat 10” to “repeat until pin > 13. Because I didn’t have a pin greater than 13, it would light all of my LEDs. Specifically, it would turn pin 6 on wait 1 sec and then change the pin by 1 so that pin 7 will light up. After reaching pin 14, it would go onto the next loop. This loop said “repeat until pin < 6”, so it would set the last pin it was on (pin 13) to 0 (low), wait one second, and then change the pin by -1. If there was no negative sign before the one, then nothing would go off after pin 13 because there is no pin which is one greater than 13.
Thursday-Friday, January 26-2, 2017
We continued programming using mBlock. The task that was given to us was to make one LED fade in, then fade out. This was pretty simple to do with one LED. By having a variable called “power”, we could control how much the power increased, creating a fade-in effect. When we wanted to fade out, we told it to change the power by -1 until power = 0. A crucial block to have between the “set pwm pin pin output as power” and “change power by 1 (or -1)” is a wait .1 second. If there isn’t a wait, it would change by 1 repeatedly, too fast for anyone to see.
To get the LED to fade in one at a time down the line, we needed two repeat loops. The first repeat loop would tell it to repeat until pin > 13. Inside this repeat loop, there was a repeat loop that was the same as the one used to fade in one LED.
That was about the extent of our use of MBlock because MBlock proved to be too unstable for practical use. Screen shots of progress in "Mechatronic" google drive folder.