This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-03-11 01:59:13

Bargonaut
Scratcher
Registered: 2007-11-05
Posts: 6

Calculator with numeric display

http://scratch.mit.edu/projects/Bargonaut/924605

I wrote this program to be easy to understand.  It demonstrates a few tricky solutions in order to get the sprite-based display to follow the keys and show the results.

This calculator project is written to experiment with turning the display digits into a value, and then taking the result of the computation and putting it back to the display. The biggest challenge is getting the result broken into single digits. Luckily, Scratch lets you treat the number as a text string, and you can take just one letter at a time.

The program uses many signals to control the operations. When a number key is pressed, the "number" signal is broadcast to let the digits know a new key is about to be sent. This is the time when the digits shift over to make room for the new number. Then the key name is broadcast to change the first digit position to the right costume. After that, the "compute" signal is broadcast to turn the display digits into a numeric "screen" value.

Then, it is a matter of saving the operation (plus, minus, multiply) and the value being computed to end up in the result. It does handle minus, but since I have no decimal places, division will have to wait for a future project. Watch out for overflow, the display is only eight digits.

Offline

 

Board footer