top of page
Search
  • ncampanelli0

Assignment 1 (2 button calculator)

Updated: Sep 3, 2019

Upon receiving this assignment my first thought was I can do this in 10 minutes. I started with a simple program that could increment two numbers and then add them together. After putting this together I realized I could've just incremented one number every time a button was pressed and when both were pressed simultaneously it would add the two together. It seemed kind of wasteful to just have that so I decided to expand on the program to incorporate subtraction, multiplication and division. It took me a while (about 10 minutes) to come up with a solution to the problem, "how do I change the operation being performed?" My answer was to add to the program a check, if the answer comes out to be 0, switch the mode.


My first problem was that 0/0 comes out to undefined (or in computer speak NAN, meaning not a number). I solved this by incorporating a check if number a and number b (the two numbers that are incremented) are both 0, then to set number c (the answer to be displayed) to 0 instead of dividing, thus preventing NAN from showing on the microbit.


At this point when my ~10 lines of code project was closer to 100 lines, I read the instructions to see what I was supposed to actually be doing. The only thing I forgot to add was an animation. I looked around and saw that there was a turtle library and that it worked very much the same way in JS as it does in Python. I spent some time thinking what animation I wanted to add and decided to add an animation when the program "resets". I decided on animating pi with the turtle function. My reasoning was simple, a program made by an American, a program that does math, infinity numbers (pi is infinite)... "It's as American as Apple Pi" (All i was missing was the apple device, I programmed on Windows 10 but when I have to present the code I imagine I will be presenting on a mac, which is an apple device so all is good).


The last major problem I had which I could not figure out is that I get a failure when I try to upload the code to the microbit with a failure.txt file being generated.


Last but not least the code itself is commented, giving a break down of what each segment of the code does.


edit:


link to project: https://makecode.microbit.org/_8JtDexbo2aV1

6 views0 comments

Recent Posts

See All

Final assignment (trivia project)

How I came to this idea for a project was simple. Back when I was in high school I made a trivia style game. This game was written for Windows Command Line (.bat file). The original program was quite

Assignment 9 (drawing program)

I made a drawing program with multiple colors that can be selected (with black being used as the eraser color as the background is black). I used an array to keep track of all the colors and used a fo

Assignment 8 (bug fixes)

change log: 1. Revised collision for ball to bounce off paddles properly (instead of requiring perfect pixel alignment with a sweet spot, which was the original collision detection. I figured out it w

bottom of page