/*
* Project Portal_Capstone
* Description: “Everything you can imagine is real.” – Pablo Picasso
* Author: Chad Waples
* Date:7/31/2021
*/
#include "DFRobotDFPlayerMini.h"
#include "Adafruit_APDS9960_Particle.h" // Proximity & Gesture Sensor
#include <neopixel.h>
#include "colors.h"
#include "Particle.h"
#include "HX711.h"
#include "patterns.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN A5
#define PIXEL_COUNT 1024 // for image 1024 which is 32 x 32 otherwise 579
#define PIXEL_TYPE WS2812B
//General headers
int j;
int color;
int randNumber;
int myImage[PIXEL_COUNT];
int payloadNum;
Adafruit_NeoPixel matrix(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int imgData[3*PIXEL_COUNT+7];
int matrixRandom[PIXEL_COUNT];
int myMatrix[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, -1, -1, -1, -1,
-1, -1, -1, -1, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, -1, -1, -1,
-1, -1, -1, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, -1, -1,
-1, -1, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, -1,
-1, -1, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, -1,
-1, -1, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, -1,
-1, -1, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, -1,
-1, -1, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, -1,
-1, -1, 300, 299, 298, 297, 296, 295, 294, 293, 292, 291, 290, 289, 288, 287, 286, 285, 284, 283, 282, 281, 280, 279, 278, 277, 276, 275, 274, 273, 272, -1,
-1, -1, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, -1,
-1, -1, 358, 357, 356, 355, 354, 353, 352, 351, 350, 349, 348, 347, 346, 345, 344, 343, 342, 341, 340, 339, 338, 337, 336, 335, 334, 333, 332, 331, 330, -1,
-1, -1, -1, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, -1, -1,
-1, -1, -1, -1, 410, 409, 408, 407, 406, 405, 404, 403, 402, 401, 400, 399, 398, 397, 396, 395, 394, 393, 392, 391, 390, 389, 388, 387, 386, -1, -1, -1,
-1, -1, -1, -1, -1, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 454, 453, 452, 451, 450, 449, 448, 447, 446, 445, 444, 443, 442, 441, 440, 439, 438, 437, 436, 435, 434, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 486, 485, 484, 483, 482, 481, 480, 479, 478, 477, 476, 475, 474, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,};
//DF Player (SOUNDS)
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
const int ALARM = 1;
const int ENGINE = 2;
const int DEPARTURE = 3;
const int PULSING = 8;
const int GRAIN = 4;
const int CHARGEDOWN = 6;
const int ALIENSAUCER = 5;
//PIR Proximity infrared and detection
int pirPin = D5;
bool pirStat = 0;
bool detected = true;
bool present;
unsigned long timer;
// Load Cell
HX711 myScale(11, 12);
const int CAL_FACTOR=975;
const int SAMPLES=10;
float pressure, rawData, calibration;
int offset;
// Setup BLE UART
const size_t UART_TX_BUF_SIZE = 12;
uint8_t txBuf[UART_TX_BUF_SIZE];
uint8_t imgBuf[3];
uint8_t i;
// These UUIDs were defined by Nordic Semiconductor and are now the defacto standard for
// UART-like services over BLE. Many apps support the UUIDs now, like the Adafruit Bluefruit app.
const BleUuid serviceUuid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
const BleUuid rxUuid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E");
const BleUuid txUuid("6E400003-B5A3-F393-E0A9-E50E24DCCA9E");
BleCharacteristic txCharacteristic("tx", BleCharacteristicProperty::NOTIFY, txUuid, serviceUuid);
BleCharacteristic rxCharacteristic("rx", BleCharacteristicProperty::WRITE_WO_RSP, rxUuid, serviceUuid, onDataReceived, NULL);
BleAdvertisingData data;
//GESTURE SENSOR
Adafruit_APDS9960 apds;
void setup() {
Serial.begin(9600); //originally 115200, why?
Serial1.begin(9600);
// Serial1.begin(115200);
pinMode (pirPin, INPUT);
waitFor(Serial.isConnected, 15000);
myScale.set_scale();
delay(2000);
myScale.tare();
myScale.set_scale(CAL_FACTOR);
// DFPlayer MINI
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(Serial1)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
// Speaker volume
myDFPlayer.volume(10); //Set volume value. From 0 to 30
BLE.on();
Serial.printf("Starting up BLE Connection \n");
BLE.addCharacteristic(txCharacteristic);
BLE.addCharacteristic(rxCharacteristic);
data.appendServiceUUID(serviceUuid);
BLE.advertise(&data);
Serial.printf("Argon BLE Address: %s\n",BLE.address().toString().c_str());
//Neopixels with brightness
matrix.begin();
matrix.setBrightness(20);
matrix.show(); // Initialize all pixels to 'off'
if(!apds.begin()){
Serial.println("failed to initialize device! Please check your wiring.");
}
else Serial.println("Device initialized!");
apds.enableProximity(true); // enable proximity
apds.enableGesture(true); //enable gestures
}
void loop() {
pirStat = digitalRead(pirPin);
pressure = myScale.get_units(SAMPLES);
Serial.printf("Pressure is: %0.2f\n PIR = %i\n", pressure, pirStat);
if (pirStat == HIGH) {
hum();
myDFPlayer.play(PULSING);
delay(500);
}
if (pressure <= -100){
fillrandom();
}
if (pressure <=-300){
danger();
}
pulseout();
pulsein();
//read a gesture from the device
uint8_t gesture = apds.readGesture();
if(gesture == APDS9960_DOWN) Serial.println("v");
if(gesture == APDS9960_UP) Serial.println("^");
if(gesture == APDS9960_LEFT) Serial.println("<");
if(gesture == APDS9960_RIGHT) Serial.println(">");
}
//FUNCTIONS LIST
void fill(int color, int first, int count) {
int i;
for (i=first; i<first+count; i++){
matrix.setPixelColor(i, color);
matrix.show();
delay(10);
}
}
void filldown() {
int j;
matrix.clear();
for (j=0; j<PIXEL_COUNT; j = j+8){
fill(0xff0000,j,8);
matrix.show();
}
}
void fillup() {
int j;
matrix.clear();
for (j=PIXEL_COUNT; j>=0; j = j-8){
fill(0x00ff00,j,8);
matrix.show();
}
}
Comments
Please log in or sign up to comment.