119 lines
3.1 KiB
C++

// MAster
#include "dice.h" // Dice Function
#include "header.h" // Player Data Types
#include <Adafruit_NeoPixel.h>
#define LED_PIN 8 // Digital pin connected to the LED strip
#define NUM_LEDS 64 // 8x8 = 64 LEDs
#define BRIGHTNESS 100 // Default max brightness
#define sspacer Serial.println("--------------------------------------------")
#define dspacer Serial.println("============================================")
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
// Convert (row, col) to strip index
uint16_t getIndex(uint8_t row, uint8_t col) {
// Adjust depending on how your strip is wired
if (row % 2 == 0) {
return row * 8 + col; // Left to right
} else {
return row * 8 + (7 - col); // Right to left (zigzag)
}
}
// Set individual LED with row, col, color and brightness
void setPixelColorRC(uint8_t row, uint8_t col, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness) {
if(row >= 8 || col >= 8) return; // Bounds check
strip.setBrightness(brightness);
uint16_t index = getIndex(row, col);
strip.setPixelColor(index, strip.Color(r, g, b));
strip.show();
}
// Optional: set LED by index directly
void setPixelColorIndex(uint16_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness) {
if (index >= NUM_LEDS) return;
strip.setBrightness(brightness);
strip.setPixelColor(index, strip.Color(r, g, b));
strip.show();
}
//================================================================
// SETUP
//================================================================
void setup() {
// I2C Communications
Wire.begin(); // For Master
// Start Serial And Message
Serial.begin(115200);
Serial.println();
dspacer;
// Starting LED Strip
strip.begin();
strip.setBrightness(BRIGHTNESS); // Initial brightness
strip.show(); // Initialize all pixels to 'off'
// Red Player
player[0].i2ca = 0x10;
player[0].position.x = 0;
player[0].position.y = 0;
player[0].color.r = 255;
player[0].color.i = 60;
// Paint The Strip Position For Red Player
setPixelColorRC(
player[0].position.x,
player[0].position.y,
player[0].color.r,
player[0].color.g,
player[0].color.b,
player[0].color.i
);
// Blue Player
player[1].i2ca = 0x20;
player[1].position.x = 7;
player[1].position.y = 7;
player[1].color.b = 255;
player[1].color.i = 60;
// Paint The Strip Position For Blue Player
setPixelColorRC(
player[1].position.x,
player[1].position.y,
player[1].color.r,
player[1].color.g,
player[1].color.b,
player[1].color.i
);
// Make Dicision
diceRoll();
// Make Spacer
dspacer;
}
//================================================================
// LOOP
//================================================================
void loop() {
for(int i=0; i<2; i++) {
movePlayers(i);
}
}
//================================================================
//
//================================================================