Peters Petrol Pumps
How do you do peters petrol pumps as computing coursework AQA?
There are a couple of ways to represent a seven segment display easily in vb.net for example:
Hold the data for each segment i.e whether it should be displayed or not in a single 1D array as strings, e.g. “0111111″ representing zero etc. Then use the substring function to break out the info when iterating through each sement of the digit to be displayed.
Use a 2D array to hold the info, the 2 dimensions representing Segments 0-6 and digits 0-9
You need to separate out the numbers you are dealing with into individual digits - for this you can use the Mod function
Try the seven segment display first on a single digit and biuld up form that. Btw you will need to use a timer to increment the petrol dispensed….
They are the main problems and ways to go about tackling them.
————————————————————————–
> We have just started AQA Computing this year, having previously only
> offered ICT. Â Although a big fan of Pascal, we elected to use VB,
> since my colleague knows it, but is a bit weaker on programming
> fundamentals.
> Whilst we initially went for VB6, we ended up going VB 2005 Express,
> not least of all because of the help facilities.
> The Petrol Pump display is actually not as hard as the scare stories
> that I have heard flying around. Â The principle is to set up a
> primitive drawing subroutine that can draw a line, from one set of x,y
> coordinates to another (with an appropriate pen width and a triangular
> start and end cap). Â Call this seven times with the right coordinates
> and you can draw an 8. Â Next, introduce the idea that if you have two
> pens, one coloured and the other blank (same as the form’s
> background), then you can draw any digit. Â Set up ten routines,
> Zero(), One(), etc… to draw the correct bars to represent each
> digit. Â Ok, so now we can draw a digit, any digit. Â Next, get them to
> write a routine to make their one-digit display count. Â As
> soon as they introduce some Do While - Loops, make sure they
> understand the need for an Application.DoEvents() inside the loop or
> they won’t be able to process any interrupts (mouse-up for the pump).
> I would suggest a Select - Case statement to process the digit you are
> trying to display, keeps it neat and easier to understand.
> Hopefully, they will have a counting digit, that goes 0-9, or some
> such, which they may/may not need to slow down a little to see the
> counting, depending on how inventive they are.
> Next, they need to think about how to display a number larger than 9.
> Introduce a FuelLitres variable, that you will increment by .01 inside
> a Loop in the MouseDown routine, (here is where the
> Application.DoEvents() becomes critical), the only exit from which is
> when you reach a pre-determined fuel limit or when the system traps
> the MouseUp event. Â Displaying the fuel (and from that the price) is
> an inner loop encapsulating the Select-Case statement to display any
> single digit. Â I will just explain the fuel display… the fuel cost
> is a natural extension of this. Â It goes without saying that this is
> not something you want to give to your students directly and I am sure
> that there are other ways of doing it.
> The basics of all decimal systems is that you multiply by 10 every
> decimal place you move to the left, so… Â In the following routine,
> FuelLitres is the amount of fuel, segment is a variable that we will
> (in the end) pass to our drawing routine to offset our drawn digit,
> depending on whether we are drawing in the Unit, Ten, Hundred, etc…
> position. Â running is a boolean that is set to true when the pump
> handle is “lifted”. Â flag is a boolean that we will set to true in the
> MouseUp routine, to provide an exit. Â workvar and OneDigit are integer
> variables to hold the fuel value to display and the single digit from
> each part of the number that will be stripped out in turn
> respectively. Â DrawMyDigit() is a sub that contains the Select-Case
> statement to draw any digit.
> Â Â Â Â Do While FuelLitres < 100 And running And Not flag
> Â Â Â Â Â Â segment = 0
> Â Â Â Â Â Â FuelLitres = FuelLitres + 0.01
> Â Â Â Â Â Â workvar = FuelLitres * 100
> Â Â Â Â Â Â Do While workvar > 0
> Â Â Â Â Â Â Â Â Application.DoEvents()
> Â Â Â Â Â Â Â Â OneDigit = workvar - (Int(workvar / 10) * 10)
> Â Â Â Â Â Â Â Â DrawMyDigit(OneDigit, segment)
> Â Â Â Â Â Â Â Â workvar = Int(workvar / 10)
> Â Â Â Â Â Â Â Â segment = segment + 1
> Â Â Â Â Â Â Loop
> Â Â Â Â Loop
> After that, you need to consider a vertical offset for the various
> numbers (price, fuel, price per litre) to be displayed.
——————————————————————————–
OK if it’s just on the screen, that’s easy enough. One way to do it is for each cell, draw the 7 lines on the screen (it’s better to start with one cell to see how everything works). Name them something like Cell1Seg1, Cell1Seg2, etc.
Assuming you arrange the names such that
segment1 is the top horizontal
segment2 is top left vertical
segment3 is top right vertical
segment4 is center horizontal
segment5 is bottom left vertical
segment6 is bottom right vertical
segment7 is bottom horizontal
For each number 0 - 9 you have to tell which lines are on and which are off. You can do this by setting the color of the line.
In your routine to display the number
DisplayNumber(num as integer)
select case num
case 0
Cell1Seg1.BackColor = vbRed
Cell1Seg2.BackColor = vbRed
Cell1Seg3.BackColor = vbRed
Cell1Seg4.BackColor = vbBlack
Cell1Seg5.BackColor = vbRed
Cell1Seg6.BackColor = vbRed
Cell1Seg7.BackColor = vbRed
case 1
Cell1Seg1.BackColor = vbBlack
Cell1Seg2.BackColor = vbBlack
Cell1Seg3.BackColor = vbRed
Cell1Seg4.BackColor = vbBlack
Cell1Seg5.BackColor = vbBlack
Cell1Seg6.BackColor = vbRed
Cell1Seg7.BackColor = vbBlack
etc.
