#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// OLED display width and height, in pixels
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;
#define SCREEN_COLOR SSD1306_WHITE
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Deklarasi array dua dimensi r_theta yang dibagi menjadi 16 bagian
float r_theta_1[][2] = {
{15, 44}, {16, 64}, {17, 64}, {18, 64}, {19, 64}, {20, 64}, {21, 65}, {22, 65}, {23, 64}, {24, 65}
};
float r_theta_2[][2] = {
{25, 65}, {26, 65}, {27, 65}, {28, 65}, {29, 66}, {30, 65}, {31, 66}, {32, 66}, {33, 66}, {34, 68}
};
float r_theta_3[][2] = {
{35, 68}, {36, 161}, {37, 161}, {38, 161}, {39, 160}, {40, 160}, {41, 160}, {42, 160}, {43, 160}, {44, 160}
};
float r_theta_4[][2] = {
{45, 160}, {46, 160}, {47, 160}, {48, 160}, {49, 160}, {50, 160}, {51, 160}, {52, 160}, {53, 160}, {54, 160}
};
float r_theta_5[][2] = {
{55, 147}, {56, 147}, {57, 146}, {58, 146}, {59, 146}, {60, 146}, {61, 146}, {62, 145}, {63, 146}, {64, 146}
};
float r_theta_6[][2] = {
{65, 146}, {66, 146}, {67, 146}, {68, 145}, {69, 145}, {70, 145}, {71, 146}, {72, 146}, {73, 146}, {74, 145}
};
float r_theta_7[][2] = {
{75, 145}, {76, 145}, {77, 146}, {78, 145}, {79, 145}, {80, 145}, {81, 145}, {82, 145}, {83, 145}, {84, 145}
};
float r_theta_8[][2] = {
{85, 145}, {86, 145}, {87, 145}, {88, 44}, {89, 45}, {90, 44}, {91, 44}, {92, 44}, {93, 44}, {94, 145}
};
float r_theta_9[][2] = {
{95, 144}, {96, 145}, {97, 145}, {98, 145}, {99, 145}, {100, 145}, {101, 145}, {102, 145}, {103, 145}, {104, 145}
};
float r_theta_10[][2] = {
{105, 145}, {106, 145}, {107, 145}, {108, 146}, {109, 146}, {110, 146}, {111, 146}, {112, 146}, {113, 146}, {114, 145}
};
float r_theta_11[][2] = {
{115, 145}, {116, 145}, {117, 145}, {118, 146}, {119, 146}, {120, 146}, {121, 146}, {122, 146}, {123, 146}, {124, 146}
};
float r_theta_12[][2] = {
{125, 135}, {126, 134}, {127, 122}, {128, 122}, {129, 122}, {130, 122}, {131, 122}, {132, 122}, {133, 121}, {134, 121}
};
float r_theta_13[][2] = {
{135, 122}, {136, 122}, {137, 122}, {138, 121}, {139, 122}, {140, 122}, {141, 121}, {142, 121}, {143, 122}, {144, 122}
};
float r_theta_14[][2] = {
{145, 123}, {146, 121}, {147, 122}, {148, 122}, {149, 122}, {150, 123}, {151, 122}, {152, 122}, {153, 122}, {154, 134}
};
float r_theta_15[][2] = {
{155, 134}, {156, 123}, {157, 135}, {158, 136}, {159, 134}, {160, 135}, {161, 135}, {162, 134}, {163, 134}, {164, 135}
};
// Array pointer ke array dua dimensi
float (*r_theta_parts[])[2] = {
r_theta_1, r_theta_2, r_theta_3, r_theta_4, r_theta_5, r_theta_6, r_theta_7, r_theta_8,
r_theta_9, r_theta_10, r_theta_11, r_theta_12, r_theta_13, r_theta_14, r_theta_15
};
// Array untuk menyimpan ukuran masing-masing array
int r_theta_sizes[] = {
sizeof(r_theta_1) / sizeof(r_theta_1[0]), sizeof(r_theta_2) / sizeof(r_theta_2[0]),
sizeof(r_theta_3) / sizeof(r_theta_3[0]), sizeof(r_theta_4) / sizeof(r_theta_4[0]),
sizeof(r_theta_5) / sizeof(r_theta_5[0]), sizeof(r_theta_6) / sizeof(r_theta_6[0]),
sizeof(r_theta_7) / sizeof(r_theta_7[0]), sizeof(r_theta_8) / sizeof(r_theta_8[0]),
sizeof(r_theta_9) / sizeof(r_theta_9[0]), sizeof(r_theta_10) / sizeof(r_theta_10[0]),
sizeof(r_theta_11) / sizeof(r_theta_11[0]), sizeof(r_theta_12) / sizeof(r_theta_12[0]),
sizeof(r_theta_13) / sizeof(r_theta_13[0]), sizeof(r_theta_14) / sizeof(r_theta_14[0]),
sizeof(r_theta_15) / sizeof(r_theta_15[0])
};
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
while(true);
}
display.clearDisplay();
}
void loop() {
display.clearDisplay();
// Iterasi melalui semua bagian array
for (int j = 0; j < 15; j++) {
drawLines(r_theta_parts[j], r_theta_sizes[j]);
}
}
void drawLines(float arr[][2], int size) {
for (int i = 0; i < size; i++) {
drawLine(arr[i][0], arr[i][1]);
display.display();
delay(200);
}
}
void drawLine(int distance, int angle){
int x0, y0, x1, y1;
x0 = SCREEN_WIDTH / 2; // Pusat layar secara horizontal
y0 = SCREEN_HEIGHT / 2; // Pusat layar secara vertikal
x1 = x0 + distance * cos(radians(angle)); // Hitung koordinat x akhir
y1 = y0 - distance * sin(radians(angle)); // Hitung koordinat y akhir
// Gambarkan garis dari pusat layar ke titik yang dihitung
display.drawLine(x0, y0, x1, y1, SCREEN_COLOR);
}