Hello everyone, for me c++ is a new language. Last time i write c# scripts(unity) but im not so good there too. I have too many errors in this script, but i dont know what to do with a function errors like: (any function or function(); in code) was not declared in this scope
I read solutions but i didnt saw anything bad in code. Can you help me please?
Here is a code:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_SSD1306 display = Adafruit_SSD1306(3, 4, 5, 7, 6);
#define NUMFLAKES 8
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define pinX A1 // ось X джойстика
#define pinY A2 // ось Y джойстика
#define joybutton A3 // кнопка джойстика
//переменные
int OnHello = 0;
int joy = 0;
unsigned long sleepMiliSEC = 0;
int sleepSEC = 0;
int inMenu = 0;
int menuCursor = 0;
int ChosedButton = 1;
boolean FPStruefalse = 0;
boolean passwordset = 0;
boolean login = 0;
int SettingsChosedButton = 1;
int SettingsmenuCursor = 3;
boolean sleeping = 0;
void setup() {
Serial.begin(9600);
display.begin();
sleepMiliSEC = millis();
pinMode(1, INPUT);
pinMode(pinX, INPUT);
pinMode(pinY, INPUT);
pinMode(joybutton, INPUT);
digitalWrite(joybutton, HIGH);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(5,5);
display.println("Hello, Sasha!");
PassCheck();
}
void loop()
{
JoyStickControl();
fps(1);
//screen sleep:
if(UsingButton == 0)
{
if (millis() - sleepMiliSEC > 1000)
{
sleepMiliSEC = millis();
sleepSEC = sleepSEC + 1;
if(sleepSEC >= 5)
inMenu = 0;
display.clearDisplay();
sleeping = 1;
}
}
if(UsingButton == 1)
{
if(sleepSEC >= 1)
{
sleepSEC = 0;
sleepMiliSEC = 0;
}
}
if(UsingButton == 1)
{
if(sleeping == 1)
{
GoodMorning();
}
}
if(inMenu == 1)
{
if(pinY >= 300)
{
ChosedButton++;
if(ChosedButton == 0)
{
ChosedButton = 3;
display.write(" ");
display.setCursor(10, 2);
display.write(">");
delay(250);
}
if(ChosedButton == 4)
{
ChosedButton = 1;
display.write(" ");
display.setCursor(2, 2);
display.write(">");
delay(250);
}
if(ChosedButton < 4) {
if(ChosedButton > 0)
{
display.write(" ");
display.setCursor(menuCursor + 4, 2);
display.write(">");
delay(250);
}
}
}
if(pinY >= -300)
{
ChosedButton--;
if(ChosedButton == 0)
{
ChosedButton = 3;
display.write(" ");
display.setCursor(10, 2);
display.write(">");
delay(250);
}
if(ChosedButton == 4)
{
ChosedButton = 1;
display.write(" ");
display.setCursor(2, 2);
display.write(">");
delay(250);
}
if(ChosedButton < 4) {
if(ChosedButton > 0)
{
display.write(" ");
display.setCursor(menuCursor - 4, 2);
display.write(">");
delay(250);
}
}
}
if(UsingButton == 1)
{
if(ChosedButton == 1)
{
FlappyBird();
inMenu = 2;
}
if(ChosedButton == 2)
{
inMenu = 3;
}
if(ChosedButton == 3)
{
inMenu = 4;
SettingsMenu();
}
}
}
void GoodMorning()
{
display.setTextColor(WHITE);
display.setCursor(5,5);
display.println("Good Morning!");
delay(500);
display.setCursor(5,7);
display.println("Drag a button to open menu!");
SetPassCheck();
}
if(UsingButton == 1)
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(2,5);
display.println("flappy bird");
display.setCursor(6,5);
display.println("Заметки");
display.setCursor(10,5);
display.println("Настройки");
inMenu = 1;
delay(200);
}
void SettingsMenu()
{
if(inMenu == 4)
{
display.clearDisplay();
display.setCursor(3,2);
display.writeln("FPS:"FPStruefalse);
display.setCursor(1,2);
display.write(">");
if(pinY >= -300)
{
SettingsChosedButton--;
display.write(" ");
display.setCursor(1, SettingsmenuCursor - 2);
if(SettingsmenuCursor == 0)
{
display.write(" ");
display.setCursor(1, 6);
SettingsmenuCursor = 3;
display.write(">");
}
}
}
}
void flappyBird(void) {
uint32_t tp = millis();
float o_speed = 0.05;
float bird_y = 0.5;
float bird_vy = 0;
float g = -1;
uint8_t birdSize = 3;
obstacle obs1;
obstacle obs2;
obs2.x += SCREEN_WIDTH/2;
int score = 0;
bool won = false;
while(true) {
float dx = joyStick.x();
float dy = joyStick.y();
if(won) {
dx = 0;
dy = 0;
}
if (dx*dx + dy*dy > 0.5)
{
//jump
bird_vy = 0.5;
}
float diff = (millis() - tp);
tp = millis();
bird_vy += diff * g / 500;
bird_y += diff * bird_vy / 500;
if(bird_y > 1) {
bird_y = 1;
bird_vy = 0;
}
if(bird_y < 0) {
bird_y = 0;
bird_vy = 0;
}
if(!won) {
obs1.x -= diff * o_speed;
obs2.x -= diff * o_speed;
}
if(obs1.x < -obs1.w/2) {
obs1.x = SCREEN_WIDTH + obs1.w/2;
obs1.h = (SCREEN_HEIGHT - obs1.slotSize)*(float)rand()/RAND_MAX;
score++;
}
if(obs2.x < -obs2.w/2) {
obs2.x = SCREEN_WIDTH + obs2.w/2;
obs2.h = (SCREEN_HEIGHT - obs2.slotSize)*(float)rand()/RAND_MAX;
score++;
}
if((obs1.x > 30 - LOGO_WIDTH / 2) && (obs1.x < 30 + LOGO_WIDTH / 2)) {
bool collision = (bird_y*SCREEN_HEIGHT - LOGO_HEIGHT / 2 < SCREEN_HEIGHT-obs1.h-obs1.slotSize) || (bird_y*SCREEN_HEIGHT + LOGO_HEIGHT / 2 > SCREEN_HEIGHT-obs1.h);
if(collision)
won = true;
}
if((obs2.x > 30 - LOGO_WIDTH / 2) && (obs2.x < 30 + LOGO_WIDTH / 2)) {
bool collision = (bird_y*SCREEN_HEIGHT - LOGO_HEIGHT / 2 < SCREEN_HEIGHT-obs2.h-obs2.slotSize) || (bird_y*SCREEN_HEIGHT + LOGO_HEIGHT / 2 > SCREEN_HEIGHT-obs2.h);
if(collision)
won = true;
}
display.clearDisplay();
//display.drawCircle(30, SCREEN_HEIGHT*(1 - bird_y), birdSize, SSD1306_WHITE);
display.drawBitmap(30 - LOGO_WIDTH / 2, SCREEN_HEIGHT*(1 - bird_y) - LOGO_HEIGHT / 2, birdpic_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.fillRect(obs1.x - obs1.w/2 + 2, 0, obs1.w - 4, obs1.h, SSD1306_WHITE);
display.fillRect(obs1.x - obs1.w/2 + 2, obs1.h + obs1.slotSize, obs1.w - 4, SCREEN_HEIGHT - obs1.h - obs1.slotSize, SSD1306_WHITE);
display.fillRect(obs1.x - obs1.w/2, obs1.h - 4, obs1.w, 4, SSD1306_WHITE);
display.fillRect(obs1.x - obs1.w/2, obs1.h + obs1.slotSize, obs1.w, 4, SSD1306_WHITE);
display.fillRect(obs2.x - obs2.w/2 + 2, 0, obs2.w - 4, obs2.h, SSD1306_WHITE);
display.fillRect(obs2.x - obs2.w/2 + 2, obs2.h + obs2.slotSize, obs2.w - 4, SCREEN_HEIGHT - obs2.h - obs1.slotSize, SSD1306_WHITE);
display.fillRect(obs2.x - obs2.w/2, obs2.h - 4, obs2.w, 4, SSD1306_WHITE);
display.fillRect(obs2.x - obs2.w/2, obs2.h + obs2.slotSize, obs2.w, 4, SSD1306_WHITE);
//drawObstacle(obs1);
//drawObstacle(obs2);
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(4, 4);
display.print("score: ");
display.print(score);
display.display();
if(UsingButton == 1())
break;
}
void JoyStickControl()
{
boolean UsingButton = digitalRead(joybutton);
}
void SetPass()
{
}
void PassCheck()
{
if(passwordset == 1)
{
if(login = 0)
{
display.setCursor(5,7);
display.println("write a password now");
delay(2000);
inMenu = 5;
}
}
static inline void fps(const int seconds){
// Create static variables so that the code and variables can
// all be declared inside a function
static unsigned long lastMillis;
static unsigned long frameCount;
static unsigned int framesPerSecond;
// It is best if we declare millis() only once
unsigned long now = millis();
if(FPStruefalse == 1)
{
frameCount ++;
if (now - lastMillis >= seconds * 1000) {
framesPerSecond = frameCount / seconds;
display.setCursor(18,9);
display.write(framesPerSecond);
frameCount = 0;
lastMillis = now;
}
}
}