#include <EEPROM.h>
#include <Adafruit_HX711.h>
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <LiquidCrystal_I2C.h>
#define buttonUp 2
#define buttonDown 3
// Define other constants
const int passwordLength = 12;
const int characterSetLength = 68;
const int inputRangeMin = -32768; // Adjust based on your MPU6050 range
const int inputRangeMax = 32767;
const int stepSize = 1000; // Example increment value, adjust as needed
char characterSet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
int passwordIndex = 0;
bool passwordGenerated = false;
Adafruit_HX711 loadCell(6, 5); // Define correct pins for HX711
Adafruit_MPU6050 mpu;
LiquidCrystal_I2C lcd(0x27, 20, 4); // LCD with I2C address 0x27, 20x4 size
void setup() {
Serial.begin(9600);
// Initialize MPU6050
if (!mpu.begin()) {
Serial.println("MPU6050 initialization failed!");
while (1);
}
// Initialize load cell
if (!loadCell.begin()) {
Serial.println("HX711 initialization failed!");
while (1);
}
// Initialize LCD
lcd.init();
lcd.backlight();
}
void generatePassword() {
sensors_event_t event;
mpu.getAccelerometerSensor()->getEvent(&event);
char passwordCharacter[passwordLength];
int gyroValueX = event.acceleration.x;
int gyroValueY = event.acceleration.y;
int gyroValueZ = event.acceleration.z;
int loadCellValue = loadCell.readChannel(1); // Get load cell value from Adafruit HX711
if (!passwordGenerated) {
for (int i = 0; i < passwordLength; i++) {
int characterIndex = map((gyroValueX + gyroValueY + gyroValueZ + loadCellValue), inputRangeMin, inputRangeMax, 0, characterSetLength - 1);
passwordCharacter[i] = characterSet[characterIndex];
gyroValueX += stepSize;
gyroValueY += stepSize;
gyroValueZ += stepSize;
}
// Save generated password to EEPROM
int passwordAddress = passwordIndex * passwordLength;
for (int i = 0; i < passwordLength; i++) {
EEPROM.write(passwordAddress + i, passwordCharacter[i]);
}
EEPROM.write(passwordAddress + passwordLength, passwordIndex); // Save password index
passwordGenerated = true;
passwordIndex++; // Increment password index for next password
}
}
void displayPassword() {
int passwordAddress = passwordIndex * passwordLength;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Password No:");
lcd.setCursor(12, 0);
lcd.print(passwordIndex); // Correctly display password number
delay(2000); // Delay to show the password number
lcd.setCursor(0, 1);
for (int i = 0; i < passwordLength; i++) {
char passwordCharacter = EEPROM.read(passwordAddress + i);
if (passwordCharacter >= 32 && passwordCharacter <= 126) { // Ensure valid ASCII character range
lcd.print(passwordCharacter);
} else {
lcd.print('?'); // Replace invalid characters with a placeholder
}
}
while (!digitalRead(buttonUp) && !digitalRead(buttonDown)) {
// Wait for buttonUp or buttonDown to be pressed
}
}
void loop() {
generatePassword();
displayPassword();
delay(5000); // Delay before regenerating and displaying the next password
}