Lehmitz
Published © CC BY

Smart LARP Armor

A leather armor breastplate with pressure sensors to count how many times a player has been hit.

IntermediateWork in progressOver 2 days299
Smart LARP Armor

Things used in this project

Story

Read more

Custom parts and enclosures

armor_electronics_box2_iLl8zYLtE8.STL

Schematics

20240117_2018201_8mHmyh0PM1.jpg

Code

LARP Smart Amor

C/C++
Code files to operate the Piezoelectric room controller armor
/* 
 * Project myProject
 * Author: Your Name
 * Date: 
 * For comprehensive documentation and examples, please visit:
 * https://docs.particle.io/firmware/best-practices/firmware-template/
 */

// Include Particle Device OS APIs
#include "Particle.h"
#include "hue.h"
#include "wemo.h"
#include "neopixel.h"
//#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(MANUAL);

// Run the application and system concurrently in separate threads
//SYSTEM_THREAD(ENABLED);

const int PIEZOBUTTON = D14; 
int pinState;
int timerCurrent;
int timerPrior;
int maximum;
int strike;
int lastTime;
const int LEDPIN = D7;
const int YELLOWBUTTON = D6;
const int PIXELCOUNT = 12;
const int NEOPIXEL = D18;
int i;
int j;
const int OLED_RESET=-1;

Adafruit_SSD1306 display(OLED_RESET);
Adafruit_NeoPixel pixel(PIXELCOUNT, SPI1, WS2812B);

void setup() {
  // Put initialization like pinMode and begin functions here
  Serial.begin(9600);
waitFor(Serial.isConnected,10000);
Serial.println("up and running\n");
pinMode(PIEZOBUTTON,INPUT_PULLDOWN);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // start OLED Display system

WiFi.on();
 WiFi.clearCredentials(); // prevent from connecting to DDCIOT
 WiFi.setCredentials("IoTNetwork");
 // If network requires a password
 // setCredentials ( const "" NetworkName ", " Password ");

 WiFi.connect();
 while(WiFi.connecting()) {
 Serial.printf(".");
 }
 Serial.printf("\n\n");

delay(1000);
setHue(4, true, HueGreen, 255, 255);
pinMode (LEDPIN,OUTPUT);
pinMode (YELLOWBUTTON,INPUT);
pinMode (NEOPIXEL, OUTPUT);  //Tell the D18 pin to function on output mode

    // this block gets the neopixels running with begin turning them on.  A basic brightness default, and pixel.show
    // to actually allow them to display.
    pixel.begin();
    pixel.setBrightness(30);
    pixel.show();


    for(i=0;i<13;i++){
      //pixel.clear();
      pixel.setPixelColor(i,0,255,0);
      pixel.show();
      //delay(1000) 
    }
    j=12; // set the starting value for the red health counter leds.  It will count down from here.

}


void loop() {

// setting the inital time state for millis
timerCurrent = millis();

// the piezo sensor requires analog as it can give more than two values.
// pinState records the current input information from the sensor.
//pinState = analogRead(PIEZOBUTTON);


// outputs a descriptive sentence and then the current value of pinState.
//Serial.printf("Hit Detected with force: %i \n", pinState);

//digitalWrite (PIEZOBUTTON, pinState);

//bool setHue(int lightNum, bool HueOn, int HueColor=HueBlue, int HueBright=255, int HueSat=255);


// Takes the value of Maximum at zero and compares it every 250 milliseconds to determine what the higest value recorded
// during that time period was.  
maximum = 0;
lastTime = millis();
while((millis() - lastTime)< 250) {
    strike = analogRead(PIEZOBUTTON);
    if(maximum<strike) {
        maximum = strike;
    }
}
Serial.printf("Armour Sensor Value = %i\n",maximum);

//if (timerCurrent-timerPrior<=500){

  // Average baseline for the sensor is about 25.  Any significant change in pressure shoul push the value above 50.
  if(maximum>50) {
    //delay(1000);
    
    setHue(4, true, HueRed, 255, 255);  // Turn on 3 of the Hue Ligts in the color green.
    setHue(3, true, HueRed, 255, 255);
    setHue(2, true, HueRed, 255, 255);
    //delay(1000);
    switchON(0);
    switchON(3);
    switchON(4);
    setHue(4, true, HueGreen, 255, 255);
    setHue(3, true, HueGreen, 255, 255);
    setHue(2, true, HueGreen, 255, 255);
    switchOFF(0);
    switchOFF(3);
    switchOFF(4);
    
    //delay(1000);
    // SwitchON and OFF activate and deactivat the HUE outlets lighting the arious objects in the room.  While they
    // initially are using a delay this will be replaced in later version.
    //digitalWrite(D7, HIGH);
    
      j--;
      pixel.setPixelColor(j,255,0,0);
      pixel.show();
      delay(1000);
    
  } 

pinState = digitalRead(YELLOWBUTTON);
Serial.printf("The value of the button is %i \n", pinState);

  if (pinState>0){
    j=12;
    digitalWrite (D7, HIGH);
        for(i=0;i<13;i++){
      //pixel.clear();
      pixel.setPixelColor(i,0,255,0);
      
      //delay(1000) 
    }

    pixel.show();
  }

    //pixel.clear();  // Clear refreshes all values to default off
    //pixel.setPixelColor(3, 100, 100, 100); // selects pixel and defines its color with RGB values.

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.printf("Hit Points remaining %i \n", j); 
  display.display();
}

Credits

Lehmitz

Lehmitz

3 projects • 5 followers

Comments