Paso 4: Se permite obtener diversión
1) entra en https://build.particle.io/build/new y crear una nueva aplicación de""
2) agregar las librerías necesarias. En la partícula construir interfaz de web, haga clic en el icono de "Bibliotecas" en la parte derecha (icono se asemeja al de un marcador). Usted será capaz de buscar y añadir las librerías necesarias para la aplicación. Añadir bibliotecas "internetButton" y "Simon" que debe tambien math.h.
Una vez seleccionada la biblioteca Asegúrese de haga clic en el botón "Incluir en la App" y seleccione el nombre de la aplicación que acaba de crear.
El siguiente código incluye dos maneras diferentes de codificar el botón Internet. Una forma ha sido comentada y la segunda forma de mostrar los colores del LED y la música quedó sin comentarios. Usted debe ser capaz de copiar el código, comentario a las secciones de línea y eliminar los comentarios en las partes que se comentan para probar la versión dos.
En el ejemplo sólo uno de los botones es hasta reunir y analizar la información de aceleración del acelerómetro. Tal botón se considera el modo de "mayor" y también se ha establecido para activar una alerta al conjunto y una alerta separada si cae el individuo utilizando el dispositivo.
#include "InternetButton/InternetButton.h" #include "math.h" #include "Simon/Simon.h"
InternetButton b = InternetButton(); uint8_t button1 = 0; uint8_t button2 = 0; uint8_t button3 = 0; uint8_t button4 = 0; uint8_t buttonAll = 0; int gaugeCount = 0;
char Org[] = "Alert Buddy"; char Disp[] = "Alert Buddy"; char Locn[] = "LOCATION";
//enum Position: int { Top = 0 , Right = 1, Bottom = 2, Left = 3, None = -1};<br>//enum State: int { Welcome, Ready, Showing}; //State state; //Position read = anyButtonOn(); //int person;
/* void welcome () { b.playSong("C4,8,E4,8,G4,8,C5,8,G5,4"); b.allLedsOn(0,20,20); delay(500); b.allLedsOff(); flash(Top, true, true); flash(Right, true, true); flash(Bottom, true, true); flash(Left, true, true); state = Ready; } */ void welcome () { b.playSong("C4,8,E4,8,G4,8,C5,8,G5,4"); //b.allLedsOn(0,20,20); delay(500); b.ledOn(11, 30, 250, 0); //255,0,0 b.ledOn(1, 30, 20, 0); b.playNote("C4",4); delay(20); b.allLedsOff(); b.ledOn(2, 0, 0, 255); b.ledOn(3, 0, 0, 255); b.ledOn(4, 0, 0, 255); b.playNote("E4",4); delay(20); b.ledOn(5, 120, 120, 0); b.ledOn(6, 120, 120, 0); b.ledOn(7, 120, 120, 0); b.playNote("G4",4); delay(20); b.ledOn(8, 255, 0, 0); b.ledOn(9, 255, 0, 0); b.ledOn(10, 255, 0, 0); b.playNote("C5",4); //state = Ready; exit;
}
void loop(){ //switch (state) { //case Welcome: //welcome(); //break; //case Ready: ready(); //break; //case Showing: show(); //break; //} /* int ledPos = b.lowestLed(); char payload[255];
snprintf(payload, sizeof(payload), "{ \"s\":\"Giroscope\", \"u\":\"Gir\",\"l\":\"%s\",\"m\":\"Movement\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, ledPos, Disp); Serial.println(payload); Spark.publish("ConnectTheDots", payload);
Delay(500); */ delay(500); */ }
/ * anular flash (posición p, bool temporizado, sonido de bool) {switch (p) {caso parte superior: //button 1 verde b.ledOn (11, 30, 250, 0); //255,0,0 b.ledOn (1, 30, 20, 0); si (sonido) {b.playNote("C4",4); /* void flash(Position p, bool timed, bool sound) { switch (p) { case Top: //button 1 green b.ledOn(11, 30, 250, 0); //255,0,0 b.ledOn(1, 30, 20, 0); if (sound) { b.playNote("C4",4); } break; case Right: //button 2 blue b.ledOn(2, 0, 0, 255); b.ledOn(3, 0, 0, 255); b.ledOn(4, 0, 0, 255); if (sound) { b.playNote("E4",4); } break; case Bottom: //button 3 yellow b.ledOn(5, 120, 120, 0); b.ledOn(6, 120, 120, 0); b.ledOn(7, 120, 120, 0); if (sound) { b.playNote("G4",4); } break; case Left: //button 4 red b.ledOn(8, 255, 0, 0); b.ledOn(9, 255, 0, 0); b.ledOn(10, 255, 0, 0); if (sound) { b.playNote("C5",4); } break; case None: delay(100); return; } if (timed) { b.allLedsOff(); } } */ rotura; Derecho del caso: //button 2 azul b.ledOn (2, 0, 0, 255); b.ledOn (3, 0, 0, 255); b.ledOn (4, 0, 0, 255); Si (sonido) {b.playNote("E4",4); void ready() { rotura; Fondo del caso: //button 3 amarillo b.ledOn (5, 120, 120, 0); b.ledOn (6, 120, 120, 0); b.ledOn (7, 120, 120, 0); Si (sonido) {b.playNote("G4",4); if(b.allButtonsOn()){ if(!buttonAll){ buttonAll = 1; Spark.publish("allbuttons",NULL, 60, PRIVATE); b.rainbow(10); delay(100); b.allLedsOff(); } } else {buttonAll = 0;} if(b.buttonOn(1)){ if(!button1){ button1 = 1; Spark.publish("button1",NULL, 60, PRIVATE); b.ledOn(12,30, 250, 0); //top green delay(200); b.ledOff(12); } } else {button1 = 0;} if(b.buttonOn(2)){ if(!button2){ button2 = 1; Spark.publish("ElderHelp",NULL, 60, PRIVATE); b.ledOn(3,0, 0, 255); //right blue delay(100); b.ledOff(3); } } else {button2 = 0;} if(b.buttonOn(3)){ if(!button3){ button3 = 1; Spark.publish("button3",NULL, 60, PRIVATE); b.ledOn(6,120, 120, 0); //bottom yellow delay(100); b.ledOff(6); } } else {button3 = 0;} if(b.buttonOn(4)){ if(!button4){ button4 = 1; Spark.publish("button4",NULL, 60, PRIVATE); b.ledOn(9,255,0,0); //left red delay(100); b.ledOff(9); } } else {button4 = 0;} rotura; Izquierda del caso: //button 4 b.ledOn rojo (8, 255, 0, 0); b.ledOn (9, 255, 0, 0); b.ledOn (10, 255, 0, 0); Si (sonido) {b.playNote("C5",4); //Wait a mo' delay(50); /* Position read = anyButtonOn(); switch (read) { case None: return; case Top: //elderly person GREEN person = 1; break; case Right: // epileptic BLUE object = 4; break; case Bottom: //baby YELLOW object = 8; break; } */ //celebrate(); } rotura; caso ninguno: delay(100); retorno; /* void setColor() { if (object > 0 && object < 2) { RGB.color(30, 250, 0); // green //red (255,0,0) return; } if (object > 3 && object < 6) { RGB.color(0, 0, 255); //blue return; } if (object > 7 && object < 20) { RGB.color(120, 120, 0); //yellow return; } RGB.color(0, 255, 0); } * Si (tiempo) {b.allLedsOff(); * void start() { //generate(object); setColor(); state = Showing; }
void generate(int size) {
if(b.allButtonsOn()) {if(!buttonAll) {buttonAll = 1; Spark.Publish ("allbuttons", NULL, 60, privado); b.Rainbow(10); Delay(100); b.allLedsOff(); } */ } else {buttonAll = 0;} if(b.buttonOn(1)) {if(!button1) {button1 = 1; Spark.Publish ("button1", NULL, 60, privado); b.ledOn (12,30, 250, 0); delay(200) verde superior; b.ledOff(12); void show() { //b.allLedsOff(); //How much are you moving in the x direction? (look at the white text on the board) int xValue = b.readX(); } else {button1 = 0;} if(b.buttonOn(2)) {if(!button2) {button2 = 1; Spark.Publish ("ElderHelp", NULL, 60, privado); b.ledOn (3, 0, 0, 255); delay(100) derecha azul; b.ledOff(3); //How about in the y direction? int yValue = b.readY(); } else {button2 = 0;} if(b.buttonOn(3)) {if(!button3) {button3 = 1; Spark.Publish ("button3", NULL, 60, privado); b.ledOn (6.120, 120, 0); fondo amarillo delay(100); b.ledOff(6); //And the z! int zValue = b.readZ(); } else {button3 = 0;} if(b.buttonOn(4)) {if(!button4) {button4 = 1; Spark.Publish ("button4", NULL, 60, privado); b.ledOn(9,255,0,0); delay(100) rojo izquierdo; b.ledOff(9); int sumAccel = (abs(xValue) + abs(yValue) + abs(zValue))/30; if (sumAccel > 10) { b.allLedsOn(255, 0, 0); //if accelerates flash red b.playNote("G4",4); delay(900); b.allLedsOff(); Spark.publish("ALERT FALLING DOWN",NULL, 60, PRIVATE); }
Esperar un mo' delay(50); / * Posición leer = anyButtonOn(); interruptor (leer) {caso ninguno: volver; caso parte superior: //elderly persona verde persona = 1; break; caso derecho: / / epilépticos objeto azul = 4; break; caso inferior: //baby amarillo objeto = 8; rotura; //int ledPos = b.lowestLed(); /* char payload[255]; * / / / celebrate(); snprintf(payload, sizeof(payload), "{ \"s\":\"Giroscope\", \"u\":\"Gir\",\"l\":\"%s\",\"m\":\"Movement\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, sumAccel, Disp); Serial.println(payload); Spark.publish("ConnectTheDots", payload);
/ * void setColor() {si (objeto > 0 & & objeto < 2) {RGB.color (30, 250, 0); / / verde //red (255,0,0) return; delay(500); */ } /* enum anyButtonOn() { if (b.buttonOn(1)) { return Top; } if (b.buttonOn(2)) { return Right; } if (b.buttonOn(3)) { return Bottom; } if (b.buttonOn(4)) { return Left; } return None; } */ /* void celebrate() { Si (objeto > 3 & & objeto < 6) {RGB.color (0, 0, 255); //blue retorno; delay(500); b.ledOn(11, 30, 250, 0); //255,0,0 b.ledOn(1, 30, 20, 0); b.playNote("C4",4); delay(20); b.allLedsOff(); b.ledOn(2, 0, 0, 255); b.ledOn(3, 0, 0, 255); b.ledOn(4, 0, 0, 255); b.playNote("E4",4); delay(20); b.ledOn(5, 120, 120, 0); b.ledOn(6, 120, 120, 0); b.ledOn(7, 120, 120, 0); b.playNote("G4",4); delay(20); b.ledOn(8, 255, 0, 0); b.ledOn(9, 255, 0, 0); b.ledOn(10, 255, 0, 0); b.playNote("C5",4); */ /* flash(Top, false, false); flash(Right, false, false); flash(Bottom, false, false); flash(Left, false, false); b.playSong("C4,8,E4,8,G4,8,C5,8,G5,4"); delay(300); b.allLedsOff(); */ /* delay(100); //start(); } */ Si (objeto > 7 & & objeto < 20) {RGB.color (120, 120, 0); //yellow retorno; void setup() { //Tell b to get everything ready to go // Use b.begin(1); if you have the original SparkButton, which does not have a buzzer or a plastic enclosure // to use, just add a '1' between the parentheses in the code below. //state = Welcome; RGB.control(true); //int person = 0; b.begin(); welcome(); b.allLedsOff(); } RGB.color (0, 255, 0); SparkButton b = SparkButton();uint8_t button1 = 0; uint8_t button2 = 0; uint8_t button3 = 0; uint8_t button4 = 0; uint8_t buttonAll = 0; int gaugeCount = 0;
* void start() {/ / generate(object); setColor(); estado = demostrar; $ vi webhook.json
{ "event": "ConnectTheDots", "url": "https://XXXXXXX-ns.servicebus.windows.net/ehdevices/messages", "requestType": "POST", "json": { "subject": "{{s}}", "unitofmeasure": "{{u}}", "measurename": "{{m}}", "value": "{{v}}", "organization": "{{o}}", "displayname": "{{d}}", "location": "{{l}}", "timecreated": "{{SPARK_PUBLISHED_AT}}", "guid": "{{SPARK_CORE_ID}}"
},
"azure_sas_token": { "key_name": "D1", "key": "XXXXXXXXXXX" }, "mydevices": true }
$ particle webhook create webhook.json
$ particle webhook list
int sumAccel = (abs(xValue) + abs(yValue) + abs(zValue)) / 30; Si (sumAccel > 10) {b.allLedsOn (255, 0, 0); //if acelera flash rojo b.playNote("G4",4); delay(900); b.allLedsOff(); Spark.Publish ("alerta de caída", NULL, 60, privado);
Delay(500); *// * enum anyButtonOn() {si (b.buttonOn(1)) {return Top;Si (b.buttonOn(2)) {vuelta derecha;Si (b.buttonOn(3)) {vuelta abajo;Si (b.buttonOn(4)) {vuelta izquierda;volver a ninguno;
Delay(500); b.ledOn (11, 30, 250, 0); b.ledOn 255,0,0 (1, 30, 20, 0); b.playNote("C4",4); Delay(20); b.allLedsOff(); b.ledOn (2, 0, 0, 255); b.ledOn (3, 0, 0, 255); b.ledOn (4, 0, 0, 255); b.playNote("E4",4); Delay(20); b.ledOn (5, 120, 120, 0); b.ledOn (6, 120, 120, 0); b.ledOn (7, 120, 120, 0); b.playNote("G4",4); Delay(20); b.ledOn (8, 255, 0, 0); b.ledOn (9, 255, 0, 0); b.ledOn (10, 255, 0, 0); b.playNote("C5",4); * / / * flash (false false, Top,); Flash (false false, derecha); Flash (false false, abajo); Flash (false false, izquierda,); b.playSong("C4,8,E4,8,G4,8,C5,8,G5,4"); Delay(300); b.allLedsOff(); * / / * delay(100); Start();
void setup() {//Tell b para tener todo listo / / usar b.begin(1); si tienes el SparkButton original, que no tiene un zumbador o una caja de plástico / / para usar, sólo tiene que añadir un '1' entre paréntesis en el código de abajo. //state = Bienvenido; RGB.control(true); int persona = 0; b.Begin(); Welcome(); b.allLedsOff();