@copilot Can You help me with this code?
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------>
http://www.adafruit.com/category/63_98
This example is for a 128x32 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h> //Libreria TTF
//
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif18pt7b.h> // Add a custom font
#include <Fonts/FreeSansOblique9pt7b.h>
#include <Fonts/FreeMono9pt7b.h>
//
#include <Adafruit_SSD1331.h>
//
#define OLED_RESET 4
//Adafruit_SSD1306 display(OLED_RESET);
// Declare pins for the display:
#define TFT_CS 10
#define TFT_RST 9 // You can also connect this to the Arduino reset in which case, set this
#define pin to -1!
#define TFT_DC 8
// The rest of the pins are pre-selected as the default hardware SPI for Arduino Uno (SCK = 13 and SDA = 11)
// Create display:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
//Esta parte del codigo define los tonos del tema musical
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int cH = 523;
const int cSH = 554;
const int dH = 587;
const int dSH = 622;
const int eH = 659;
const int fH = 698;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;
/Definicion de variables para contadores radios del tamaños de la Estrella de la muerte
así como como sus disparos/
int metx = 0; //posición horizontal del proyectil del jugador
int mety = 0; //posición vertical del proyectil del jugador
int postoji = 0; //controlar si un proyectil del jugador está en existencia o no. Esta variable se inicializa en 0 y se actualiza durante el bucle principal del juego.
int nep = 8; //representar la posición vertical del enemigo
int smjer = 0; //determinar la dirección del movimiento del enemigo si llega a cierto limite sube o baja
int go = 0;
int rx = 95;
int ry = 0;
int rx2 = 95;
int ry2 = 0;
int rx3 = 95;
int ry3 = 0;
int puntos = 0;
int speed = 3; //speed of bullet
int disparo = 1;
int najmanja = 600;
int najveca = 1200;
int promjer = 10;
int rx4 = 95;
int ry4 = 0;
int zivoti = 5;
int poc = 0;
int ispaljeno = 0;
int nivo = 1;
int centar = 95;
unsigned long pocetno = 0;
unsigned long odabrano = 0;
unsigned long trenutno = 0;
unsigned long nivovrije = 0;
int poz = 30;
//diodal es la nave de la Resistencia
const unsigned char PROGMEM dioda16 [] = {
0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x3F, 0xF0, 0x3C, 0x00, 0x3C, 0x00, 0xFF, 0x00, 0x7F, 0xFF,
0x7F, 0xFF, 0xFF, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x1F, 0xF0, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00
};
//Codigo de la imagen inicial del storm trooper
const unsigned char PROGMEM storm [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0x00, 0x00, 0x00, 0x07, 0x80, 0x01, 0xE0, 0x00, 0x00, 0x0C,
0x00, 0x00, 0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x30, 0x00, 0x00, 0x04, 0x00,
0x00, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x60, 0x00, 0x00,
0x02, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x40,
0x00, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7F, 0xE0, 0x00, 0x01, 0x00,
0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xD7, 0xFF, 0xFF,
0xE1, 0x00, 0x01, 0xBF, 0xFC, 0x1F, 0xFA, 0x80, 0x01, 0xBF, 0xF1, 0xCF, 0xFA, 0x80, 0x01, 0x3F,
0xC2, 0x37, 0xF7, 0x80, 0x01, 0xEF, 0x9C, 0x01, 0xE7, 0xC0, 0x01, 0xE0, 0x70, 0x06, 0x06, 0x80,
0x01, 0xE0, 0xC0, 0x03, 0x06, 0x80, 0x01, 0xFF, 0x80, 0x01, 0xFF, 0x80, 0x01, 0xF8, 0x00, 0x00,
0x1D, 0xC0, 0x03, 0x70, 0x00, 0x80, 0x0C, 0x60, 0x05, 0xB0, 0x07, 0xF0, 0x08, 0x90, 0x09, 0x10,
0x1F, 0xF8, 0x09, 0xD0, 0x0B, 0x90, 0x1F, 0x7C, 0x03, 0xF0, 0x0F, 0xC0, 0xFC, 0x0F, 0x07, 0x90,
0x0D, 0x43, 0xC0, 0x03, 0x07, 0x90, 0x05, 0x64, 0x00, 0x00, 0xCF, 0x10, 0x07, 0xFC, 0x00, 0x00,
0x26, 0x10, 0x01, 0x80, 0x00, 0x00, 0x10, 0x20, 0x01, 0x00, 0x00, 0x00, 0x0E, 0x40, 0x01, 0x80,
0x07, 0xF0, 0x01, 0x80, 0x00, 0x80, 0x07, 0xC8, 0x00, 0x80, 0x00, 0x80, 0x0B, 0xE8, 0x00, 0x80,
0x00, 0x87, 0x97, 0xE9, 0xE0, 0x80, 0x00, 0x87, 0xDF, 0xEF, 0xA0, 0x80, 0x00, 0x4B, 0xFF, 0xFF,
0xA0, 0x80, 0x00, 0x6B, 0xDF, 0xFB, 0xA3, 0x00, 0x00, 0x24, 0x97, 0xE8, 0x24, 0x00, 0x00, 0x1E,
0x1F, 0xC0, 0x2C, 0x00, 0x00, 0x07, 0xF8, 0x1F, 0xF0, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00
};
//Inicio del código
void setup()
{
pinMode(3, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
//display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Display setup:
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_BLACKTAB); // Initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK); // Fill screen with black
//tft.setRotation(0); // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0,
// which is portrait mode.
tft.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
// We are going to print on the display everything that is static on the setup, to leave the loop free for dynamic elements:
// Write to the display the text "Hello":
//display.display();
// display.clearDisplay();
tft.drawBitmap(20, 30, storm, 48, 48, 1); //imprime imagen Storm trooper
tft.setTextColor(ST7735_CYAN)
tft.setCursor(0, 0);
float voltaza = readVcc() / 1000; //Imprime Voltaje de la placa
tft.println(voltaza);;
//Imprime NOMBRE DEL JUEGO
tft.setFont(&FreeSans9pt7b);// Start using a custom font: FreeSansOblique9pt7b.h FreeMono9pt7b.h
tft.setTextColor(ST7735_GREEN);// Set color of text. First is the color of text and after is color of background
tft.setTextSize(0);
tft.setCursor(55, 14);
tft.println("X-Wing");
tft.setFont(&FreeSerif18pt7b);
tft.setCursor(65, 17);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(0);
tft.println("vs");
//Imprime Nombre le Juego
tft.setFont(&FreeSans9pt7b);
tft.setTextColor(ST7735_RED);
tft.setCursor(65, 39);
tft.println("Death");
tft.setCursor(65, 42);
tft.println("star");
//A U T O R
tft.setTextSize(0);
tft.setCursor(65, 55);
tft.println("modified by Bilskirnir V 1.0");
tft.setCursor(65, 20);
//tft.display();
tft.setFont();
//REPRODUCIR TONO INICIAL
beep(a, 500);
beep(a, 500);
beep(a, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);
delay(500);
delay(500);
}
void loop() {
if (go == 0) {
//tft.clearDisplay();
tft.initR(INITR_BLACKTAB); // Initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK); // Fill screen with black
//tft.setRotation(0); // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0,
// which is portrait mode.
tft.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
tft.drawPixel(50, 30, ST7735_WHITE);
tft.drawPixel(30, 17, ST7735_CYAN);
tft.drawPixel(60, 18, ST7735_YELLOW);
tft.drawPixel(55, 16, ST7735_MAGENTA);
tft.drawPixel(25, 43, ST7735_WHITE);
tft.drawPixel(100, 43, ST7735_CYAN);
tft.drawPixel(117, 52, ST7735_MAGENTA);
tft.drawPixel(14, 49, ST7735_CYAN);
tft.drawPixel(24, 24, ST7735_YELLOW);
tft.drawPixel(78, 36, ST7735_MAGENTA);
tft.drawPixel(80, 57, ST7735_WHITE);
tft.drawPixel(107, 11, ST7735_CYAN);
tft.drawPixel(150, 11, ST7735_WHITE);
tft.drawPixel(5, 5, ST7735_MAGENTA);
tft.drawPixel(8, 7, ST7735_GREEN);
tft.drawPixel(70, 12, ST7735_CYAN);
tft.drawPixel(10, 56, ST7735_YELLOW);
tft.drawPixel(70, 25, ST7735_GREEN);
if (poc == 0) {
pocetno = millis();
odabrano = random(400, 1200);
poc = 1;
}
trenutno = millis();
//nivoi
if ((trenutno - nivovrije) > 50000)
{
nivovrije = trenutno;
nivo = nivo + 1;
speed = speed + 1; //VELOCIDAD DE LA BALA DEL ENEMIGO brizna neprijateljevog BALA (metka)
if ( nivo % 2 == 0 )
{
disparo = disparo + 1;
promjer = promjer - 1;
}
najmanja = najmanja - 50;
najveca = najveca - 50;
}
if ((odabrano + pocetno) < trenutno)
{
poc = 0;
ispaljeno = ispaljeno + 1;
if (ispaljeno == 1)
{ rx = 95;
ry = nep;
}
if (ispaljeno == 2) {
rx2 = 95;
ry2 = nep;
}
if (ispaljeno == 3)
{
rx3 = 95;
ry3 = nep;
}
if (ispaljeno == 4) {
rx4 = 95;
ry4 = nep;
}
}
if (ispaljeno > 0)
{
tft.drawCircle(rx, ry, 2, 1);
rx = rx - speed;
}
if (ispaljeno > 1)
{
tft.drawCircle(rx2, ry2, 1,ST7735_GREEN);
rx2 = rx2 - speed;
}
if (ispaljeno > 2)
{
tft.drawCircle(rx3, ry3, 4,ST7735_GREEN);
rx3 = rx3 - speed;
}
if (ispaljeno > 3)
{
tft.drawCircle(rx4, ry4, 2,ST7735_GREEN);
rx4 = rx4 - speed;
}
/**/
if (digitalRead(12) == 0 && poz >= 2) {
poz = poz - 2;
}
if (digitalRead(11) == 0 && poz <= 46) {
poz = poz + 2;
}
if (digitalRead(3) == 0 && postoji == 0)
{
postoji = 1;
metx = 6;
mety = poz + 8;
tone(9, 1200, 20);
}
if (postoji == 1)
{
metx = metx + 8 ;
tft.drawLine(metx, mety, metx + 4, mety, 1);
}
tft.drawBitmap(4, poz, dioda16, 16, 16, 1);
tft.fillCircle(centar, nep, promjer, 1);
tft.fillCircle(centar + 2, nep + 3, promjer / 3, 0);
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(33, 57);
tft.println("score:");
tft.setCursor(68, 57);
tft.println(puntos);
tft.setCursor(33, 0);
tft.println("lives:");
tft.setCursor(68, 0);
tft.println(zivoti);
tft.setCursor(110, 0);
tft.println("L:");
tft.setCursor(122, 0);
tft.println(nivo);
tft.setCursor(108, 57);
tft.println(trenutno / 1000);
tft.display();
if (metx > 128)postoji = 0;
if (smjer == 0) {
nep = nep + disparo;
}
else
{
nep = nep - disparo;
}
if (nep >= (64 - promjer))
smjer = 1;
if (nep <= promjer)
smjer = 0;
if (mety >= nep - promjer && mety <= nep + promjer)
if (metx > (centar - promjer) && metx < (centar + promjer))
{
metx = -20;
tone(9, 500, 20);
puntos = puntos + 1;
postoji = 0;
}
int pozicija = poz + 8;
if (ry >= pozicija - 8 && ry <= pozicija + 8)
if (rx < 12 && rx > 4)
{
rx = 95;
ry = -50;
tone(9, 100, 100);
zivoti = zivoti - 1;
}
if (ry2 >= pozicija - 8 && ry2 <= pozicija + 8)
if (rx2 < 12 && rx2 > 4)
{
rx2 = -50;
ry2 = -50;
tone(9, 100, 100);
zivoti = zivoti - 1;
}
if (ry3 >= pozicija - 8 && ry3 <= pozicija + 8)
if (rx3 < 12 && rx3 > 4)
{
rx3 = -50;
ry3 = -50;
tone(9, 100, 100);
zivoti = zivoti - 1;
}
if (ry4 >= pozicija - 8 && ry4 <= pozicija + 8)
if (rx4 < 12 && rx4 > 4)
{
rx4 = 200;
ry4 = -50;
ispaljeno = 0;
tone(9, 100, 100);
zivoti = zivoti - 1;
}
if (rx4 < 1) {
ispaljeno = 0;
rx4 = 200;
}
if (zivoti == 0)
go = 1;
}
// Código para mostrar la pantalla de "Game Over", reproduce musica de fin de juego
if (go == 1)
{
if (zivoti == 0) {
tone(9, 200, 300);
delay(300);
tone(9, 250, 200);
delay(200);
tone(9, 300, 300);
delay(300);
zivoti = 5;
}
tft.clearDisplay();
tft.setFont();
tft.setTextSize(2);
tft.setTextColor(ST7735_BLUE);
tf.setCursor(7, 10);
tft.println("GAME OVER!");
tft.setTextSize(1);
tft.setCursor(7, 30);
tft.println("score:");
tft.setCursor(44, 30);
tft.println(puntos);
tft.setCursor(7, 40);
tft.println("level:");
tft.setCursor(44, 40);
tft.println(nivo);
tft.setCursor(7, 50);
tft.println("time(s):");
tft.setCursor(60, 50);
tft.println(trenutno / 1000);
tft.display();
if (digitalRead(3) == 0)
{
tone(9, 280, 300);
delay(300);
tone(9, 250, 200);
delay(200);
tone(9, 370, 300);
delay(300);
ponovo();
}
}
}
void ponovo()
{
metx = 0;
mety = 0;
postoji = 0;
nep = 8;
smjer = 0;
go = 0;
rx = 95;
ry = 0;
rx2 = 95;
ry2 = 0;
rx3 = 95;
ry3 = 0;
puntos = 0;
speed = 3; //brizna neprijateljevog metka
disparo = 1;
najmanja = 600;
najveca = 1200;
promjer = 12;
rx4 = 95;
ry4 = 0;
zivoti = 5;
poc = 0;
ispaljeno = 0;
nivo = 1;
pocetno = 0;
odabrano = 0;
trenutno = 0;
nivovrije = 0;
}
long readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA, ADSC)); // measuring
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
long result = (high << 8) | low;
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.110231000
return result; // Vcc in millivolts
}
void beep(int note, int duration)
{
//Play tone on buzzerPin
tone(9, note, duration);
delay(duration);
noTone(9);
delay(50);
}