Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Spinning Arrow
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-12 00:32:16
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Draw an animation like a spinning arrow */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_SSD1306.h> // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
- #include <U8g2_for_Adafruit_GFX.h> // https://github.com/olikraus/U8g2_for_Adafruit_GFX
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void drawArrow(int16_t x, int16_t y, int16_t angle); // Function to draw the arrow
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t ga_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
- const uint8_t ga_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
- const uint8_t ga_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the display with the reset pin
- Adafruit_SSD1306 display(ga_SSD1306OledDisplay_I2C_PIN_SDA_A4, ga_SSD1306OledDisplay_I2C_PIN_SCL_A5, -1, -1, ga_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
- // Initialize U8g2_for_Adafruit_GFX with the display instance
- U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; // Instance for U8g2 support
- void setup(void)
- {
- // Initialize the display
- display.begin(SSD1306_SWITCHCAPVCC, ga_SSD1306OledDisplay_I2C_SLAVE_ADDRESS); // Initialize with I2C address
- u8g2_for_adafruit_gfx.begin(display); // Connect U8g2 to Adafruit GFX
- // Clear the display buffer
- display.clearDisplay();
- display.display(); // Make the buffer visible
- }
- void loop(void)
- {
- // Animation loop for spinning arrow
- for (int angle = 0; angle < 360; angle += 10) { // Increment angle for animation
- display.clearDisplay(); // Clear the display buffer
- drawArrow(display.width() / 2, display.height() / 2, angle); // Draw the arrow at the center
- display.display(); // Update the display
- delay(100); // Delay for animation effect
- }
- }
- // Function to draw an arrow at a given angle
- void drawArrow(int16_t x, int16_t y, int16_t angle) {
- // Calculate the arrow points based on the angle
- int16_t arrowLength = 20; // Length of the arrow
- int16_t arrowWidth = 5; // Width of the arrow head
- // Calculate the end point of the arrow
- int16_t endX = x + arrowLength * cos(radians(angle));
- int16_t endY = y + arrowLength * sin(radians(angle));
- // Draw the arrow shaft
- display.drawLine(x, y, endX, endY, WHITE); // Draw line from center to end point
- // Draw the arrow head
- display.drawLine(endX, endY, endX - arrowWidth * cos(radians(angle - 45)), endY - arrowWidth * sin(radians(angle - 45)), WHITE); // Left head
- display.drawLine(endX, endY, endX - arrowWidth * cos(radians(angle + 45)), endY - arrowWidth * sin(radians(angle + 45)), WHITE); // Right head
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement