#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int hCenter = 32; // horizontal center of 64 / 2 = 32
int Radius = 30;
const float Pi = 3.14159265359;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
}
void loop() {
display.clearDisplay();
display.drawRect(0, 0, 120, 64, WHITE);
display.drawLine(0,30,120,30,WHITE);
display.drawLine(30,0,30,64,WHITE);
display.drawLine(60,0,60,64,WHITE);
display.drawLine(90,0,90,64,WHITE);
for (int i=0; i<120; i++)
{
float Angle = i * 3;
int a = (hCenter + (sin(Angle * (Pi / 180)) * Radius));
int b = (hCenter + (cos(Angle * (Pi / 180)) * Radius));
display.drawPixel(i,a,WHITE);
display.drawPixel(i,b,WHITE);
display.display();
}
}