The following electronic components are also required:
Raspberry Pi 3;
7x jumpers male-female;
Protoboard;
LED RGB module (or common 4 pins LED RGB);
Push-button module (or common push-button).
In order to execute Gpiod methods at your embedded device, you will also need to have the libgpiod-dev package installed in your board. You can do that by entering the following command at the device's terminal:
Step 1: open VS Code console (CTRL + Shift + P) and type TotalC… autocomplete should help!
Step 2: select TotalCross: Create new Project;
Step 3: create a folder called HelloWorld and select it;
Step 4: GroupId will be com.totalcross;
Step 5:ArtifactId will be HelloWorld;
Step 6: select the latest version of TotalCross SDK and -linux-arm platform;
Step 7: openRunHelloWorldApplication.java and click Run (IDE). The result should be:
Step 8: watch the integrated simulator!
The following project deals with the control of an RGB LED with user interface buttons and a pin reset button!
Step 1: follow the schematic:
Step 2: to work with pin logic after public class HelloWorld extends MainWindow { add:
// Integers to store pin numbersprivateint R =4, G =17, B =27, pushButton =18;// Integers to store state of each LED pin, 0 (LOW) and 1 (HIGH)privateint sttR, sttG, sttB;// Buttons to control colors privateButton btnR, btnG, btnB;
If you need to work with different pinouts check the manufacturer manual!
Step 3: at HelloWorld.java in initUI() code add:
// Label helloWorld made on project creationLabel helloWorld =newLabel("Hello World!");// Change the position of label on the Y axis, with TOP (beginning of Y) + a fill of 20add(helloWorld, CENTER, TOP +20);
// Set LED pins as outputs and default value sttXpinR.requestOutput("CONSUMER",sttR);pinG.requestOutput("CONSUMER",sttG);pinB.requestOutput("CONSUMER",sttB);// Set Reset pin as inputpinPushButton.requestInput("CONSUMER");
Step 6: the red button:
// The TotalCross button:btnR =newButton("R"); // Button instantiation// without textbtnR.setBackColor(Color.RED); // Set background color (red)btnR.addPressListener(newPressListener() { // Press event listener @OverridepublicvoidcontrolPressed(ControlEvent controlEvent) { sttR =1- sttR; // Invert pin state pinR.setValue(sttR); // Set value (HIGH or LOW) }});add(btnR, CENTER -70, AFTER +40); // To make horizontally aligned // buttons in the 'RGB' sequence,// take the center reference and // decrease 70 to place the // leftmost R. In the Y axis just// take the reference of the// previous component and add 40
Step 7: and the other buttons:
btnG =newButton("G");btnG.setBackColor(Color.GREEN);btnG.addPressListener(newPressListener() { @OverridepublicvoidcontrolPressed(ControlEvent controlEvent) { sttG =1- sttG; // Pay attention to change pin!!!pinG.setValue(sttG); }});add(btnG, CENTER, SAME); // The green button will be // placed at the center and in // the same line of previous // buttonbtnB =newButton("B");btnB.setBackColor(Color.BLUE);btnB.addPressListener(newPressListener() { @OverridepublicvoidcontrolPressed(ControlEvent controlEvent) { sttB =1- sttB; // Pay attention to change pin!!!pinB.setValue(sttB); }});add(btnB, CENTER +70, SAME); // The last button will be placed // to the right of the center.
Step 8: finally we use a thread to check the state of the reset button:
// A thread will be used to check every 20 ms, if the reset button has been pressed: if yes then // the pin state goes to LOWnewThread() { @Overridepublicvoidrun() {while(true){if(pinPushButton.getValue() ==1) { sttG =1- sttG; sttR =1- sttR; sttB =1- sttB;pinR.setValue(sttR);pinG.setValue(sttG);pinB.setValue(sttB); }Vm.sleep(100); } }}.start();
Step 9: run RunHelloWorldApplication.java again and watch the results!
Step 1: open VS Code console (CTRL + Shift + P) and select TotalCross: Deploy
Step 2: a second dialog box will appear and just fill in the board's information:
Step 3: see the results in screen or VNC
After basics
This was the beginning of application development for TotalCross embedded systems, how about taking a look at TCSample and seeing all that can be done? See dashboard made especially for Web Summit 2019:
See more
Are you interested in development with embedded systems? Contact us via Telegram!