I have created the following code to depict a snow scene using an Arduino Nano and an OLED screen.
The code works perfectly but what I'd like to do is to move everything between lines 10 to 47 ( from "Class Snow" to just above "Snow Flake[FLAKE_COUNT];") to a new tab. However, when I do, I start to see errors, for example: "Snow flake[FLAKE_COUNT];" gives:
'snow_test:12:1: error: 'Snow' does not name a type; did you mean 'pow'?
Snow flake[FLAKE_COUNT];'
Snowfall.ino (1.7 KB)
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define FLAKE_COUNT 30
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
class Snow {
public:
int x, y;
int radius;
int speedX;
int speedY;
int r = 4;
Snow() : x(0), y(0), radius(0), speedX(0), speedY(0){}
Snow(int initialX, int initialY, int initialSize, int initialSpeedX, int initialSpeedY)
: x(initialX+8), y(initialY), radius(initialSize), speedX(initialSpeedX), speedY(initialSpeedY) {}
void update() {
y = y + random(1,4);
x = x + random(-1, 4);
}
void show() {
display.drawPixel(x, y, SSD1306_WHITE);
}
void edges() {
if (y > SCREEN_HEIGHT) {
y = 0 + r;
}
if (x < -r) {
x = SCREEN_WIDTH - r;
}else{
if (x > SCREEN_WIDTH) {
x = 0 + r;
}
}
}
};
Snow flake[FLAKE_COUNT];
void setup() {
// put your setup code here, to run once:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(500);
display.clearDisplay();
for (int i = 0; i < FLAKE_COUNT; ++i) {
flake[i] = Snow(random(SCREEN_WIDTH), (SCREEN_HEIGHT), 4, random(2,5), random(2,5));
}
}
void loop() {
display.clearDisplay();
for (int i = 0; i < FLAKE_COUNT; ++i) {
flake[i].update();
flake[i].show();
flake[i].edges();
}
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(100,64);
//display.print("THE WINTER");
display.fillRect(0, 59, 128, 5, WHITE);
display.fillCircle(100, 54, 10, WHITE);
display.fillCircle(105, 40, 5, WHITE);
display.display();
delay(20);
}
Could anybody point me in the right direction?
Thanks in advance