2025-06-10 22:28:08 +03:00

104 lines
2.6 KiB
C++

#include "pins.h"
#include <Wire.h>
#include "healthbar.h"
#include "map.h"
#define X_PIN 1
#define Y_PIN 2
#define BUTTON_PIN 3
#define DEAD_ZONE 50 // Adjust this value for your joystick sensitivity
struct _location {
uint8_t x;
uint8_t y;
};
_location playerLocation;
void setup() {
playerLocation.x = 0;
playerLocation.y = 7;
Serial.begin(9600);
while (!Serial); // Wait for serial monitor on boards like Leonardo
map_begin();
// Display Helth
fastled_begin();
red_health(4, 5);
blue_health(2, 5);
fastled_show();
// map display - map_setDot(int x, int y, byte r, byte g, byte b)
map_setDot(0, 7, 255, 0, 0, 5);
map_setDot(7, 0, 0, 0, 255, 5);
map_show();
// // Initialize I2C buses (example for ESP32)
// Wire.begin(6, 7); // Public I2C (SDA 6, SCL 7)
// Wire1.begin(12, 11); // Local I2C (SDA 12, SCL 11) - remove if not available
}
void loop() {
// Serial.println(String(analogRead(X_PIN)) + " " + String(analogRead(Y_PIN)));
// delay(250);
String joymem = readJoystick();
Serial.println(joymem);
if(joymem == "up") {
if(playerLocation.y < 7) {
// Clear Previous playerLocation
map_setDot(playerLocation.x, playerLocation.y, 0, 0, 0, 0);
// New Value
playerLocation.y += 1;
// Draw On New playerLocation
map_setDot(playerLocation.x, playerLocation.y, 255, 0, 0, 50);
// Display On Map
map_show();
delay(500);
}
} else if(joymem == "down") {
if(playerLocation.y > 0) {
// Clear Previous playerLocation
map_setDot(playerLocation.x, playerLocation.y, 0, 0, 0, 0);
// New Value
playerLocation.y -= 1;
// Draw On New playerLocation
map_setDot(playerLocation.x, playerLocation.y, 255, 0, 0, 50);
// Display On Map
map_show();
delay(500);
}
} else if(joymem == "left") {
if(playerLocation.x > 0) {
// Clear Previous playerLocation
map_setDot(playerLocation.x, playerLocation.y, 0, 0, 0, 0);
// New Value
playerLocation.x -= 1;
// Draw On New playerLocation
map_setDot(playerLocation.x, playerLocation.y, 255, 0, 0, 50);
// Display On Map
map_show();
delay(500);
}
} else if(joymem == "right") {
if(playerLocation.x < 7) {
// Clear Previous playerLocation
map_setDot(playerLocation.x, playerLocation.y, 0, 0, 0, 0);
// New Value
playerLocation.x += 1;
// Draw On New playerLocation
map_setDot(playerLocation.x, playerLocation.y, 255, 0, 0, 50);
// Display On Map
map_show();
delay(500);
}
}
}