Slinger — Arduino Nano simulation

A little arduino nano game

An interactive Arduino Nano circuit simulation you can run free in your browser on Velxio, by mortonben00.

Components

Sketch code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include <Bounce2.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

//sets button pins
const int b1 = 5;
const int b2 = 6;
const int b3 = 7;
// assigns debouncers
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//frame timer
const unsigned long FRAME_TIME = 25;
unsigned long lastFrame = 0;

//---------Ship---------------------
//verticies of the Triangle
const int shipax = 0;
const int shipay = -5;
const int shipbx = 4;
const int shipby = 6;
const int shipcx = -4;
const int shipcy = 6;
//Verticies of the "flame"
const int flameAX = 0;
int flameAY;
const int flameBX = -2;
const int flameBY = 9;
const int flameCX = 2;
const int flameCY = 9;
// sets triangle position on screen
const int shipOriginX = 64;
const int shipOriginY = 32;
// angle value of the triangle
float theta = 1.57; // 360 degrees = 6.28
float shipCos; //X value of theta
float shipSin; //Y value of theta
//final pos values of the triangle
int rax, ray, rbx, rby, rcx, rcy;
//final pos values of the "flame"
int fax, fay, fbx, fby, fcx, fcy;

float velocityX = 0;
float velocityY = 0;
float thrustPower = 0.00;
float friction = 0.9995;
bool thrusting;

//--------------Stars---------------------
// Star 1 position
float posX = 100;
float posY = 50;
int size = 5;
// Star 2 position
float posX2 = 92;
float posY2 = 20;
int size2 = 4;
// Star 3 position
float posX3 = 40;
float posY3 = 15;
int size3 = 3;
// Star 4 position
float posX4 = 15;
float posY4 = 60;
int size4 = 1;
// Star 5 position
float posX5 = 32;
float posY5 = 60;
// Star 6 position
float posX6 = 41;
float posY6 = 17;

//--------Planets---------------
float planetX;
float planetY;
float orbitX;
float orbitY;
float planetSurfaceX;
float planetSurfaceY;
float maxOrbitX;
float maxOrbitY;
int planetSize;
bool planetMade;
float distanceToPlanet;
float orbitDistance;

//-------HUD---------
//orbit pointer
float lineStartOrbitX;
float lineStartOrbitY;
float lineEndOrbitX;
float lineEndOrbitY;


void setup(){
  Serial.begin(115200);
  randomSeed(A0);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;) {}}
  Wire.setClock(400000);
  pinMode(b1, INPUT_PULLUP);
  pinMode(b2, INPUT_PULLUP);
  pinMode(b3,INPUT_PULLUP);
  //attaches the button to the debouncer function to use the button call the debouncer function
  debouncer1.attach(b1); 
  debouncer1.interval(25);
  debouncer2.attach(b2);
  debouncer2.interval(25);
  debouncer3.attach(b3);
  debouncer3.interval(25);
  //readies display
  display.clearDisplay();
  display.display();
}

void loop(){
  //-----Sets frame time---------------------
  unsigned long now = millis();
  if (now - lastFrame < FRAME_TIME) return;
  lastFrame = now;
    //---------clear display---------
  display.clearDisplay

More projects by mortonben00