Results 1 to 3 of 3

Thread: remove

  1. #1
    Denny is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Help with GUI board

    Hello everyone, I'm new to java and we have an assignment at school where we have to display a counter on a GUI-board. I work with BlueJ.
    When I start the script it displays a counter on the GUI-board. Screenshot of the GUI board below

    I only use the first five digit displays on the first row(so 0x18, 0x16, 0x14, 0x12, 0x10) These digit displays are separate from each other. So when you want to write the number 10 to the display, you use IO.writeshort(0x10,0); followed by IO.writeShort(0x10);. The 0x10 and 0x12 are the locations of where the followed number has to go.

    I understand how to increase the counter, but the assignment is when you press a button on the GUI-board and the counter is counting backwards.

    I currently have this:

    Java Code:
    public class assignment45
    {
        public assignment45()
        {
            IO.init();
        }
         public void clearAll()
        {
            IO.writeShort(0x10,256);
            IO.writeShort(0x12,256);
            IO.writeShort(0x14,256);
            IO.writeShort(0x16,256);
            IO.writeShort(0x18,256);
        }
        public void test1()
        {
            clearAll();
                int x = 0;
                int een = 0;
                int tien = 0;
                int honderd = 0;
                int duizend = 0;
                int tienduizend = 0;
            while (een < 10) {
                     if (IO.readShort(0x80) == 0) {
                        IO.writeShort(0x10,een);
                        IO.delay(100);
                        een++;
                         if (een == 10) {
                           een = 0;
                           tien++;
                           IO.writeShort(0x12,tien);
                        }
                        if (tien == 10) {
                           tien = 0;
                           honderd++;
                           IO.writeShort(0x12,tien);
                           IO.writeShort(0x14,honderd);
                        }
                        if (honderd == 10) {
                            honderd = 0;
                            duizend++;
                            IO.writeShort(0x14,honderd);
                            IO.writeShort(0x16,duizend);
                        }
                        if (duizend == 10) {
                            duizend = 0;
                            tienduizend++;
                            IO.writeShort(0x16,duizend);
                            IO.writeShort(0x18,tienduizend);
                        }
                     }
                     if (IO.readShort(0x80) == 1) {
                         if (een >= 0) {
                         IO.writeShort(0x10,een);
                        }
                        if (een == 0) {
                           een = 10;
                        }
                        if (een == 9) {
                           tien--;
                           IO.writeShort(0x12,tien);
                        }   
                        if (tien == 0) {
                            tien = 10;
                        } 
                        if (tien == 9 && een == 9) {
                            honderd--;
                            IO.writeShort(0x14,honderd);
                        }
                        IO.delay(100);
                        een--;
                     }
            }
        }
    }
    if (IO.readShort(0x80) == 0) { means the button is off
    if (IO.readShort(0x80) == 1) { means the button is on

    Can someone help/explain me the method to make it so it will count backwards? My method is not very good. It wont work for counting back after 1000.
    If anything isn't clear I'll try to explain if further.
    Last edited by Denny; 09-26-2013 at 07:44 PM. Reason: Help

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: remove

    What is int x suppose to be for?

    So it's suppose to increment/decrement the counter once per delay? Seems a little complicated for this. I suggest trying something along these lines:

    Java Code:
    // count forward
    for(int i = 0; i < 100000; i++)
    {
    	int ones = i % 10;
    	int tens = (i % 100) / 10;
    	int hundreds = (i % 1000) / 100;
    	int thousands = (i % 10000) / 1000;
    	int tenthousands = (i % 100000) / 10000;
    	
    	writeOnes(ones);
    	writeTens(tens);
    	writeHundreds(hundreds);
    	writeThousands(thousands);
    	writeTenThousands(tenthousands);
    	delay();
    }
    
    // count backward
    for(int i = 99999; i >= 0; i--)
    {
    	int ones = i % 10;
    	int tens = (i % 100) / 10;
    	int hundreds = (i % 1000) / 100;
    	int thousands = (i % 10000) / 1000;
    	int tenthousands = (i % 100000) / 10000;
    	
    	writeOnes(ones);
    	writeTens(tens);
    	writeHundreds(hundreds);
    	writeThousands(thousands);
    	writeTenThousands(tenthousands);
    	delay();
    }
    Last edited by AndrewM16921; 09-27-2013 at 05:26 PM.

  3. #3
    Denny is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: remove

    I was testing something with x.
    My friend explained this to me with a similar method like you, thank you for your response and effort to post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •