W15- Interface application programming¶
http://fabacademy.org/2019/labs/barcelona/local/wa/week13/
http://academy.cba.mit.edu/classes/interface_application_programming/index.html
To make interfaces¶
https://www.openprocessing.org
FTT¶
“If this thing happens->do this”
https://ifttt.com
Easyest to use!
I might use it to send the alert to the police in the case of gunshot or noise in my final project.
To use it you need to put the FTT library and get a key from the web and put it in your code.
For mobile apps¶
Bluetooth BLE HC-08 (SWIFT) or 05
Make sure each bit of code works before you integrate it to an app, make sure it worked with an already made app, otherwise is too crazy to debug.
With the AT-COMMANDS is used to check if your bluetooth works with your arduino.
APP¶
INVENTOR
To create an app in android, not so good for IOS.
THUNKABLE also works
VR¶
AFRAME work like JavaScript to create VR fast.
UNITY AND UNREAL
VR those can be dowloaded in am App, but the learning curve is worse.
Grasshopper loves Arduino¶
Firefly, only for Windows.
Is better to use sketches in arduino without putting delays on the arduino or sketch and arduino may end up desincronized.
ASSIGNMENT¶
I try to simply make an alarm button with a funduino.
It will show an alarm on my computer screen.
It will be made with processing at the end.
First try:¶
Processing looks pretty much like the ARDUINO environment. And is based in C as well.
The idea is that when I press the button it flashes the alarm on the screen.
I cannot make it work
val=0;
x=5;
if ((val ==0)&&(x!=0)){
x--;
text("ALARM",100,100);
print("hola");
delay(1000);
}else{
text("ADEU",100,100);
print("adeu");
}
delay(1000);
background(155); // Set background to white
text("mmm",100,100);
//val=1;
}
For some reason if I put the delays, it goes in the if, but doesn’t print anything, although “hola” is printed out. It passes from white backgroung of initialisation to gray and “mmm” but skips “ALARM”. We try it with Xavi’s computer and different program and is the same, the problem is in the delays.
I try with if’s
val=0;
x=0;
if ((val ==0)&&(x==0)){
text("ALARM",100,100);
print("hola");
x=1;
print(x);
//delay(1000);
}
if ((val==0)&&(x==1)){
background(155); // Set background to white
print("ff");
x=0;
}else{
text("ADEU",100,100);
print("adeu");
}
//delay(1000);
//background(155); // Set background to white
//text("mmm",100,100);
//val=1;
}
Is not working, I try only with changing the color background and skipping the text, but is the same thing.
Ok what worked was to instead of changing the background’s color I change a rectangle’s color of the same size.
if (ALARM==false){
fill(255);
rect(0,0,200,200);
}
ALARM=true;
if (ALARM==true && Red==false){
fill(#FF0000);
rect(0,0,200,200);
Red=true;
delay(100);
print("hola");
}
else if (ALARM==true && Red==true){
fill(255);
rect(0,0,200,200);
Red=false;
delay(100);
}
Now I´m going to stop the program if someone clicks on the square
The idea is:
I click a button and an alarm starts in my computer screen and a buzzer… buzzes from pin 12 in the arduino until I stop it by clicking the alarm on my screen.
The App code:
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val=0; // Data received from the serial port
int x=5;
boolean Click=false;
boolean Red=false;
boolean ALARM=false;
boolean SQUARE() {
return(mouseX >= 0 && mouseX <= 200 && mouseY >= 0 && mouseY <= 200 && mousePressed);
}
void setup()
{
size(200, 200);
background(255);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
ALARM=true;// x=50000;
}
else {
val = 0;
// x=0;
}
if (ALARM==false){
fill(255);
rect(0,0,200,200);
}
if (x!=0){ //Just to test
ALARM=true;
x--;
}
if (ALARM==true && Red==false){
fill(#FF0000);
rect(0,0,200,200);
Red=true;
delay(100);
print("hola");
}
else if (ALARM==true && Red==true){
fill(255);
rect(0,0,200,200);
Red=false;
delay(100);
}
if (mousePressed == false){
Click = false;
}else if (mousePressed == true){
Click = true;
print(Click);
}
if (SQUARE() && Click == true) {
// Click = true;
ALARM=false;
}
if (Click == true) {
// Click = true;
ALARM=false;
}
}
The arduino code is:
int Trece=0;
int ALARM=0;
void setup() {
Serial.begin(9600); //Set up speed laptop and arduino communicate
pinMode(13,INPUT);
pinMode(12,OUTPUT);
}
void loop() {
if((digitalRead (13)==0) && (Trece==0)){
Serial.write(1);
Serial.write(1);
Trece=1;
ALARM=1;
}
if(digitalRead(13) == 1) {
Trece = 0;
}
if (ALARM=1){
digitalWrite(12,HIGH);
if(Serial.available() > 0){ //LEO BLUETOOTH
Trece=0;
digitalWrite(12,LOW);
ALARM=0;
}
}
}
I did a shield for the FUNDUINO, I did it in fotoshop, not in eagle, it was faster. The holes have to be inverted in mods.
You can see there is space for a capacitor which is not used, originally was intended for a debouncing capacitor, but is connected to VCC which is wrong, it should have connected it between GND and the PIN, in any case, it works just fine, but sadly my attempt to get electronically fancy end up in nothing.
Here is more info about debouncing capacitors
I have not much time to do the output, so right now I’m going to do the input, if I have time I’ll do the output.