/****************************************
// https://www.facebook.com/groups/arduino.support.forum/permalink/1200190981187527/
HERE IS A COMBINED CODE FOR AMTEL AVR XPLAINED MINI OR CALLED
NANAO V3 HAVING THREE ONBOARD RGB LEDS
THAT ARE CONNECTED TO PIN 2 I HAVE USED THE NANAO BOARD AND HAVE SHOWN THE RGB LEDS SEPERATLY
AS NANO V3 IS NOT A COMPONENT OF WOKWI ,HOEVER THE ABOVE LINK WILL EXPLAIN NANO V3
ARVIND PATIL INDIA 23/7/24
https://youtu.be/GaplZeeH1P4?si=EWd2KeX36ce1fqZ4
*********************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_NeoPixel.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define PIN 2 // The pin connected to the NeoPixel strip
#define NUMPIXELS 3 // The number of LEDs in the strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Variables for timing
unsigned long previousMillisDisplay = 0;
unsigned long previousMillisNeoPixel = 0;
const long intervalDisplay = 3000; // Interval for OLED display updates
const long intervalNeoPixel = 20; // Interval for NeoPixel updates
// Function to generate rainbow colors across 0-255 positions
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
// Function for rainbow cycle
void rainbowCycle() {
static uint16_t j = 0;
uint16_t i;
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
j++;
}
void setup() {
Serial.begin(9600);
// Initialize OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize with the I2C addr 0x3C (for the 128x32)
display.clearDisplay();
display.display(); // This command will display all the data which is in buffer
// Initialize NeoPixel strip
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
unsigned long currentMillis = millis();
// Update OLED display based on the time interval
if (currentMillis - previousMillisDisplay >= intervalDisplay) {
previousMillisDisplay = currentMillis;
// Drawing animation on OLED display
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.println("ARVIND");
display.display();
display.setCursor(20, 40);
display.setTextSize(1);
display.println("COMBINED CODES");
display.display();
delay(3000);
// Drawing diagonal lines
display.clearDisplay();
display.drawLine(0, 0, display.width() - 1, display.height() - 1, WHITE);
display.drawLine(display.width() - 1, 0, 0, display.height() - 1, WHITE);
display.display();
delay(5000);
// Drawing rectangles
display.clearDisplay();
display.drawRect(100, 10, 20, 20, WHITE);
display.fillRect(10, 10, 45, 15, WHITE);
display.drawRoundRect(60, 20, 35, 35, 8, WHITE);
display.display();
delay(5000);
// Drawing circles
display.clearDisplay();
display.drawCircle(30, 15, 15, WHITE);
display.fillCircle(25, 10, 2, WHITE);
display.fillCircle(35, 10, 2, WHITE);
display.display();
delay(5000);
// Drawing points
display.clearDisplay();
display.drawPixel(20, 35, WHITE);
display.drawPixel(45, 12, WHITE);
display.drawPixel(120, 59, WHITE);
display.drawPixel(97, 20, WHITE);
display.drawPixel(35, 36, WHITE);
display.drawPixel(72, 19, WHITE);
display.drawPixel(90, 7, WHITE);
display.drawPixel(11, 29, WHITE);
display.drawPixel(57, 42, WHITE);
display.drawPixel(69, 34, WHITE);
display.drawPixel(108, 12, WHITE);
display.display();
delay(5000);
}
// Update NeoPixel strip based on the time interval
if (currentMillis - previousMillisNeoPixel >= intervalNeoPixel) {
previousMillisNeoPixel = currentMillis;
rainbowCycle(); // Update NeoPixel colors
}
}