Final arduino code
This commit is contained in:
@@ -0,0 +1,111 @@
|
|||||||
|
const int alarmButton = 6;
|
||||||
|
const int cancelButton = 7;
|
||||||
|
|
||||||
|
int alarmButtonState = 0;
|
||||||
|
int prevAlarmButtonState = 0;
|
||||||
|
|
||||||
|
int cancelButtonState = 0;
|
||||||
|
int prevCancelButtonState = 0;
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
const int x_out = A1; /* connect x_out of module to A1 of UNO board */
|
||||||
|
const int y_out = A2; /* connect y_out of module to A2 of UNO board */
|
||||||
|
const int z_out = A3; /* connect z_out of module to A3 of UNO board */
|
||||||
|
|
||||||
|
// my added extra variables
|
||||||
|
int avDisplacement = 0;
|
||||||
|
int finx_displacement = 0;
|
||||||
|
int finy_displacement = 0;
|
||||||
|
int finz_displacement = 0;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
pinMode(alarmButton, INPUT);
|
||||||
|
pinMode(cancelButton, INPUT);
|
||||||
|
pinMode(0, OUTPUT);
|
||||||
|
pinMode(1, OUTPUT);
|
||||||
|
pinMode(2, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(0, LOW);
|
||||||
|
digitalWrite(1, LOW);
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
alarmButtonState = digitalRead(alarmButton);
|
||||||
|
cancelButtonState = digitalRead(cancelButton);
|
||||||
|
|
||||||
|
if (alarmButtonState != prevAlarmButtonState)
|
||||||
|
{
|
||||||
|
if (alarmButtonState == LOW)
|
||||||
|
{
|
||||||
|
digitalWrite(0, HIGH);
|
||||||
|
digitalWrite(1, HIGH);
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
Serial.println("Alert:Patient_16_Has_Fallen_Down!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancelButtonState != prevCancelButtonState)
|
||||||
|
{
|
||||||
|
if (cancelButtonState == LOW)
|
||||||
|
{
|
||||||
|
digitalWrite(0, LOW);
|
||||||
|
digitalWrite(1, LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
prevAlarmButtonState = alarmButtonState;
|
||||||
|
prevCancelButtonState = cancelButtonState;
|
||||||
|
|
||||||
|
// new copy-paste accelerometer code
|
||||||
|
int x_adc_value, y_adc_value, z_adc_value;
|
||||||
|
x_adc_value = analogRead(x_out); /* Digital value of voltage on x_out pin */
|
||||||
|
y_adc_value = analogRead(y_out); /* Digital value of voltage on y_out pin */
|
||||||
|
z_adc_value = analogRead(z_out); /* Digital value of voltage on z_out pin */
|
||||||
|
Serial.print("x = ");
|
||||||
|
Serial.print(x_adc_value);
|
||||||
|
Serial.print("\t\t");
|
||||||
|
Serial.print("y = ");
|
||||||
|
Serial.print(y_adc_value);
|
||||||
|
Serial.print("\t\t");
|
||||||
|
Serial.print("z = ");
|
||||||
|
Serial.print(z_adc_value);
|
||||||
|
Serial.print("\t\t");
|
||||||
|
// delay(100);
|
||||||
|
|
||||||
|
finx_displacement = x_adc_value - 850;
|
||||||
|
finy_displacement = y_adc_value - 863;
|
||||||
|
finz_displacement = z_adc_value - 1015;
|
||||||
|
avDisplacement = sqrt((sq(finx_displacement)) + (sq(finy_displacement)) + (sq(finz_displacement)));
|
||||||
|
|
||||||
|
Serial.print("Average Displacement is: ");
|
||||||
|
Serial.print(avDisplacement);
|
||||||
|
delay(150);
|
||||||
|
|
||||||
|
Serial.print("finXdisp = ");
|
||||||
|
Serial.print(finx_displacement);
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print("finYdisp =");
|
||||||
|
Serial.print(finy_displacement);
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print("finZdisp =");
|
||||||
|
Serial.print(finz_displacement);
|
||||||
|
Serial.print("\n\n");
|
||||||
|
delay(150);
|
||||||
|
|
||||||
|
if (avDisplacement > 180)
|
||||||
|
{
|
||||||
|
digitalWrite(0, HIGH);
|
||||||
|
digitalWrite(1, HIGH);
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
Serial.println("Alert:Patient_16_Has_Fallen_Down!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,24 @@
|
|||||||
|
#include <SPI.h>
|
||||||
#include <WiFiNINA.h>
|
#include <WiFiNINA.h>
|
||||||
|
|
||||||
char ssid[] = "SOTON-IoT";
|
char ssid[] = "SOTON-IoT";
|
||||||
char pass[] = "c0YhM1lf8v88";
|
char pass[] = "c0YhM1lf8v88";
|
||||||
|
//char ssid[] = "OnePlus 6T";
|
||||||
|
//char pass[] = "linsey69";
|
||||||
int status = WL_IDLE_STATUS;
|
int status = WL_IDLE_STATUS;
|
||||||
|
|
||||||
int HTTP_PORT = 443;
|
int HTTP_PORT = 443;
|
||||||
String HTTP_METHOD = "GET";
|
String HTTP_METHOD = "POST";
|
||||||
char HOST_NAME[] = "example.phpoc.com";
|
char HOST_NAME[] = "us-central1-picohack-2022.cloudfunctions.net";
|
||||||
String PATH_NAME = "";
|
String PATH_NAME = "/panic";
|
||||||
|
String body = "{\n \"patient\": 16\n}";
|
||||||
WiFiSSLClient client;
|
|
||||||
|
|
||||||
|
WiFiClient client;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
while (status != WL_CONNECTED) {
|
while (status != WL_CONNECTED) {
|
||||||
Serial.print("Attempting to connect to network: ");
|
Serial.print("Attempting to connect to network: ");
|
||||||
Serial.println(ssid);
|
Serial.println(ssid);
|
||||||
@@ -23,25 +27,40 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Connected");
|
Serial.println("Connected");
|
||||||
if(client.connectSSL(HOST_NAME, HTTP_PORT)) {
|
|
||||||
|
if(client.connect(HOST_NAME, HTTP_PORT)) {
|
||||||
|
//Serial.println(client.connected());
|
||||||
Serial.println("Connected to server");
|
Serial.println("Connected to server");
|
||||||
client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1");
|
|
||||||
|
//client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1");
|
||||||
|
client.println("POST /panic HTTP/1.1");
|
||||||
client.println("Host: " + String(HOST_NAME));
|
client.println("Host: " + String(HOST_NAME));
|
||||||
|
|
||||||
|
client.println("Content-Type: application/json");
|
||||||
|
client.println("Content-Length: " + String(body.length()));
|
||||||
|
|
||||||
client.println("Connection: close");
|
client.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
while(client.available())
|
//Serial.println(client.connected());
|
||||||
{
|
|
||||||
|
client.println(body);
|
||||||
|
//Serial.println(client.connected());
|
||||||
|
|
||||||
|
|
||||||
|
//Serial.println(client.available());
|
||||||
|
while(client.connected()) {
|
||||||
|
Serial.println(client.connected());
|
||||||
|
|
||||||
|
if (client.available()){
|
||||||
|
Serial.println("here1");
|
||||||
// read an incoming byte from the server and print them to serial monitor:
|
// read an incoming byte from the server and print them to serial monitor:
|
||||||
char c = client.read();
|
char c = client.read();
|
||||||
Serial.println(c);
|
Serial.println(c);
|
||||||
Serial.println("here");
|
Serial.println("here");
|
||||||
}
|
}}
|
||||||
|
|
||||||
if(!client.connected())
|
|
||||||
{
|
|
||||||
Serial.println("disconnected");
|
Serial.println("disconnected");
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user