Hello everybody,

I am working on a school project now and I want to have a blinking LED. The piece of hardware we use is not familiar because it is designed by school.

I have the methods to put on the led and to put off, but can't get it too blink.

dev.getPortD().setPinValue(0, true); //Turn on LED
dev.getPortD().setPinValue(0, false); //Turn of LED

All help is appreciated :)
thanks in advance.

Greetz

MeandJava

ehm ... what is not working about it? OK, you know which methods to call, but how are you calling them?
looks to me like you'll need either an infinite loop that turns the led on and off

while ( true ){
dev.getPortD().setPinValue(0, true);
dev.getPortD().setPinValue(0, false);
}

off course, if you need to perform other actions while the blinking is going on, you'll need to use a thread, and perform the same two calls repeatedly inside that thread.

Thanks, but I also need a delay, because now you see it blinking very fast.
Thanks in advance :)

Greetz

Meandjava

well, what's to stop you to use a thread with a sleep in it?
try taking a look at this, should help you get a bit further

example

Thanks this works :)

for (int i = 0; i < 60; i++) {
            dev.getPortD().setPinValue(0, true);
            //Pause for 4 seconds
            try{
            Thread.sleep(500);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            dev.getPortD().setPinValue(0, false);

            try{
                Thread.sleep(500);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.