I just got an Idea of trying to code rain simulation with arduino and Adafruit OLED display. When I finished it was quite messy code so I thought That maybe doing it Object Oriented would help. This code is just a sketch that MAYBE works. The thing is that I need to create an array of objects(drops) and then display them. I have tried to display just one drop and it does not seem to do anything, even Serial wont print the pos_y. I have never wrote an Arduino code with objects so I just made a quick research and tried. here is the code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
class Drop{
private:
int pos_x = random(0, 128);
int pos_y = random(-5, -20);
int len = random(3, 7);
int speed = random(6, 13);
public:
void fall()
{
display.drawFastVLine(pos_x, pos_y, len, 1);
pos_y = pos_y + speed;
delay(5);
Serial.println(pos_y);
display.display();
display.clearDisplay();
}
};
Drop* drop = new Drop[50];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
}
void loop() {
drop[1].fall();
}
I will appreciate any suggestion or solution, spent almost entire day doing this "simple thing"..
Adafruit_SSD1306
that just prints to the serial port. It seems to work as expected.