├── library.properties ├── keywords.txt ├── examples ├── i2c_SSD1306_SensorPlayground │ └── i2c_SSD1306_SensorPlayground.ino ├── i2c_SSD1306_AnimationSequences │ └── i2c_SSD1306_AnimationSequences.ino ├── i2c_SSD1306_Basics │ └── i2c_SSD1306_Basics.ino ├── spi_SSD1306_AnimationSequences │ └── spi_SSD1306_AnimationSequences.ino ├── spi_SSD1322_Basics │ └── spi_SSD1322_Basics.ino ├── spi_SSD1306_Basics │ └── spi_SSD1306_Basics.ino ├── i2c_SH1106_Basics │ └── i2c_SH1106_Basics.ino ├── i2c_SSD1306_DHT22-TemperatureSensor │ └── i2c_SSD1306_DHT22-TemperatureSensor.ino └── i2c_SSD1306_ConfigurationBoard │ └── i2c_SSD1306_ConfigurationBoard.ino ├── README.md ├── src └── FluxGarage_RoboEyes.h └── LICENSE.txt /library.properties: -------------------------------------------------------------------------------- 1 | name=FluxGarage RoboEyes for OLED Displays 2 | version=1.1.1 3 | author=Dennis Hoelscher 4 | maintainer=Dennis Hoelscher 5 | sentence=Draws smoothly animated robot eyes on OLED displays, using the Adafruit GFX library. 6 | paragraph=Robot eye shapes are configurable in terms of width, height, border radius and space between. Several different mood expressions (happy, tired, angry, default) and animations (autoblinker, idle, laughing, confused) are available. 7 | category=Display 8 | url=https://github.com/FluxGarage/RoboEyes 9 | architectures=* 10 | depends=Adafruit GFX Library 11 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For RoboEyes 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | RoboEyes KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | begin KEYWORD2 14 | update KEYWORD2 15 | setFramerate KEYWORD2 16 | setDisplayColors KEYWORD2 17 | setWidth KEYWORD2 18 | setHeight KEYWORD2 19 | setBorderradius KEYWORD2 20 | setSpacebetween KEYWORD2 21 | setMood KEYWORD2 22 | setPosition KEYWORD2 23 | setAutoblinker KEYWORD2 24 | setIdleMode KEYWORD2 25 | setCuriosity KEYWORD2 26 | setCyclops KEYWORD2 27 | setHFlicker KEYWORD2 28 | setVFlicker KEYWORD2 29 | setSweat KEYWORD2 30 | getScreenConstraint_X KEYWORD2 31 | getScreenConstraint_Y KEYWORD2 32 | close KEYWORD2 33 | open KEYWORD2 34 | blink KEYWORD2 35 | anim_confused KEYWORD2 36 | anim_laugh KEYWORD2 37 | drawEyes KEYWORD2 38 | 39 | ####################################### 40 | # Constants and Literals (LITERAL1) 41 | ####################################### 42 | DEFAULT LITERAL1 43 | TIRED LITERAL1 44 | ANGRY LITERAL1 45 | HAPPY LITERAL1 46 | ON LITERAL1 47 | OFF LITERAL1 48 | N LITERAL1 49 | NE LITERAL1 50 | E LITERAL1 51 | SE LITERAL1 52 | S LITERAL1 53 | SW LITERAL1 54 | W LITERAL1 55 | NW LITERAL1 56 | -------------------------------------------------------------------------------- /examples/i2c_SSD1306_SensorPlayground/i2c_SSD1306_SensorPlayground.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to read an LDR sensor (also called photoresistor) 3 | // to open the RoboEyes when it's bright and close the eyes in the dark. 4 | // Check the dedicated Youtube short: 5 | // https://youtube.com/shorts/vDrkL4PK0HA?feature=share 6 | // 7 | // Parts needed: 8 | // - Micro controller, e.g. ESP32 C3 Supermini or other Arduino compatible board 9 | // - Oled display, SSD1306 10 | // - LDR, such as the GL5528 11 | // - Fixed resistor, 10 kΩ 12 | // - Jumper Wires 13 | // 14 | // Wiring: 15 | // 3.3V ----[ LDR ]---- A0 ----[ 10kΩ Resistor ]---- GND 16 | // 17 | // Published in August 2025 by Dennis Hoelscher, FluxGarage 18 | // www.youtube.com/@FluxGarage 19 | // www.fluxgarage.com 20 | // 21 | //*********************************************************************************************** 22 | 23 | // Display Driver 24 | #include 25 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 26 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 27 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 28 | #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 29 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 30 | 31 | // RoboEyes 32 | #include 33 | RoboEyes roboEyes(display); // create RoboEyes instance 34 | 35 | 36 | void setup() { 37 | // Startup Serial 38 | Serial.begin(115200); 39 | 40 | // Startup OLED Display 41 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 42 | if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C or 0x3D 43 | Serial.println(F("SSD1306 allocation failed")); 44 | for(;;); // Don't proceed, loop forever 45 | } 46 | 47 | // Startup robo eyes 48 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); 49 | roboEyes.setPosition(DEFAULT); 50 | } 51 | 52 | 53 | void loop() { 54 | readLDR(A0, 3200); // read LDR sensor at pin A0 and define threshold 55 | roboEyes.update(); // update eyes drawings 56 | } 57 | 58 | 59 | 60 | // READ LDR SENSOR / PHOTO RESISTOR 61 | void readLDR(int ldrPin, int ldrThreshold) { 62 | int ldrValue = analogRead(ldrPin); 63 | Serial.println(ldrValue); 64 | if (ldrValue > ldrThreshold) { 65 | roboEyes.open(); // Open the eyes if it's brighter than the threshold 66 | } 67 | else { 68 | roboEyes.close(); // Close the eyes if it's darker than the threshold 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/i2c_SSD1306_AnimationSequences/i2c_SSD1306_AnimationSequences.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to create Robo Eyes animation sequences without the use of delay(); 3 | // 4 | // Hardware: You'll need a breadboard, an arduino nano r3, an I2C oled display with 1306 5 | // or 1309 chip and some jumper wires. 6 | // 7 | // Published in September 2024 by Dennis Hoelscher, FluxGarage 8 | // www.youtube.com/@FluxGarage 9 | // www.fluxgarage.com 10 | // 11 | //*********************************************************************************************** 12 | 13 | 14 | #include 15 | 16 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 17 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 18 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 19 | #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 20 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 21 | 22 | #include 23 | // create a RoboEyes instance using an Adafruit_SSD1306 display driver 24 | RoboEyes roboEyes(display); 25 | 26 | 27 | // EVENT TIMER 28 | unsigned long eventTimer; // will save the timestamps 29 | bool event1wasPlayed = 0; // flag variables 30 | bool event2wasPlayed = 0; 31 | bool event3wasPlayed = 0; 32 | 33 | 34 | void setup() { 35 | // OLED Display 36 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 37 | if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C or 0x3D 38 | Serial.println(F("SSD1306 allocation failed")); 39 | for(;;); // Don't proceed, loop forever 40 | } 41 | 42 | // Startup robo eyes 43 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate - 60-100fps are good for smooth animations 44 | roboEyes.setPosition(DEFAULT); // eye position should be middle center 45 | roboEyes.close(); // start with closed eyes 46 | 47 | eventTimer = millis(); // start event timer from here 48 | 49 | } // end of setup 50 | 51 | 52 | void loop() { 53 | roboEyes.update(); // update eyes drawings 54 | 55 | // LOOPED ANIMATION SEQUENCE 56 | // Do once after defined number of milliseconds 57 | if(millis() >= eventTimer+2000 && event1wasPlayed == 0){ 58 | event1wasPlayed = 1; // flag variable to make sure the event will only be handled once 59 | roboEyes.open(); // open eyes 60 | } 61 | // Do once after defined number of milliseconds 62 | if(millis() >= eventTimer+4000 && event2wasPlayed == 0){ 63 | event2wasPlayed = 1; // flag variable to make sure the event will only be handled once 64 | roboEyes.setMood(HAPPY); 65 | roboEyes.anim_laugh(); 66 | //roboEyes.anim_confused(); 67 | } 68 | // Do once after defined number of milliseconds 69 | if(millis() >= eventTimer+6000 && event3wasPlayed == 0){ 70 | event3wasPlayed = 1; // flag variable to make sure the event will only be handled once 71 | roboEyes.setMood(TIRED); 72 | //roboEyes.blink(); 73 | } 74 | // Do once after defined number of milliseconds, then reset timer and flags to restart the whole animation sequence 75 | if(millis() >= eventTimer+8000){ 76 | roboEyes.close(); // close eyes again 77 | roboEyes.setMood(DEFAULT); 78 | // Reset the timer and the event flags to restart the whole "complex animation loop" 79 | eventTimer = millis(); // reset timer 80 | event1wasPlayed = 0; // reset flags 81 | event2wasPlayed = 0; 82 | event3wasPlayed = 0; 83 | } 84 | // END OF LOOPED ANIMATION SEQUENCE 85 | 86 | } // end of main loop 87 | -------------------------------------------------------------------------------- /examples/i2c_SSD1306_Basics/i2c_SSD1306_Basics.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to use the basic methods of the FluxGarage Robo Eyes library. 3 | // 4 | // Hardware: You'll need a breadboard, an arduino nano r3, an I2C oled display with 1306 5 | // or 1309 chip and some jumper wires. 6 | // 7 | // Published in September 2024 by Dennis Hoelscher, FluxGarage 8 | // www.youtube.com/@FluxGarage 9 | // www.fluxgarage.com 10 | // 11 | //*********************************************************************************************** 12 | 13 | 14 | #include 15 | #include 16 | 17 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 18 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 19 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 20 | #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 21 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 22 | 23 | // create a RoboEyes instance using an Adafruit_SSD1306 display driver 24 | RoboEyes roboEyes(display); 25 | 26 | 27 | void setup() { 28 | Serial.begin(9600); 29 | 30 | // Startup OLED Display 31 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 32 | if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C or 0x3D 33 | Serial.println(F("SSD1306 allocation failed")); 34 | for(;;); // Don't proceed, loop forever 35 | } 36 | 37 | // Startup robo eyes 38 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate 39 | 40 | // Define some automated eyes behaviour 41 | roboEyes.setAutoblinker(ON, 3, 2); // Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds 42 | roboEyes.setIdleMode(ON, 2, 2); // Start idle animation cycle (eyes looking in random directions) -> turn on/off, set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds 43 | 44 | // Define eye shapes, all values in pixels 45 | //roboEyes.setWidth(36, 36); // byte leftEye, byte rightEye 46 | //roboEyes.setHeight(36, 36); // byte leftEye, byte rightEye 47 | //roboEyes.setBorderradius(8, 8); // byte leftEye, byte rightEye 48 | //roboEyes.setSpacebetween(10); // int space -> can also be negative 49 | 50 | // Cyclops mode 51 | //roboEyes.setCyclops(ON); // bool on/off -> if turned on, robot has only on eye 52 | 53 | // Define mood, curiosity and position 54 | //roboEyes.setMood(DEFAULT); // mood expressions, can be TIRED, ANGRY, HAPPY, DEFAULT 55 | //roboEyes.setPosition(DEFAULT); // cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered) 56 | //roboEyes.setCuriosity(ON); // bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right 57 | 58 | // Set horizontal or vertical flickering 59 | //roboEyes.setHFlicker(ON, 2); // bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels 60 | //roboEyes.setVFlicker(ON, 2); // bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels 61 | 62 | // Play prebuilt oneshot animations 63 | //roboEyes.anim_confused(); // confused - eyes shaking left and right 64 | //roboEyes.anim_laugh(); // laughing - eyes shaking up and down 65 | 66 | } // end of setup 67 | 68 | 69 | void loop() { 70 | roboEyes.update(); // update eyes drawings 71 | // Dont' use delay() here in order to ensure fluid eyes animations. 72 | // Check the AnimationSequences example for common practices. 73 | } 74 | -------------------------------------------------------------------------------- /examples/spi_SSD1306_AnimationSequences/spi_SSD1306_AnimationSequences.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to create Robo Eyes animation sequences without the use of delay(); 3 | // 4 | // Hardware: You'll need a breadboard, an arduino nano r3, an SPI oled display with 1306 5 | // or 1309 chip and some jumper wires. 6 | // 7 | // Published in September 2024 by Dennis Hoelscher, FluxGarage 8 | // www.youtube.com/@FluxGarage 9 | // www.fluxgarage.com 10 | // 11 | //*********************************************************************************************** 12 | 13 | 14 | #include 15 | 16 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 17 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 18 | // Declaration for SSD1306 display connected using software SPI (default case): 19 | #define OLED_MOSI 9 20 | #define OLED_CLK 10 21 | #define OLED_DC 11 22 | #define OLED_CS 12 23 | #define OLED_RESET 13 24 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, 25 | OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 26 | 27 | /* Comment out above, uncomment this block to use hardware SPI 28 | #define OLED_DC 11 29 | #define OLED_CS 12 30 | #define OLED_RESET 13 31 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, 32 | &SPI, OLED_DC, OLED_RESET, OLED_CS); 33 | */ 34 | 35 | #include 36 | RoboEyes roboEyes(display); // create RoboEyes instance 37 | 38 | // EVENT TIMER 39 | unsigned long eventTimer; // will save the timestamps 40 | bool event0wasPlayed = 0; // flag variables 41 | bool event1wasPlayed = 0; 42 | bool event2wasPlayed = 0; 43 | bool event3wasPlayed = 0; 44 | 45 | 46 | void setup() { 47 | // Startup OLED Display 48 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 49 | if(!display.begin(SSD1306_SWITCHCAPVCC)) { 50 | Serial.println(F("SSD1306 allocation failed")); 51 | for(;;); // Don't proceed, loop forever 52 | } 53 | 54 | // Startup robo eyes 55 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate - 60-100fps are good for smooth animations 56 | roboEyes.setPosition(DEFAULT); // eye position should be middle center 57 | roboEyes.close(); // start with closed eyes 58 | 59 | eventTimer = millis(); // start event timer from here 60 | 61 | } // end of setup 62 | 63 | 64 | void loop() { 65 | roboEyes.update(); // update eyes drawings 66 | 67 | // LOOPED ANIMATION SEQUENCE 68 | // Do once after defined number of milliseconds 69 | if(millis() >= eventTimer+2000 && event1wasPlayed == 0){ 70 | event1wasPlayed = 1; // flag variable to make sure the event will only be handled once 71 | roboEyes.open(); // open eyes 72 | } 73 | // Do once after defined number of milliseconds 74 | if(millis() >= eventTimer+4000 && event2wasPlayed == 0){ 75 | event2wasPlayed = 1; // flag variable to make sure the event will only be handled once 76 | roboEyes.setMood(HAPPY); 77 | roboEyes.anim_laugh(); 78 | //roboEyes.anim_confused(); 79 | } 80 | // Do once after defined number of milliseconds 81 | if(millis() >= eventTimer+6000 && event3wasPlayed == 0){ 82 | event3wasPlayed = 1; // flag variable to make sure the event will only be handled once 83 | roboEyes.setMood(TIRED); 84 | //roboEyes.blink(); 85 | } 86 | // Do once after defined number of milliseconds, then reset timer and flags to restart the whole animation sequence 87 | if(millis() >= eventTimer+8000){ 88 | roboEyes.close(); // close eyes again 89 | roboEyes.setMood(DEFAULT); 90 | // Reset the timer and the event flags to restart the whole "complex animation loop" 91 | eventTimer = millis(); // reset timer 92 | event1wasPlayed = 0; // reset flags 93 | event2wasPlayed = 0; 94 | event3wasPlayed = 0; 95 | } 96 | // END OF LOOPED ANIMATION SEQUENCE 97 | 98 | } // end of main loop 99 | -------------------------------------------------------------------------------- /examples/spi_SSD1322_Basics/spi_SSD1322_Basics.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to use the basic methods of the FluxGarage Robo Eyes library. 3 | // 4 | // Hardware: You'll need a breadboard, a micro controller such as ESP32, an SPI oled display 5 | // with 1322 chip and some jumper wires. 6 | // 7 | // Published in may 2025 by Dennis Hoelscher, FluxGarage 8 | // www.youtube.com/@FluxGarage 9 | // www.fluxgarage.com 10 | // 11 | //*********************************************************************************************** 12 | 13 | #include // -> Display driver, download here: https://github.com/venice1200/SSD1322_for_Adafruit_GFX 14 | 15 | // Used for software SPI 16 | #define OLED_CLK 4 17 | #define OLED_MOSI 6 18 | 19 | // Used for software or hardware SPI 20 | #define OLED_CS 7 21 | #define OLED_DC 9 22 | 23 | // Used for I2C or SPI 24 | #define OLED_RESET 8 25 | 26 | // hardware SPI 27 | Adafruit_SSD1322 display(256, 64, &SPI, OLED_DC, OLED_RESET, OLED_CS); 28 | 29 | #include 30 | RoboEyes roboEyes(display); // create RoboEyes instance 31 | #define SCREEN_WIDTH 256 // OLED display width, in pixels 32 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 33 | 34 | 35 | void setup() { 36 | Serial.begin(9600); 37 | //while (! Serial) delay(100); 38 | Serial.println("SSD1327 OLED test"); 39 | 40 | if ( ! display.begin(0x3D) ) { 41 | Serial.println("Unable to initialize OLED"); 42 | while (1) yield(); 43 | } 44 | 45 | // Startup robo eyes 46 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate 47 | roboEyes.setDisplayColors(0x00, 0x0F); // Most dark/bright values for grayscale oleds, such as the SSD1322 48 | 49 | // Define some automated eyes behaviour 50 | roboEyes.setAutoblinker(ON, 3, 2); // Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds 51 | roboEyes.setIdleMode(ON, 2, 2); // Start idle animation cycle (eyes looking in random directions) -> turn on/off, set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds 52 | 53 | // Define eye shapes, all values in pixels 54 | //roboEyes.setWidth(36, 36); // byte leftEye, byte rightEye 55 | //roboEyes.setHeight(36, 36); // byte leftEye, byte rightEye 56 | //roboEyes.setBorderradius(8, 8); // byte leftEye, byte rightEye 57 | //roboEyes.setSpacebetween(10); // int space -> can also be negative 58 | 59 | // Cyclops mode 60 | //roboEyes.setCyclops(ON); // bool on/off -> if turned on, robot has only on eye 61 | 62 | // Define mood, curiosity and position 63 | //roboEyes.setMood(DEFAULT); // mood expressions, can be TIRED, ANGRY, HAPPY, DEFAULT 64 | //roboEyes.setPosition(DEFAULT); // cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered) 65 | //roboEyes.setCuriosity(ON); // bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right 66 | 67 | // Set horizontal or vertical flickering 68 | //roboEyes.setHFlicker(ON, 2); // bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels 69 | //roboEyes.setVFlicker(ON, 2); // bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels 70 | 71 | // Play prebuilt oneshot animations 72 | //roboEyes.anim_confused(); // confused - eyes shaking left and right 73 | //roboEyes.anim_laugh(); // laughing - eyes shaking up and down 74 | 75 | } // end of setup 76 | 77 | 78 | void loop() { 79 | roboEyes.update(); // update eyes drawings 80 | // Dont' use delay() here in order to ensure fluid eyes animations. 81 | // Check the AnimationSequences example for common practices. 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/spi_SSD1306_Basics/spi_SSD1306_Basics.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to use the basic methods of the FluxGarage Robo Eyes library. 3 | // 4 | // Hardware: You'll need a breadboard, an arduino nano r3, an SPI oled display with 1306 5 | // or 1309 chip and some jumper wires. 6 | // 7 | // Published in September 2024 by Dennis Hoelscher, FluxGarage 8 | // www.youtube.com/@FluxGarage 9 | // www.fluxgarage.com 10 | // 11 | //*********************************************************************************************** 12 | 13 | 14 | #include 15 | 16 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 17 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 18 | // Declaration for SSD1306 display connected using software SPI (default case): 19 | #define OLED_MOSI 9 20 | #define OLED_CLK 10 21 | #define OLED_DC 11 22 | #define OLED_CS 12 23 | #define OLED_RESET 13 24 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, 25 | OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 26 | 27 | /* Comment out above, uncomment this block to use hardware SPI 28 | #define OLED_DC 11 29 | #define OLED_CS 12 30 | #define OLED_RESET 13 31 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, 32 | &SPI, OLED_DC, OLED_RESET, OLED_CS); 33 | */ 34 | 35 | #include 36 | RoboEyes roboEyes(display); // create RoboEyes instance 37 | 38 | 39 | void setup() { 40 | // Startup OLED Display 41 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 42 | if(!display.begin(SSD1306_SWITCHCAPVCC)) { 43 | Serial.println(F("SSD1306 allocation failed")); 44 | for(;;); // Don't proceed, loop forever 45 | } 46 | 47 | // Startup robo eyes 48 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate 49 | 50 | // Define some automated eyes behaviour 51 | roboEyes.setAutoblinker(ON, 3, 2); // Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds 52 | roboEyes.setIdleMode(ON, 2, 2); // Start idle animation cycle (eyes looking in random directions) -> turn on/off, set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds 53 | 54 | // Define eye shapes, all values in pixels 55 | //roboEyes.setWidth(36, 36); // byte leftEye, byte rightEye 56 | //roboEyes.setHeight(36, 36); // byte leftEye, byte rightEye 57 | //roboEyes.setBorderradius(8, 8); // byte leftEye, byte rightEye 58 | //roboEyes.setSpacebetween(10); // int space -> can also be negative 59 | 60 | // Cyclops mode 61 | //roboEyes.setCyclops(ON); // bool on/off -> if turned on, robot has only on eye 62 | 63 | // Define mood, curiosity and position 64 | //roboEyes.setMood(DEFAULT); // mood expressions, can be TIRED, ANGRY, HAPPY, DEFAULT 65 | //roboEyes.setPosition(DEFAULT); // cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered) 66 | //roboEyes.setCuriosity(ON); // bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right 67 | 68 | // Set horizontal or vertical flickering 69 | //roboEyes.setHFlicker(ON, 2); // bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels 70 | //roboEyes.setVFlicker(ON, 2); // bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels 71 | 72 | // Play prebuilt oneshot animations 73 | //roboEyes.anim_confused(); // confused - eyes shaking left and right 74 | //roboEyes.anim_laugh(); // laughing - eyes shaking up and down 75 | 76 | } // end of setup 77 | 78 | 79 | void loop() { 80 | roboEyes.update(); // update eyes drawings 81 | // Dont' use delay() here in order to ensure fluid eyes animations. 82 | // Check the AnimationSequences example for common practices. 83 | } 84 | 85 | -------------------------------------------------------------------------------- /examples/i2c_SH1106_Basics/i2c_SH1106_Basics.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // This example shows how to use the basic methods of the FluxGarage Robo Eyes library. 3 | // 4 | // Hardware: You'll need a breadboard, a microcontroller such as arduino nano v3 or better an esp32, 5 | // an I2C oled display with sh1106 chip and some jumper wires. 6 | // 7 | // Use the dedicated I2C pins of your microcontroller, on ESP32-WROOM-32 module use pin 22 for SCL and pin 21 for SDA. 8 | // Please note: This example turned out to have slow refresh rates on Arduino Uno. Did not find a fix yet. 9 | // 10 | // Published in January 2025 by Dennis Hoelscher, FluxGarage 11 | // www.youtube.com/@FluxGarage 12 | // www.fluxgarage.com 13 | // 14 | //*********************************************************************************************** 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/ 22 | #define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's 23 | //#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's 24 | 25 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 26 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 27 | #define OLED_RESET -1 // QT-PY / XIAO 28 | Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 29 | 30 | #include 31 | RoboEyes roboEyes(display); // create RoboEyes instance 32 | 33 | 34 | void setup() { 35 | Serial.begin(9600); 36 | 37 | delay(250); // wait for the OLED to power up 38 | display.begin(i2c_Address, true); // Address 0x3C default 39 | //display.setContrast (0); // dim display 40 | 41 | // Startup robo eyes 42 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate 43 | 44 | // Define some automated eyes behaviour 45 | roboEyes.setAutoblinker(ON, 3, 2); // Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds 46 | roboEyes.setIdleMode(ON, 2, 2); // Start idle animation cycle (eyes looking in random directions) -> turn on/off, set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds 47 | 48 | // Define eye shapes, all values in pixels 49 | //roboEyes.setWidth(36, 36); // byte leftEye, byte rightEye 50 | //roboEyes.setHeight(36, 36); // byte leftEye, byte rightEye 51 | //roboEyes.setBorderradius(8, 8); // byte leftEye, byte rightEye 52 | //roboEyes.setSpacebetween(10); // int space -> can also be negative 53 | 54 | // Cyclops mode 55 | //roboEyes.setCyclops(ON); // bool on/off -> if turned on, robot has only on eye 56 | 57 | // Define mood, curiosity and position 58 | //roboEyes.setMood(DEFAULT); // mood expressions, can be TIRED, ANGRY, HAPPY, DEFAULT 59 | //roboEyes.setPosition(DEFAULT); // cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered) 60 | //roboEyes.setCuriosity(ON); // bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right 61 | 62 | // Set horizontal or vertical flickering 63 | //roboEyes.setHFlicker(ON, 2); // bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels 64 | //roboEyes.setVFlicker(ON, 2); // bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels 65 | 66 | // Play prebuilt oneshot animations 67 | //roboEyes.anim_confused(); // confused - eyes shaking left and right 68 | //roboEyes.anim_laugh(); // laughing - eyes shaking up and down 69 | 70 | } // end of setup 71 | 72 | 73 | void loop() { 74 | roboEyes.update(); // update eyes drawings 75 | // Dont' use delay() here in order to ensure fluid eyes animations. 76 | // Check the AnimationSequences example for common practices. 77 | } 78 | 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FluxGarage RoboEyes Library 2 | 3 | Draws smoothly animated robot eyes on OLED displays, using the Adafruit GFX library. Robot eye shapes are configurable in terms of width, height, border radius and space between. Several different mood expressions (happy, tired, angry, default) and animations (autoblinker, idle, laughing, confused) are available. All state changes have smooth transitions and thus, complex animation sequences are easily feasible. 4 | 5 | Developing this library was the first step of a larger project: the creation of my own DIY robot from the design perspective. Check out the [FluxGarage Youtube Channel](https://www.youtube.com/@FluxGarage). 6 | 7 | 8 | ## Watch the Demo and Getting Started Videos on Youtube 9 | 10 | [![#1 - Smoothly Animated Robot Eyes on OLED Displays with the Robo Eyes Library](https://img.youtube.com/vi/ibSaDEkfUOI/0.jpg)](https://www.youtube.com/watch?v=ibSaDEkfUOI) 11 | [![#2 - Getting Started With the Free Robo Eyes Arduino Library](https://img.youtube.com/vi/WtLWc5zzrmI/0.jpg)](https://www.youtube.com/watch?v=WtLWc5zzrmI) 12 | 13 | 14 | ## Installation 15 | 16 | 1. Navigate to [github.com/FluxGarage/RoboEyes](https://github.com/FluxGarage/RoboEyes). 17 | 2. Choose "Code > Download Zip" 18 | 3. In the Arduino IDE, navigate to "Sketch > Include Library > Add .ZIP Library" and select the downloaded file 19 | 20 | 21 | ## Functions 22 | 23 | ### General 24 | - **begin()** _(screen-width, screen-height, max framerate)_ 25 | - **update()** _update eyes drawings in the main loop, limited by max framerate as defined in begin()_ 26 | - **drawEyes()** _same as update(), but without the framerate limitation_ 27 | - **setDisplayColors()** _(uint8_t background, uint8_t main)_ 28 | -> background: background and overlays, choose 0 for monochrome displays and 0x00 for grayscale displays such as SSD1322 29 | -> main: drawings, choose 1 for monochrome displays and 0x0F for grayscale displays such as SSD1322 (0x0F = maximum brightness) 30 | 31 | ### Define Eye Shapes, all values in pixels 32 | - **setWidth()** _(byte leftEye, byte rightEye)_ 33 | - **setHeight()** _(byte leftEye, byte rightEye)_ 34 | - **setBorderradius()** _(byte leftEye, byte rightEye)_ 35 | - **setSpacebetween()** _(int space) -> can also be negative_ 36 | - **setCyclops()** _(bool ON/OFF) -> if turned ON, robot has only on eye_ 37 | 38 | ### Define Face Expressions (Mood, Curiosity, Eye-Position, Open/Close) 39 | - **setMood()** _mood expression, can be TIRED, ANGRY, HAPPY, DEFAULT_ 40 | - **setPosition()** _cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered)_ 41 | - **setCuriosity()** _(bool ON/OFF) -> when turned on, height of the outer eyes increases when moving to the very left or very right_ 42 | - **setSweat()** _(bool ON/OFF) -> when turned on, animated sweat drops appear in the upper screen area_ 43 | - **open()** _open both eyes -> open(1,0) opens left eye only_ 44 | - **close()** _close both eyes -> close(1,0) closes left eye only_ 45 | 46 | ### Set Horizontal and/or Vertical Flicker 47 | Alternately displaces the eyes in the defined amplitude in pixels: 48 | - **setHFlicker()** _(bool ON/OFF, byte amplitude)_ 49 | - **setVFlicker()** _(bool ON/OFF, byte amplitude)_ 50 | 51 | ### Play Prebuilt Oneshot Animations 52 | - **anim_confused()** _confused -> eyes shaking left and right_ 53 | - **anim_laugh()** _laughing -> eyes shaking up and down_ 54 | - **blink()** _close and open both eyes_ 55 | - **blink(0,1)** _close and open right eye_ 56 | 57 | ### Macro Animators 58 | Blinks both eyes randomly: 59 | - **setAutoblinker()** _(bool ON/OFF, int interval, int variation) -> turn on/off, set interval between each blink in full seconds, set range for additional random interval variation in full seconds_ 60 | 61 | Repositions both eyes randomly: 62 | - **setIdleMode()** _(bool ON/OFF, int interval, int variation) -> turn on/off, set interval between each eye repositioning in full seconds, set range for additional random interval variation in full seconds_ 63 | 64 | ### Further (Inofficial) Resources by Other Users 65 | - micropython-roboeyes by mchobby: https://github.com/mchobby/micropython-roboeyes 66 | - RoboEyes Micropython Edition by Youssef Tech: https://github.com/yousseftechdev/RoboEyes-Micropython 67 | - RoboEyes for TFT displays by Youssef Tech: https://github.com/yousseftechdev/RoboEyesTFT 68 | - MQTT control system by teletoby-swctv: https://github.com/teletoby-swctv/FluxGarage-RoboEyes-MQTT 69 | 70 | -------------------------------------------------------------------------------- /examples/i2c_SSD1306_DHT22-TemperatureSensor/i2c_SSD1306_DHT22-TemperatureSensor.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | // REQUIRES the following Arduino libraries: 5 | // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library 6 | // - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor 7 | 8 | //*********************************************************************************************** 9 | // Adafruit's example has been extended for being used with the FluxGarage RoboEyes, 10 | // showing different robot face expressions and animations in relation to the temperature 11 | // variable "t". Beside the DHT22 sensor, add an I2C SSD1306 OLED display to get started. 12 | // Check the dedicated Youtube short: https://youtube.com/shorts/xLKj-iLbz8U 13 | // 14 | // Published in August 2025 by Dennis Hoelscher, FluxGarage 15 | // www.youtube.com/@FluxGarage 16 | // www.fluxgarage.com 17 | // 18 | //*********************************************************************************************** 19 | 20 | #include "DHT.h" 21 | 22 | #define DHTPIN 2 // Digital pin connected to the DHT sensor 23 | // Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- 24 | // Pin 15 can work but DHT must be disconnected during program upload. 25 | 26 | // Uncomment whatever type you're using! 27 | //#define DHTTYPE DHT11 // DHT 11 28 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 29 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 30 | 31 | // Connect pin 1 (on the left) of the sensor to +5V 32 | // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 33 | // to 3.3V instead of 5V! 34 | // Connect pin 2 of the sensor to whatever your DHTPIN is 35 | // Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins) 36 | // Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins) 37 | // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 38 | 39 | // Initialize DHT sensor. 40 | // Note that older versions of this library took an optional third parameter to 41 | // tweak the timings for faster processors. This parameter is no longer needed 42 | // as the current DHT reading algorithm adjusts itself to work on faster procs. 43 | DHT dht(DHTPIN, DHTTYPE); 44 | 45 | 46 | #include 47 | 48 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 49 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 50 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 51 | #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 52 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 53 | 54 | #include // https://github.com/FluxGarage/RoboEyes 55 | RoboEyes roboEyes(display); // create RoboEyes instance 56 | 57 | // EVENT TIMER 58 | unsigned long eventTimer; // will save the timestamps 59 | 60 | void setup() { 61 | Serial.begin(9600); 62 | 63 | // Startup OLED Display 64 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 65 | if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C or 0x3D 66 | Serial.println(F("SSD1306 allocation failed")); 67 | for(;;); // Don't proceed, loop forever 68 | } 69 | 70 | // Startup dht sensor lib 71 | dht.begin(); 72 | //Serial.println(F("DHTxx test!")); 73 | 74 | // Startup robo eyes 75 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate 76 | roboEyes.setPosition(DEFAULT); // eye position should be middle center 77 | roboEyes.setAutoblinker(ON, 3, 2); // start auto blinker 78 | 79 | display.setRotation(2); // Rotate the display by 180 degrees - this makes sense if your display is mounted upside down 80 | 81 | eventTimer = millis(); // start event timer from here 82 | 83 | } 84 | 85 | void loop() { 86 | roboEyes.update(); // update eyes drawings 87 | // dont' use delay() here in order to ensure fluid eyes animations 88 | 89 | // Measure temperature every 5 seconds 90 | if(millis() >= eventTimer+5000){ 91 | // Reading temperature or humidity takes about 250 milliseconds! 92 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 93 | float h = dht.readHumidity(); 94 | // Read temperature as Celsius (the default) 95 | float t = dht.readTemperature(); 96 | // Read temperature as Fahrenheit (isFahrenheit = true) 97 | float f = dht.readTemperature(true); 98 | 99 | // Check if any reads failed and exit early (to try again). 100 | if (isnan(h) || isnan(t) || isnan(f)) { 101 | Serial.println(F("Failed to read from DHT sensor!")); 102 | return; 103 | } 104 | 105 | // Compute heat index in Fahrenheit (the default) 106 | float hif = dht.computeHeatIndex(f, h); 107 | // Compute heat index in Celsius (isFahreheit = false) 108 | float hic = dht.computeHeatIndex(t, h, false); 109 | 110 | /*Serial.print(F("Humidity: ")); 111 | Serial.print(h); 112 | Serial.print(F("% Temperature: ")); 113 | Serial.print(t); 114 | Serial.print(F("°C ")); 115 | Serial.print(f); 116 | Serial.print(F("°F Heat index: ")); 117 | Serial.print(hic); 118 | Serial.print(F("°C ")); 119 | Serial.print(hif); 120 | Serial.println(F("°F")); 121 | */ 122 | Serial.println(t); 123 | 124 | if (t < 15){ 125 | // Robot is freezing if temperature is below 15° Celsius 126 | roboEyes.setMood(TIRED); 127 | roboEyes.setHFlicker(ON, 2); 128 | } 129 | else if (t > 25){ 130 | // Robot is sweating if temperature is above 25° Celsius 131 | roboEyes.setMood(TIRED); 132 | roboEyes.setSweat(ON); 133 | roboEyes.setPosition(S); 134 | } 135 | else { 136 | // Robot's comfort zone: temperature is between 15° and 25° Celsius 137 | roboEyes.setMood(DEFAULT); // neutral face expression 138 | roboEyes.setPosition(DEFAULT); // eye position: middle center 139 | roboEyes.setHFlicker(OFF); 140 | roboEyes.setSweat(OFF); 141 | } 142 | 143 | eventTimer = millis(); // reset timer 144 | } 145 | } // end of main loop 146 | 147 | -------------------------------------------------------------------------------- /examples/i2c_SSD1306_ConfigurationBoard/i2c_SSD1306_ConfigurationBoard.ino: -------------------------------------------------------------------------------- 1 | //*********************************************************************************************** 2 | // Code for the Robo Eyes configuration board as shown in the first video: 3 | // https://youtu.be/ibSaDEkfUOI 4 | // 5 | // The configuration board enables you to configure your preferred eye shapes and play around 6 | // with the library's mood types and animations - you just need a breadboard, an arduino nano, 7 | // some pushbuttons, jumper wires and optionally a joystick module. Find the instructions here: 8 | // http://www.instructables.com/member/FluxGarage/ 9 | // 10 | // Published in September 2024 by Dennis Hoelscher, FluxGarage 11 | // www.youtube.com/@FluxGarage 12 | // www.fluxgarage.com 13 | // 14 | //*********************************************************************************************** 15 | 16 | #include 17 | 18 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 19 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 20 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 21 | #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 22 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 23 | 24 | #include 25 | RoboEyes roboEyes(display); 26 | 27 | #include // Pushbutton library by Pololu, can be found in the Arduino library manager 28 | 29 | // Create buttons and define their pins 30 | Pushbutton buttonMood(5); // Change mood types 31 | Pushbutton buttonLaugh(6); // Trigger laugh animation 32 | Pushbutton buttonConfused(7); // Trigger confused animation 33 | Pushbutton buttonFlicker(8); // Toggle flicker animation 34 | Pushbutton buttonConfigMode(9); // Configuration mode 35 | Pushbutton buttonIncrement(10); // Configuration increment 36 | Pushbutton buttonDecrement(11); // Configuration decrement 37 | Pushbutton buttonJoystick(12); // Joystick button - switch between idle mode (automatic random eye positions) and joystick mode (manual control of eye positions with joystick) 38 | 39 | // Joystick pins 40 | int joystickXpin = A0; 41 | int joystickYpin = A1; 42 | // For toggling the reading of the joystick 43 | bool joystickToggle = 0; 44 | 45 | // For setting mood expression and eye position 46 | byte mood = 0; // Mood switch 47 | byte position = 0; // Position switch 48 | 49 | // Name aliases for different config mode states 50 | #define EYES_WIDTHS 0 51 | #define EYES_HEIGHTS 1 52 | #define EYES_BORDERRADIUS 2 53 | #define EYES_SPACEBETWEEN 3 54 | #define CYCLOPS_TOGGLE 4 55 | #define CURIOUS_TOGGLE 5 56 | #define PREDEFINED_POSITIONS 6 57 | byte configMode = 6; // for saving current config mode state 58 | bool showConfigMode = 0; // for showing current config mode on display 59 | unsigned long showConfigModeTimer = 0; 60 | int showConfigModeDuration = 1500; // how long should the current config mode headline be displayed? 61 | 62 | 63 | void setup() { 64 | 65 | //Serial.begin(9600); // Serial might not work properly, probably due to exhausted memory capacity when using ATMEGA328P based boards 66 | 67 | // Initialize OLED display 68 | // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 69 | if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C or 0x3D 70 | //Serial.println(F("SSD1306 allocation failed")); 71 | for(;;); // Don't proceed, loop forever 72 | } 73 | 74 | // Startup robo eyes 75 | roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate 76 | roboEyes.close(); // start with closed eyes 77 | roboEyes.setPosition(DEFAULT); // eyes should be initially centered 78 | 79 | // Define eyes behaviour for demonstration 80 | roboEyes.setAutoblinker(ON, 3, 2); // Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds 81 | roboEyes.setIdleMode(ON, 3, 1); // Start idle animation cycle (eyes looking in random directions) -> set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds 82 | 83 | //display.invertDisplay(true); // show inverted display colors (black eyes on bright background) 84 | 85 | } // end of setup 86 | 87 | 88 | void loop() { 89 | if (!showConfigMode){ 90 | roboEyes.update(); // Updates eye drawings limited by max framerate (good for fast controllers to limit animation speed). 91 | // If you want to use the full horsepower of your controller without limits, you can use drawEyes(); instead. 92 | } else { 93 | // Show current config mode headline in display 94 | display.clearDisplay(); // clear screen 95 | // Basic text setup for displaying config mode headlines 96 | display.setTextSize(2); 97 | display.setTextColor(WHITE); 98 | display.setCursor(0,3); 99 | if(configMode == EYES_WIDTHS){ 100 | display.println("Widths"); 101 | display.println(roboEyes.eyeLwidthCurrent); 102 | } 103 | else if(configMode == EYES_HEIGHTS){ 104 | display.println("Heights"); 105 | display.println(roboEyes.eyeLheightCurrent); 106 | } 107 | else if(configMode == EYES_BORDERRADIUS){ 108 | display.println("Border \nRadius"); 109 | display.println(roboEyes.eyeLborderRadiusCurrent); 110 | } 111 | else if(configMode == EYES_SPACEBETWEEN){ 112 | display.println("Space \nBetween"); 113 | display.println(roboEyes.spaceBetweenCurrent); 114 | } 115 | else if(configMode == CYCLOPS_TOGGLE){ 116 | display.println("Cyclops \nToggle"); 117 | } 118 | else if(configMode == CURIOUS_TOGGLE){ 119 | display.println("Curiosity \nToggle"); 120 | } 121 | else if(configMode == PREDEFINED_POSITIONS){ 122 | display.println("Predefined\nPositions"); 123 | roboEyes.setIdleMode(0); // turn off idle mode 124 | roboEyes.setPosition(DEFAULT); // start with middle centered eyes 125 | } 126 | display.display(); // additionally show configMode on display 127 | if(millis() >= showConfigModeTimer+showConfigModeDuration){ 128 | showConfigMode = 0; // don't show the current config mode on the screen anymore 129 | } 130 | } 131 | 132 | readButtons(); 133 | 134 | if (joystickToggle){ 135 | readJoystick(); 136 | } 137 | 138 | } // end of main loop 139 | 140 | 141 | // Read joystick and map eye position accordingly 142 | void readJoystick(){ 143 | int joystickX = analogRead(joystickXpin); 144 | int joystickY = analogRead(joystickYpin); 145 | roboEyes.eyeLxNext = map(joystickX, 0, 1023, 0, roboEyes.getScreenConstraint_X() ); 146 | roboEyes.eyeLyNext = map(joystickY, 0, 1023, 0, roboEyes.getScreenConstraint_Y() ); 147 | } // end of readJoystick 148 | 149 | 150 | // Read all buttons 151 | void readButtons(){ 152 | // MOOD TYPES 153 | // choose between different mood type expressions 154 | if (buttonMood.getSingleDebouncedPress()){ 155 | if (mood<3){mood++;} else{mood=0;} 156 | if (mood==0){roboEyes.setMood(DEFAULT);} 157 | else if (mood==1){roboEyes.setMood(TIRED);} 158 | else if(mood==2){roboEyes.setMood(ANGRY);} 159 | else if(mood==3){roboEyes.setMood(HAPPY);} 160 | } 161 | 162 | // PLAY LAUGH ANIMATION 163 | if (buttonLaugh.getSingleDebouncedPress()){ 164 | roboEyes.anim_laugh(); // trigger animation "laugh" 165 | } 166 | 167 | // PLAY CONFUSED ANIMATION 168 | if (buttonConfused.getSingleDebouncedPress()){ 169 | roboEyes.anim_confused(); // trigger animation "confused" 170 | } 171 | 172 | // ADD HORIZONTAL FLICKER: TURN ON WHEN PRESSED, TURN OFF WHEN RELEASED 173 | if (buttonFlicker.getSingleDebouncedPress()){ 174 | roboEyes.setHFlicker(ON, 1); // bool flickerBit, byte Amplitude -> Turn on/off, set horizontal amplitude in px 175 | } 176 | if (buttonFlicker.getSingleDebouncedRelease()){ 177 | roboEyes.setHFlicker(OFF); // turn off 178 | } 179 | 180 | // EYES GEOMETRY CONFIGURATION 181 | if (buttonConfigMode.getSingleDebouncedPress()){ 182 | if(configMode<6){configMode++;} 183 | else {configMode=0;} 184 | showConfigMode = 1; 185 | showConfigModeTimer = millis(); 186 | } 187 | if (buttonIncrement.getSingleDebouncedPress()){ 188 | showConfigMode = 0; // don't show the current config mode on the screen anymore 189 | if(configMode == EYES_WIDTHS){roboEyes.eyeLwidthNext++; roboEyes.eyeRwidthNext++;} 190 | else if(configMode == EYES_HEIGHTS){roboEyes.eyeLheightNext++; roboEyes.eyeRheightNext++; roboEyes.eyeLheightDefault++; roboEyes.eyeRheightDefault++;} 191 | else if(configMode == EYES_BORDERRADIUS){ 192 | if(roboEyes.eyeLborderRadiusNext<50){roboEyes.eyeLborderRadiusNext++;} 193 | if(roboEyes.eyeRborderRadiusNext<50){roboEyes.eyeRborderRadiusNext++;} 194 | } 195 | else if(configMode == EYES_SPACEBETWEEN){roboEyes.spaceBetweenNext++;} 196 | else if(configMode == CYCLOPS_TOGGLE){roboEyes.setCyclops(OFF);} // no cyclops mode 197 | else if(configMode == CURIOUS_TOGGLE){roboEyes.setCuriosity(ON);} // curious mode 198 | else if(configMode == PREDEFINED_POSITIONS){ 199 | if (position<8){position++;} else{position=0;} 200 | updatePosition(); 201 | } 202 | } 203 | if (buttonDecrement.getSingleDebouncedPress()){ 204 | showConfigMode = 0; // don't show the current config mode on the screen anymore 205 | if(configMode == EYES_WIDTHS){roboEyes.eyeLwidthNext--; roboEyes.eyeRwidthNext--;} 206 | else if(configMode == EYES_HEIGHTS){roboEyes.eyeLheightNext--; roboEyes.eyeRheightNext--; roboEyes.eyeLheightDefault--; roboEyes.eyeRheightDefault--;} 207 | else if(configMode == EYES_BORDERRADIUS){ 208 | if(roboEyes.eyeLborderRadiusNext>0){roboEyes.eyeLborderRadiusNext--;} 209 | if(roboEyes.eyeRborderRadiusNext>0){roboEyes.eyeRborderRadiusNext--;} 210 | } 211 | else if(configMode == EYES_SPACEBETWEEN){roboEyes.spaceBetweenNext--;} 212 | else if(configMode == CYCLOPS_TOGGLE){roboEyes.setCyclops(ON);} // cyclops mode 213 | else if(configMode == CURIOUS_TOGGLE){roboEyes.setCuriosity(OFF);} // no curious mode 214 | else if(configMode == PREDEFINED_POSITIONS){ 215 | if (position>0){position--;} else{position=8;} 216 | updatePosition(); 217 | } 218 | } 219 | 220 | // JOYSTICK BUTTON 221 | // toggles between joystick controlled eye position and idle animation (eyes looking in random directions) 222 | if (buttonJoystick.getSingleDebouncedPress()){ 223 | joystickToggle = !joystickToggle; 224 | roboEyes.idle = !roboEyes.idle; 225 | } 226 | 227 | 228 | } // end of readButtons 229 | 230 | // Using predefined positions 231 | void updatePosition(){ 232 | if (position==0){roboEyes.setPosition(DEFAULT);} 233 | else if(position==1){roboEyes.setPosition(N);} 234 | else if(position==2){roboEyes.setPosition(NE);} 235 | else if(position==3){roboEyes.setPosition(E);} 236 | else if(position==4){roboEyes.setPosition(SE);} 237 | else if(position==5){roboEyes.setPosition(S);} 238 | else if(position==6){roboEyes.setPosition(SW);} 239 | else if(position==7){roboEyes.setPosition(W);} 240 | else if(position==8){roboEyes.setPosition(NW);} 241 | } // end of updatePosition 242 | 243 | -------------------------------------------------------------------------------- /src/FluxGarage_RoboEyes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FluxGarage RoboEyes for OLED Displays V 1.1.1 3 | * Draws smoothly animated robot eyes on OLED displays, based on the Adafruit GFX 4 | * library's graphics primitives, such as rounded rectangles and triangles. 5 | * 6 | * Copyright (C) 2024-2025 Dennis Hoelscher 7 | * www.fluxgarage.com 8 | * www.youtube.com/@FluxGarage 9 | * 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #ifndef _FLUXGARAGE_ROBOEYES_H 27 | #define _FLUXGARAGE_ROBOEYES_H 28 | 29 | 30 | // Display colors 31 | uint8_t BGCOLOR = 0; // background and overlays 32 | uint8_t MAINCOLOR = 1; // drawings 33 | 34 | // For mood type switch 35 | #define DEFAULT 0 36 | #define TIRED 1 37 | #define ANGRY 2 38 | #define HAPPY 3 39 | 40 | // For turning things on or off 41 | #define ON 1 42 | #define OFF 0 43 | 44 | // For switch "predefined positions" 45 | #define N 1 // north, top center 46 | #define NE 2 // north-east, top right 47 | #define E 3 // east, middle right 48 | #define SE 4 // south-east, bottom right 49 | #define S 5 // south, bottom center 50 | #define SW 6 // south-west, bottom left 51 | #define W 7 // west, middle left 52 | #define NW 8 // north-west, top left 53 | // for middle center set "DEFAULT" 54 | 55 | 56 | // Constructor: takes a reference to the active Adafruit display object (e.g., Adafruit_SSD1327) 57 | // Eg: roboEyes = eyes(display); 58 | template 59 | class RoboEyes 60 | { 61 | private: 62 | 63 | // Yes, everything is currently still accessible. Be responsible and don't mess things up :) 64 | 65 | public: 66 | 67 | // Reference to Adafruit display object 68 | AdafruitDisplay *display; 69 | 70 | // For general setup - screen size and max. frame rate 71 | int screenWidth = 128; // OLED display width, in pixels 72 | int screenHeight = 64; // OLED display height, in pixels 73 | int frameInterval = 20; // default value for 50 frames per second (1000/50 = 20 milliseconds) 74 | unsigned long fpsTimer = 0; // for timing the frames per second 75 | 76 | // For controlling mood types and expressions 77 | bool tired = 0; 78 | bool angry = 0; 79 | bool happy = 0; 80 | bool curious = 0; // if true, draw the outer eye larger when looking left or right 81 | bool cyclops = 0; // if true, draw only one eye 82 | bool eyeL_open = 0; // left eye opened or closed? 83 | bool eyeR_open = 0; // right eye opened or closed? 84 | 85 | 86 | //********************************************************************************************* 87 | // Eyes Geometry 88 | //********************************************************************************************* 89 | 90 | // EYE LEFT - size and border radius 91 | int eyeLwidthDefault = 36; 92 | int eyeLheightDefault = 36; 93 | int eyeLwidthCurrent = eyeLwidthDefault; 94 | int eyeLheightCurrent = 1; // start with closed eye, otherwise set to eyeLheightDefault 95 | int eyeLwidthNext = eyeLwidthDefault; 96 | int eyeLheightNext = eyeLheightDefault; 97 | int eyeLheightOffset = 0; 98 | // Border Radius 99 | byte eyeLborderRadiusDefault = 8; 100 | byte eyeLborderRadiusCurrent = eyeLborderRadiusDefault; 101 | byte eyeLborderRadiusNext = eyeLborderRadiusDefault; 102 | 103 | // EYE RIGHT - size and border radius 104 | int eyeRwidthDefault = eyeLwidthDefault; 105 | int eyeRheightDefault = eyeLheightDefault; 106 | int eyeRwidthCurrent = eyeRwidthDefault; 107 | int eyeRheightCurrent = 1; // start with closed eye, otherwise set to eyeRheightDefault 108 | int eyeRwidthNext = eyeRwidthDefault; 109 | int eyeRheightNext = eyeRheightDefault; 110 | int eyeRheightOffset = 0; 111 | // Border Radius 112 | byte eyeRborderRadiusDefault = 8; 113 | byte eyeRborderRadiusCurrent = eyeRborderRadiusDefault; 114 | byte eyeRborderRadiusNext = eyeRborderRadiusDefault; 115 | 116 | // EYE LEFT - Coordinates 117 | int eyeLxDefault = ((screenWidth)-(eyeLwidthDefault+spaceBetweenDefault+eyeRwidthDefault))/2; 118 | int eyeLyDefault = ((screenHeight-eyeLheightDefault)/2); 119 | int eyeLx = eyeLxDefault; 120 | int eyeLy = eyeLyDefault; 121 | int eyeLxNext = eyeLx; 122 | int eyeLyNext = eyeLy; 123 | 124 | // EYE RIGHT - Coordinates 125 | int eyeRxDefault = eyeLx+eyeLwidthCurrent+spaceBetweenDefault; 126 | int eyeRyDefault = eyeLy; 127 | int eyeRx = eyeRxDefault; 128 | int eyeRy = eyeRyDefault; 129 | int eyeRxNext = eyeRx; 130 | int eyeRyNext = eyeRy; 131 | 132 | // BOTH EYES 133 | // Eyelid top size 134 | byte eyelidsHeightMax = eyeLheightDefault/2; // top eyelids max height 135 | byte eyelidsTiredHeight = 0; 136 | byte eyelidsTiredHeightNext = eyelidsTiredHeight; 137 | byte eyelidsAngryHeight = 0; 138 | byte eyelidsAngryHeightNext = eyelidsAngryHeight; 139 | // Bottom happy eyelids offset 140 | byte eyelidsHappyBottomOffsetMax = (eyeLheightDefault/2)+3; 141 | byte eyelidsHappyBottomOffset = 0; 142 | byte eyelidsHappyBottomOffsetNext = 0; 143 | // Space between eyes 144 | int spaceBetweenDefault = 10; 145 | int spaceBetweenCurrent = spaceBetweenDefault; 146 | int spaceBetweenNext = 10; 147 | 148 | 149 | //********************************************************************************************* 150 | // Macro Animations 151 | //********************************************************************************************* 152 | 153 | // Animation - horizontal flicker/shiver 154 | bool hFlicker = 0; 155 | bool hFlickerAlternate = 0; 156 | byte hFlickerAmplitude = 2; 157 | 158 | // Animation - vertical flicker/shiver 159 | bool vFlicker = 0; 160 | bool vFlickerAlternate = 0; 161 | byte vFlickerAmplitude = 10; 162 | 163 | // Animation - auto blinking 164 | bool autoblinker = 0; // activate auto blink animation 165 | int blinkInterval = 1; // basic interval between each blink in full seconds 166 | int blinkIntervalVariation = 4; // interval variaton range in full seconds, random number inside of given range will be add to the basic blinkInterval, set to 0 for no variation 167 | unsigned long blinktimer = 0; // for organising eyeblink timing 168 | 169 | // Animation - idle mode: eyes looking in random directions 170 | bool idle = 0; 171 | int idleInterval = 1; // basic interval between each eye repositioning in full seconds 172 | int idleIntervalVariation = 3; // interval variaton range in full seconds, random number inside of given range will be add to the basic idleInterval, set to 0 for no variation 173 | unsigned long idleAnimationTimer = 0; // for organising eyeblink timing 174 | 175 | // Animation - eyes confused: eyes shaking left and right 176 | bool confused = 0; 177 | unsigned long confusedAnimationTimer = 0; 178 | int confusedAnimationDuration = 500; 179 | bool confusedToggle = 1; 180 | 181 | // Animation - eyes laughing: eyes shaking up and down 182 | bool laugh = 0; 183 | unsigned long laughAnimationTimer = 0; 184 | int laughAnimationDuration = 500; 185 | bool laughToggle = 1; 186 | 187 | // Animation - sweat on the forehead 188 | bool sweat = 0; 189 | byte sweatBorderradius = 3; 190 | 191 | // Sweat drop 1 192 | int sweat1XPosInitial = 2; 193 | int sweat1XPos; 194 | float sweat1YPos = 2; 195 | int sweat1YPosMax; 196 | float sweat1Height = 2; 197 | float sweat1Width = 1; 198 | 199 | // Sweat drop 2 200 | int sweat2XPosInitial = 2; 201 | int sweat2XPos; 202 | float sweat2YPos = 2; 203 | int sweat2YPosMax; 204 | float sweat2Height = 2; 205 | float sweat2Width = 1; 206 | 207 | // Sweat drop 3 208 | int sweat3XPosInitial = 2; 209 | int sweat3XPos; 210 | float sweat3YPos = 2; 211 | int sweat3YPosMax; 212 | float sweat3Height = 2; 213 | float sweat3Width = 1; 214 | 215 | 216 | //********************************************************************************************* 217 | // GENERAL METHODS 218 | //********************************************************************************************* 219 | 220 | RoboEyes(AdafruitDisplay &disp) : display(&disp) {}; 221 | 222 | // Startup RoboEyes with defined screen-width, screen-height and max. frames per second 223 | void begin(int width, int height, byte frameRate) { 224 | screenWidth = width; // OLED display width, in pixels 225 | screenHeight = height; // OLED display height, in pixels 226 | display->clearDisplay(); // clear the display buffer 227 | display->display(); // show empty screen 228 | eyeLheightCurrent = 1; // start with closed eyes 229 | eyeRheightCurrent = 1; // start with closed eyes 230 | setFramerate(frameRate); // calculate frame interval based on defined frameRate 231 | } 232 | 233 | void update(){ 234 | // Limit drawing updates to defined max framerate 235 | if(millis()-fpsTimer >= frameInterval){ 236 | drawEyes(); 237 | fpsTimer = millis(); 238 | } 239 | } 240 | 241 | 242 | //********************************************************************************************* 243 | // SETTERS METHODS 244 | //********************************************************************************************* 245 | 246 | // Calculate frame interval based on defined frameRate 247 | void setFramerate(byte fps){ 248 | frameInterval = 1000/fps; 249 | } 250 | 251 | // Set color values 252 | void setDisplayColors(uint8_t background, uint8_t main) { 253 | BGCOLOR = background; // background and overlays, choose 0 for monochrome displays and 0x00 for grayscale displays such as SSD1322 254 | MAINCOLOR = main; // drawings, choose 1 for monochrome displays and 0x0F for grayscale displays such as SSD1322 (0x0F = maximum brightness) 255 | } 256 | 257 | void setWidth(byte leftEye, byte rightEye) { 258 | eyeLwidthNext = leftEye; 259 | eyeRwidthNext = rightEye; 260 | eyeLwidthDefault = leftEye; 261 | eyeRwidthDefault = rightEye; 262 | } 263 | 264 | void setHeight(byte leftEye, byte rightEye) { 265 | eyeLheightNext = leftEye; 266 | eyeRheightNext = rightEye; 267 | eyeLheightDefault = leftEye; 268 | eyeRheightDefault = rightEye; 269 | } 270 | 271 | // Set border radius for left and right eye 272 | void setBorderradius(byte leftEye, byte rightEye) { 273 | eyeLborderRadiusNext = leftEye; 274 | eyeRborderRadiusNext = rightEye; 275 | eyeLborderRadiusDefault = leftEye; 276 | eyeRborderRadiusDefault = rightEye; 277 | } 278 | 279 | // Set space between the eyes, can also be negative 280 | void setSpacebetween(int space) { 281 | spaceBetweenNext = space; 282 | spaceBetweenDefault = space; 283 | } 284 | 285 | // Set mood expression 286 | void setMood(unsigned char mood) 287 | { 288 | switch (mood) 289 | { 290 | case TIRED: 291 | tired=1; 292 | angry=0; 293 | happy=0; 294 | break; 295 | case ANGRY: 296 | tired=0; 297 | angry=1; 298 | happy=0; 299 | break; 300 | case HAPPY: 301 | tired=0; 302 | angry=0; 303 | happy=1; 304 | break; 305 | default: 306 | tired=0; 307 | angry=0; 308 | happy=0; 309 | break; 310 | } 311 | } 312 | 313 | // Set predefined position 314 | void setPosition(unsigned char position) 315 | { 316 | switch (position) 317 | { 318 | case N: 319 | // North, top center 320 | eyeLxNext = getScreenConstraint_X()/2; 321 | eyeLyNext = 0; 322 | break; 323 | case NE: 324 | // North-east, top right 325 | eyeLxNext = getScreenConstraint_X(); 326 | eyeLyNext = 0; 327 | break; 328 | case E: 329 | // East, middle right 330 | eyeLxNext = getScreenConstraint_X(); 331 | eyeLyNext = getScreenConstraint_Y()/2; 332 | break; 333 | case SE: 334 | // South-east, bottom right 335 | eyeLxNext = getScreenConstraint_X(); 336 | eyeLyNext = getScreenConstraint_Y(); 337 | break; 338 | case S: 339 | // South, bottom center 340 | eyeLxNext = getScreenConstraint_X()/2; 341 | eyeLyNext = getScreenConstraint_Y(); 342 | break; 343 | case SW: 344 | // South-west, bottom left 345 | eyeLxNext = 0; 346 | eyeLyNext = getScreenConstraint_Y(); 347 | break; 348 | case W: 349 | // West, middle left 350 | eyeLxNext = 0; 351 | eyeLyNext = getScreenConstraint_Y()/2; 352 | break; 353 | case NW: 354 | // North-west, top left 355 | eyeLxNext = 0; 356 | eyeLyNext = 0; 357 | break; 358 | default: 359 | // Middle center 360 | eyeLxNext = getScreenConstraint_X()/2; 361 | eyeLyNext = getScreenConstraint_Y()/2; 362 | break; 363 | } 364 | } 365 | 366 | // Set automated eye blinking, minimal blink interval in full seconds and blink interval variation range in full seconds 367 | void setAutoblinker(bool active, int interval, int variation){ 368 | autoblinker = active; 369 | blinkInterval = interval; 370 | blinkIntervalVariation = variation; 371 | } 372 | void setAutoblinker(bool active){ 373 | autoblinker = active; 374 | } 375 | 376 | // Set idle mode - automated eye repositioning, minimal time interval in full seconds and time interval variation range in full seconds 377 | void setIdleMode(bool active, int interval, int variation){ 378 | idle = active; 379 | idleInterval = interval; 380 | idleIntervalVariation = variation; 381 | } 382 | void setIdleMode(bool active) { 383 | idle = active; 384 | } 385 | 386 | // Set curious mode - the respectively outer eye gets larger when looking left or right 387 | void setCuriosity(bool curiousBit) { 388 | curious = curiousBit; 389 | } 390 | 391 | // Set cyclops mode - show only one eye 392 | void setCyclops(bool cyclopsBit) { 393 | cyclops = cyclopsBit; 394 | } 395 | 396 | // Set horizontal flickering (displacing eyes left/right) 397 | void setHFlicker (bool flickerBit, byte Amplitude) { 398 | hFlicker = flickerBit; // turn flicker on or off 399 | hFlickerAmplitude = Amplitude; // define amplitude of flickering in pixels 400 | } 401 | void setHFlicker (bool flickerBit) { 402 | hFlicker = flickerBit; // turn flicker on or off 403 | } 404 | 405 | // Set vertical flickering (displacing eyes up/down) 406 | void setVFlicker (bool flickerBit, byte Amplitude) { 407 | vFlicker = flickerBit; // turn flicker on or off 408 | vFlickerAmplitude = Amplitude; // define amplitude of flickering in pixels 409 | } 410 | void setVFlicker (bool flickerBit) { 411 | vFlicker = flickerBit; // turn flicker on or off 412 | } 413 | 414 | void setSweat (bool sweatBit) { 415 | sweat = sweatBit; // turn sweat on or off 416 | } 417 | 418 | 419 | //********************************************************************************************* 420 | // GETTERS METHODS 421 | //********************************************************************************************* 422 | 423 | // Returns the max x position for left eye 424 | int getScreenConstraint_X(){ 425 | return screenWidth-eyeLwidthCurrent-spaceBetweenCurrent-eyeRwidthCurrent; 426 | } 427 | 428 | // Returns the max y position for left eye 429 | int getScreenConstraint_Y(){ 430 | return screenHeight-eyeLheightDefault; // using default height here, because height will vary when blinking and in curious mode 431 | } 432 | 433 | 434 | //********************************************************************************************* 435 | // BASIC ANIMATION METHODS 436 | //********************************************************************************************* 437 | 438 | // BLINKING FOR BOTH EYES AT ONCE 439 | // Close both eyes 440 | void close() { 441 | eyeLheightNext = 1; // closing left eye 442 | eyeRheightNext = 1; // closing right eye 443 | eyeL_open = 0; // left eye not opened (=closed) 444 | eyeR_open = 0; // right eye not opened (=closed) 445 | } 446 | 447 | // Open both eyes 448 | void open() { 449 | eyeL_open = 1; // left eye opened - if true, drawEyes() will take care of opening eyes again 450 | eyeR_open = 1; // right eye opened 451 | } 452 | 453 | // Trigger eyeblink animation 454 | void blink() { 455 | close(); 456 | open(); 457 | } 458 | 459 | // BLINKING FOR SINGLE EYES, CONTROL EACH EYE SEPARATELY 460 | // Close eye(s) 461 | void close(bool left, bool right) { 462 | if(left){ 463 | eyeLheightNext = 1; // blinking left eye 464 | eyeL_open = 0; // left eye not opened (=closed) 465 | } 466 | if(right){ 467 | eyeRheightNext = 1; // blinking right eye 468 | eyeR_open = 0; // right eye not opened (=closed) 469 | } 470 | } 471 | 472 | // Open eye(s) 473 | void open(bool left, bool right) { 474 | if(left){ 475 | eyeL_open = 1; // left eye opened - if true, drawEyes() will take care of opening eyes again 476 | } 477 | if(right){ 478 | eyeR_open = 1; // right eye opened 479 | } 480 | } 481 | 482 | // Trigger eyeblink(s) animation 483 | void blink(bool left, bool right) { 484 | close(left, right); 485 | open(left, right); 486 | } 487 | 488 | 489 | //********************************************************************************************* 490 | // MACRO ANIMATION METHODS 491 | //********************************************************************************************* 492 | 493 | // Play confused animation - one shot animation of eyes shaking left and right 494 | void anim_confused() { 495 | confused = 1; 496 | } 497 | 498 | // Play laugh animation - one shot animation of eyes shaking up and down 499 | void anim_laugh() { 500 | laugh = 1; 501 | } 502 | 503 | //********************************************************************************************* 504 | // PRE-CALCULATIONS AND ACTUAL DRAWINGS 505 | //********************************************************************************************* 506 | 507 | void drawEyes(){ 508 | 509 | //// PRE-CALCULATIONS - EYE SIZES AND VALUES FOR ANIMATION TWEENINGS //// 510 | 511 | // Vertical size offset for larger eyes when looking left or right (curious gaze) 512 | if(curious){ 513 | if(eyeLxNext<=10){eyeLheightOffset=8;} 514 | else if (eyeLxNext>=(getScreenConstraint_X()-10) && cyclops){eyeLheightOffset=8;} 515 | else{eyeLheightOffset=0;} // left eye 516 | if(eyeRxNext>=screenWidth-eyeRwidthCurrent-10){eyeRheightOffset=8;} 517 | else{eyeRheightOffset=0;} // right eye 518 | } else { 519 | eyeLheightOffset=0; // reset height offset for left eye 520 | eyeRheightOffset=0; // reset height offset for right eye 521 | } 522 | 523 | // Left eye height 524 | eyeLheightCurrent = (eyeLheightCurrent + eyeLheightNext + eyeLheightOffset)/2; 525 | eyeLy+= ((eyeLheightDefault-eyeLheightCurrent)/2); // vertical centering of eye when closing 526 | eyeLy-= eyeLheightOffset/2; 527 | // Right eye height 528 | eyeRheightCurrent = (eyeRheightCurrent + eyeRheightNext + eyeRheightOffset)/2; 529 | eyeRy+= (eyeRheightDefault-eyeRheightCurrent)/2; // vertical centering of eye when closing 530 | eyeRy-= eyeRheightOffset/2; 531 | 532 | 533 | // Open eyes again after closing them 534 | if(eyeL_open){ 535 | if(eyeLheightCurrent <= 1 + eyeLheightOffset){eyeLheightNext = eyeLheightDefault;} 536 | } 537 | if(eyeR_open){ 538 | if(eyeRheightCurrent <= 1 + eyeRheightOffset){eyeRheightNext = eyeRheightDefault;} 539 | } 540 | 541 | // Left eye width 542 | eyeLwidthCurrent = (eyeLwidthCurrent + eyeLwidthNext)/2; 543 | // Right eye width 544 | eyeRwidthCurrent = (eyeRwidthCurrent + eyeRwidthNext)/2; 545 | 546 | 547 | // Space between eyes 548 | spaceBetweenCurrent = (spaceBetweenCurrent + spaceBetweenNext)/2; 549 | 550 | // Left eye coordinates 551 | eyeLx = (eyeLx + eyeLxNext)/2; 552 | eyeLy = (eyeLy + eyeLyNext)/2; 553 | // Right eye coordinates 554 | eyeRxNext = eyeLxNext+eyeLwidthCurrent+spaceBetweenCurrent; // right eye's x position depends on left eyes position + the space between 555 | eyeRyNext = eyeLyNext; // right eye's y position should be the same as for the left eye 556 | eyeRx = (eyeRx + eyeRxNext)/2; 557 | eyeRy = (eyeRy + eyeRyNext)/2; 558 | 559 | // Left eye border radius 560 | eyeLborderRadiusCurrent = (eyeLborderRadiusCurrent + eyeLborderRadiusNext)/2; 561 | // Right eye border radius 562 | eyeRborderRadiusCurrent = (eyeRborderRadiusCurrent + eyeRborderRadiusNext)/2; 563 | 564 | 565 | //// APPLYING MACRO ANIMATIONS //// 566 | 567 | if(autoblinker){ 568 | if(millis() >= blinktimer){ 569 | blink(); 570 | blinktimer = millis()+(blinkInterval*1000)+(random(blinkIntervalVariation)*1000); // calculate next time for blinking 571 | } 572 | } 573 | 574 | // Laughing - eyes shaking up and down for the duration defined by laughAnimationDuration (default = 500ms) 575 | if(laugh){ 576 | if(laughToggle){ 577 | setVFlicker(1, 5); 578 | laughAnimationTimer = millis(); 579 | laughToggle = 0; 580 | } else if(millis() >= laughAnimationTimer+laughAnimationDuration){ 581 | setVFlicker(0, 0); 582 | laughToggle = 1; 583 | laugh=0; 584 | } 585 | } 586 | 587 | // Confused - eyes shaking left and right for the duration defined by confusedAnimationDuration (default = 500ms) 588 | if(confused){ 589 | if(confusedToggle){ 590 | setHFlicker(1, 20); 591 | confusedAnimationTimer = millis(); 592 | confusedToggle = 0; 593 | } else if(millis() >= confusedAnimationTimer+confusedAnimationDuration){ 594 | setHFlicker(0, 0); 595 | confusedToggle = 1; 596 | confused=0; 597 | } 598 | } 599 | 600 | // Idle - eyes moving to random positions on screen 601 | if(idle){ 602 | if(millis() >= idleAnimationTimer){ 603 | eyeLxNext = random(getScreenConstraint_X()); 604 | eyeLyNext = random(getScreenConstraint_Y()); 605 | idleAnimationTimer = millis()+(idleInterval*1000)+(random(idleIntervalVariation)*1000); // calculate next time for eyes repositioning 606 | } 607 | } 608 | 609 | // Adding offsets for horizontal flickering/shivering 610 | if(hFlicker){ 611 | if(hFlickerAlternate) { 612 | eyeLx += hFlickerAmplitude; 613 | eyeRx += hFlickerAmplitude; 614 | } else { 615 | eyeLx -= hFlickerAmplitude; 616 | eyeRx -= hFlickerAmplitude; 617 | } 618 | hFlickerAlternate = !hFlickerAlternate; 619 | } 620 | 621 | // Adding offsets for horizontal flickering/shivering 622 | if(vFlicker){ 623 | if(vFlickerAlternate) { 624 | eyeLy += vFlickerAmplitude; 625 | eyeRy += vFlickerAmplitude; 626 | } else { 627 | eyeLy -= vFlickerAmplitude; 628 | eyeRy -= vFlickerAmplitude; 629 | } 630 | vFlickerAlternate = !vFlickerAlternate; 631 | } 632 | 633 | // Cyclops mode, set second eye's size and space between to 0 634 | if(cyclops){ 635 | eyeRwidthCurrent = 0; 636 | eyeRheightCurrent = 0; 637 | spaceBetweenCurrent = 0; 638 | } 639 | 640 | //// ACTUAL DRAWINGS //// 641 | 642 | display->clearDisplay(); // start with a blank screen 643 | 644 | // Draw basic eye rectangles 645 | display->fillRoundRect(eyeLx, eyeLy, eyeLwidthCurrent, eyeLheightCurrent, eyeLborderRadiusCurrent, MAINCOLOR); // left eye 646 | if (!cyclops){ 647 | display->fillRoundRect(eyeRx, eyeRy, eyeRwidthCurrent, eyeRheightCurrent, eyeRborderRadiusCurrent, MAINCOLOR); // right eye 648 | } 649 | 650 | // Prepare mood type transitions 651 | if (tired){eyelidsTiredHeightNext = eyeLheightCurrent/2; eyelidsAngryHeightNext = 0;} else{eyelidsTiredHeightNext = 0;} 652 | if (angry){eyelidsAngryHeightNext = eyeLheightCurrent/2; eyelidsTiredHeightNext = 0;} else{eyelidsAngryHeightNext = 0;} 653 | if (happy){eyelidsHappyBottomOffsetNext = eyeLheightCurrent/2;} else{eyelidsHappyBottomOffsetNext = 0;} 654 | 655 | // Draw tired top eyelids 656 | eyelidsTiredHeight = (eyelidsTiredHeight + eyelidsTiredHeightNext)/2; 657 | if (!cyclops){ 658 | display->fillTriangle(eyeLx, eyeLy-1, eyeLx+eyeLwidthCurrent, eyeLy-1, eyeLx, eyeLy+eyelidsTiredHeight-1, BGCOLOR); // left eye 659 | display->fillTriangle(eyeRx, eyeRy-1, eyeRx+eyeRwidthCurrent, eyeRy-1, eyeRx+eyeRwidthCurrent, eyeRy+eyelidsTiredHeight-1, BGCOLOR); // right eye 660 | } else { 661 | // Cyclops tired eyelids 662 | display->fillTriangle(eyeLx, eyeLy-1, eyeLx+(eyeLwidthCurrent/2), eyeLy-1, eyeLx, eyeLy+eyelidsTiredHeight-1, BGCOLOR); // left eyelid half 663 | display->fillTriangle(eyeLx+(eyeLwidthCurrent/2), eyeLy-1, eyeLx+eyeLwidthCurrent, eyeLy-1, eyeLx+eyeLwidthCurrent, eyeLy+eyelidsTiredHeight-1, BGCOLOR); // right eyelid half 664 | } 665 | 666 | // Draw angry top eyelids 667 | eyelidsAngryHeight = (eyelidsAngryHeight + eyelidsAngryHeightNext)/2; 668 | if (!cyclops){ 669 | display->fillTriangle(eyeLx, eyeLy-1, eyeLx+eyeLwidthCurrent, eyeLy-1, eyeLx+eyeLwidthCurrent, eyeLy+eyelidsAngryHeight-1, BGCOLOR); // left eye 670 | display->fillTriangle(eyeRx, eyeRy-1, eyeRx+eyeRwidthCurrent, eyeRy-1, eyeRx, eyeRy+eyelidsAngryHeight-1, BGCOLOR); // right eye 671 | } else { 672 | // Cyclops angry eyelids 673 | display->fillTriangle(eyeLx, eyeLy-1, eyeLx+(eyeLwidthCurrent/2), eyeLy-1, eyeLx+(eyeLwidthCurrent/2), eyeLy+eyelidsAngryHeight-1, BGCOLOR); // left eyelid half 674 | display->fillTriangle(eyeLx+(eyeLwidthCurrent/2), eyeLy-1, eyeLx+eyeLwidthCurrent, eyeLy-1, eyeLx+(eyeLwidthCurrent/2), eyeLy+eyelidsAngryHeight-1, BGCOLOR); // right eyelid half 675 | } 676 | 677 | // Draw happy bottom eyelids 678 | eyelidsHappyBottomOffset = (eyelidsHappyBottomOffset + eyelidsHappyBottomOffsetNext)/2; 679 | display->fillRoundRect(eyeLx-1, (eyeLy+eyeLheightCurrent)-eyelidsHappyBottomOffset+1, eyeLwidthCurrent+2, eyeLheightDefault, eyeLborderRadiusCurrent, BGCOLOR); // left eye 680 | if (!cyclops){ 681 | display->fillRoundRect(eyeRx-1, (eyeRy+eyeRheightCurrent)-eyelidsHappyBottomOffset+1, eyeRwidthCurrent+2, eyeRheightDefault, eyeRborderRadiusCurrent, BGCOLOR); // right eye 682 | } 683 | 684 | // Add sweat drops 685 | if (sweat){ 686 | // Sweat drop 1 -> left corner 687 | if(sweat1YPos <= sweat1YPosMax){sweat1YPos+=0.5;} // vertical movement from initial to max 688 | else {sweat1XPosInitial = random(30); sweat1YPos = 2; sweat1YPosMax = (random(10)+10); sweat1Width = 1; sweat1Height = 2;} // if max vertical position is reached: reset all values for next drop 689 | if(sweat1YPos <= sweat1YPosMax/2){sweat1Width+=0.5; sweat1Height+=0.5;} // shape grows in first half of animation ... 690 | else {sweat1Width-=0.1; sweat1Height-=0.5;} // ... and shrinks in second half of animation 691 | sweat1XPos = sweat1XPosInitial-(sweat1Width/2); // keep the growing shape centered to initial x position 692 | display->fillRoundRect(sweat1XPos, sweat1YPos, sweat1Width, sweat1Height, sweatBorderradius, MAINCOLOR); // draw sweat drop 693 | 694 | 695 | // Sweat drop 2 -> center area 696 | if(sweat2YPos <= sweat2YPosMax){sweat2YPos+=0.5;} // vertical movement from initial to max 697 | else {sweat2XPosInitial = random((screenWidth-60))+30; sweat2YPos = 2; sweat2YPosMax = (random(10)+10); sweat2Width = 1; sweat2Height = 2;} // if max vertical position is reached: reset all values for next drop 698 | if(sweat2YPos <= sweat2YPosMax/2){sweat2Width+=0.5; sweat2Height+=0.5;} // shape grows in first half of animation ... 699 | else {sweat2Width-=0.1; sweat2Height-=0.5;} // ... and shrinks in second half of animation 700 | sweat2XPos = sweat2XPosInitial-(sweat2Width/2); // keep the growing shape centered to initial x position 701 | display->fillRoundRect(sweat2XPos, sweat2YPos, sweat2Width, sweat2Height, sweatBorderradius, MAINCOLOR); // draw sweat drop 702 | 703 | 704 | // Sweat drop 3 -> right corner 705 | if(sweat3YPos <= sweat3YPosMax){sweat3YPos+=0.5;} // vertical movement from initial to max 706 | else {sweat3XPosInitial = (screenWidth-30)+(random(30)); sweat3YPos = 2; sweat3YPosMax = (random(10)+10); sweat3Width = 1; sweat3Height = 2;} // if max vertical position is reached: reset all values for next drop 707 | if(sweat3YPos <= sweat3YPosMax/2){sweat3Width+=0.5; sweat3Height+=0.5;} // shape grows in first half of animation ... 708 | else {sweat3Width-=0.1; sweat3Height-=0.5;} // ... and shrinks in second half of animation 709 | sweat3XPos = sweat3XPosInitial-(sweat3Width/2); // keep the growing shape centered to initial x position 710 | display->fillRoundRect(sweat3XPos, sweat3YPos, sweat3Width, sweat3Height, sweatBorderradius, MAINCOLOR); // draw sweat drop 711 | } 712 | 713 | display->display(); // show drawings on display 714 | 715 | } // end of drawEyes method 716 | 717 | 718 | }; // end of class roboEyes 719 | 720 | 721 | #endif 722 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------