This is the customary blinking LED project that every Arduino newbie starts with.
Plug a LED Brick into Port 2A of the Microcontroller Brick and run the program:
var led = new Led(PORT_2A);
while(true) {
led.setState(true); delay(1000);
led.setState(false); delay(1000);
}
The LED should blink at 1-second interval:
Plug another LED Brick into Port 2B and modify the program as follows:
var led1 = new Led(PORT_2A);
var led2 = new Led(PORT_2B);
while(true) {
led1.setState(true); led2.setState(false); delay(1000);
led1.setState(false); led2.setState(true); delay(1000);
}
Now you have two LEDs that blink in turn at 1-second interval.
How about throwing a Pushbutton Brick into the mix?
Connect a Pushbutton Brick to Port 3A. Now modify the program as follows:
var led1 = new Led(PORT_2A);
var led2 = new Led(PORT_2B);
var pb = new Pushbutton(PORT_3A);
while(true) {
led1.setState(true); led2.setState(false);
while(!pb.clicked());
led1.setState(false); led2.setState(true);
while(!pb.clicked());
}
Now the LEDs take turns lighting up when you click the button.