For this assignment I decided to create an interface through the use of Processing to read the data from the input board I created, in order to have an easy reading of the data coming from the HC-sr04 sensor
before doing this I studied how to best use Processing, by consulting this tutorial
I imported the serial library into my sketch and declared the USB port where the data will be read.
The board I used is the one created during the Input assignment
The graphic interface feature created by me (through Processing) allows to read the distance of the proximity sensor through a java application that can be run on Windows OS without running the Arduino terminal
I recommend this Tutorial on serial communication with processing to better understand how to best use to read from the serial port
This is the program I wrote in Processing
codecodeimport processing.serial.*; Serial myPort; String data="" ; PFont myFont; void setup() { size(1366,900); // size of processing window background(0);// setting background color to black myPort = new Serial(this, "COM8", 9600); myPort.bufferUntil('\n'); } void draw() { background(0); textAlign(CENTER); fill(255); text(data,820,400); textSize(100); fill(#4B5DCE); text(" Distance : cm",450,400); noFill(); stroke(#4B5DCE); } void serialEvent(Serial myPort) { data=myPort.readStringUntil('\n'); }
As you can see the code, in this case I use the serial communication sent from my board to the USB port, so I read the distance of the proximity sensor on the GUI I created
During the Assignment Networking and Communications , using the bluetooth module I created a simple app using the MIT APP Inventor software
I did this to interface my board with my smartphone. The function of this app will be to turn on the LED on my board when I shake the smartphone, using the "accelerometer" function that all smartphones now have
Start by creating a new project within MIT APP Inventor
After doing this, we find ourselves in the design sheet, where it is possible to create the graphics of our smartphone application
I insert the hidden elements that allow me to use the various sensors of my smartphone (accelerometer and bluetooth)
I have subsequently uploaded the images of my app, making sure that it signals me when the app is connected to the bluetooth module
In the block tab it is possible to write the code, using the block system very similar to Scratch
In the code I do so that I execute a string that has a value of 1 which causes the led to light up when the phone is shaken
at the end I export my application on pc and create the installation file for android smartphone (apk). This way I can install and run my app
Once my app is connected, I turn on the LED connected to my board