/************************************************************************************
TO ATTINY 85 TWO RINGS RING1 RING2 CONNECTED.WRITE CODE TO CHASE
LEDS OF RING1 CLOCKWISE USINF RANDOM SEVEN RAINBOW COLORS WHILE
RING TO CHASES LEDS ANTI CLOCKWISE BUT WITH
RAINBOW RANDOM COLORS
This code uses the Adafruit_NeoPixel library to control the LED rings.
The rainbow_colors array contains 7 different rainbow colors,
which are used to set the color of the LEDs as they chase around the rings. The setPixelColor method is used to set the color of each LED, and the show method is used to update the LEDs on the ring. The delay function is used to control the speed
of the animation.
author arvind patil 25 m,arh2023
The ATtiny85 pinout is discussed below:
Pin 1 (PB5)- It is for an analog pin ADC0 and is used for analog sensors.
Pin2 (PB3)- It is for an analog pin ADC3 and also for crystal oscillator XTAL1.
Pin3 (PB4)- It is for analog pin ADC2 and also used for crystal oscillator XTAL2.
Pin4 (GND)- It should be connected to the Ground.
Pin5 (PB0)- This pin is used as MOSI (Master Out Slave In).
It can be used as a master line for sending data to the peripherals
for SPI communication and SDA for I2C Communication.
Pin6 (PB1)- This pin is used as MISO(Master In Slave Out). It can be used
as a Slave line for sending data to the master.
Pin 7 (PB2)- This can be used as SCK for SPI Communication and
SCL for I2C Communication.
Pin 8 (Vcc)- It is used as Vcc Pin & 5V is applied on
***************************************************************************/
#include <Adafruit_NeoPixel.h>
// Number of LEDs on each ring
#define NUM_LEDS 12
// Pin numbers for each ring
#define RING1_PIN 0
#define RING2_PIN 1
// Define the LED rings
Adafruit_NeoPixel ring1 = Adafruit_NeoPixel(NUM_LEDS, RING1_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ring2 = Adafruit_NeoPixel(NUM_LEDS, RING2_PIN, NEO_GRB + NEO_KHZ800);
// Array of 7 rainbow colors
uint32_t rainbow_colors[] = {
ring1.Color(255, 0, 0), // Red
ring1.Color(255, 127, 0), // Orange
ring1.Color(255, 255, 0), // Yellow
ring1.Color(0, 255, 0), // Green
ring1.Color(0, 0, 255), // Blue
ring1.Color(75, 0, 130), // Indigo
ring1.Color(148, 0, 211) // Violet
};
void setup() {
// Initialize the LED rings
ring1.begin();
ring2.begin();
}
void loop() {
// Chase the LEDs on ring 1 clockwise using rainbow colors
for (int i = 0; i < NUM_LEDS; i++) {
// Set the LED at the current index to the current rainbow color
ring1.setPixelColor(i, rainbow_colors[i % 7]);
// Show the updated LED colors on the ring
ring1.show();
// Delay to control the speed of the animation
delay(150);
// Clear the LED at the current index
ring1.setPixelColor(i, 0);
}
// Chase the LEDs on ring 2 anti-clockwise using different rainbow colors
for (int i = NUM_LEDS - 1; i >= 0; i--) {
// Set the LED at the current index to a different rainbow color
ring2.setPixelColor(i, rainbow_colors[(i + 2) % 7]);
// Show the updated LED colors on the ring
ring2.show();
// Delay to control the speed of the animation
delay(150);
// Clear the LED at the current index
ring2.setPixelColor(i, 0);
}
}