/********************************************************************* This is an example for our Monochrome OLEDs based on SSD1306 drivers Pick one up today in the adafruit shop! ------> http://www.adafruit.com/category/63_98 This example is for a 128x64 size display using SPI to communicate 4 or 5 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information All text above, and the splash screen must be included in any redistribution *********************************************************************/ //Re-written for the Adafruit Librarys by A.Tedds #include #include #include #include //Display D0 = Clock. Arduino Pin 10 //Display D1 = SDIN or MOSI. Arduino Pin 9 //Display CS = Chip Select. Arduino Pin 12 //Display RES= Reset. Arduino Pin 13 //Display DC = Data/Command. Arduino pin 11 // If using software SPI (the default case): #define OLED_MOSI 9 #define OLED_CLK 10 #define OLED_DC 11 #define OLED_CS 12 #define OLED_RESET 13 Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); int SCREEN_WIDTH = SSD1306_LCDWIDTH;//128 int SCREEN_HEIGHT = SSD1306_LCDHEIGHT;//64 float d = 3; float px[] = { -d, d, d, -d, -d, d, d, -d }; float py[] = { -d, -d, d, d, -d, -d, d, d }; float pz[] = { -d, -d, -d, -d, d, d, d, d }; float p2x[] = { 0,0,0,0,0,0,0,0}; float p2y[] = { 0,0,0,0,0,0,0,0}; float r[] = { 0,0,0}; #define SHAPE_SIZE 950 //How big the Cube is. // Define how fast the cube rotates. Smaller numbers are faster. // This is the number of ms between draws. #define ROTATION_SPEED 0 void setup() { //Serial.begin(9600); // by default, we'll generate the high voltage from the 3.3v line internally!(neat!) display.begin(SSD1306_SWITCHCAPVCC); //display.display();//Displays Adafruit Logo. display.clearDisplay();// Clear Display delay(1000); } void loop() { drawCube(); delay(ROTATION_SPEED); } void drawCube() { r[0]=r[0]+PI/180.0; // Add a degree r[1]=r[1]+PI/180.0; // Add a degree r[2]=r[2]+PI/180.0; // Add a degree if (r[0] >= 360.0*PI/180.0) r[0] = 0; if (r[1] >= 360.0*PI/180.0) r[1] = 0; if (r[2] >= 360.0*PI/180.0) r[2] = 0; for (int i=0;i<8;i++) { float px2 = px[i]; float py2 = cos(r[0])*py[i] - sin(r[0])*pz[i]; float pz2 = sin(r[0])*py[i] + cos(r[0])*pz[i]; float px3 = cos(r[1])*px2 + sin(r[1])*pz2; float py3 = py2; float pz3 = -sin(r[1])*px2 + cos(r[1])*pz2; float ax = cos(r[2])*px3 - sin(r[2])*py3; float ay = sin(r[2])*px3 + cos(r[2])*py3; float az = pz3-150; p2x[i] = SCREEN_WIDTH/2+ax*SHAPE_SIZE/az; p2y[i] = SCREEN_HEIGHT/2+ay*SHAPE_SIZE/az; } display.clearDisplay();// Clear Display for (int i=0;i<3;i++) { display.drawLine(p2x[i],p2y[i],p2x[i+1],p2y[i+1],WHITE); display.drawLine(p2x[i+4],p2y[i+4],p2x[i+5],p2y[i+5],WHITE); display.drawLine(p2x[i],p2y[i],p2x[i+4],p2y[i+4],WHITE); } display.drawLine(p2x[3],p2y[3],p2x[0],p2y[0],WHITE); display.drawLine(p2x[7],p2y[7],p2x[4],p2y[4],WHITE); display.drawLine(p2x[3],p2y[3],p2x[7],p2y[7],WHITE); display.display(); }