// Init the Pins used for PWM const int redPin = 9; //for rgb led const int greenPin = 10; //for rgb led const int bluePin = 11; //for rgb led const int greenLedPin = 3; // green led const int yellowLedPin = 4; // yellow led const int blueLedPin = 5; // blue led const int redLedPin = 6; // red led // Init our Vars int currentColorValueRed; int currentColorValueGreen; int currentColorValueBlue; void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(redLedPin,OUTPUT); pinMode(greenLedPin,OUTPUT); pinMode(yellowLedPin,OUTPUT); pinMode(blueLedPin,OUTPUT); } void loop() { // I want the eyes to be red all the time, but changing this values // will change the eye color on both eyes to the same color // Common anode LED requires inverted values currentColorValueRed = 0; currentColorValueBlue = 255; currentColorValueGreen = 255; // Write the color to each pin using PWM and the value gathered above analogWrite(redPin, currentColorValueRed); analogWrite(bluePin, currentColorValueBlue); analogWrite(greenPin, currentColorValueGreen); flash2on2offPattern(100); clockwisePattern(100); flashAllPattern(100); counterclockwisePattern(100); flash2on2offPattern(50); clockwisePattern(50); flashAllPattern(50); counterclockwisePattern(50); flash2on2offPattern(100); clockwisePattern(100); flashAllPattern(100); counterclockwisePattern(100); } void clockwisePattern(int duration) { for(int x=0; x<10; x++ ) { digitalWrite(redLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(yellowLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(blueLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(greenLedPin, LOW); // turn the LED off by making the voltage LOW delay(duration); // wait for 2 seconds digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, LOW); // turn the LED on (HIGH is the voltage level) delay(duration); digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, HIGH); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, LOW); // turn the LED on (HIGH is the voltage level) delay(duration); digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(duration); } } void counterclockwisePattern(int duration) { for(int x=0; x<10; x++ ) { digitalWrite(redLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(yellowLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(blueLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(greenLedPin, LOW); // turn the LED off by making the voltage LOW delay(duration); // wait for 2 seconds digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(duration); digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, HIGH); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, LOW); // turn the LED on (HIGH is the voltage level) delay(duration); digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, LOW); // turn the LED on (HIGH is the voltage level) delay(duration); } } void flashAllPattern(int duration) { for(int x=0; x<15; x++ ) { digitalWrite(redLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(yellowLedPin, HIGH); // turn the LED off by making the voltage LOW digitalWrite(blueLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(greenLedPin, HIGH); // turn the LED off by making the voltage LOW delay(duration); // wait for 3 seconds digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, LOW); // turn the LED on (HIGH is the voltage level) delay(duration); } } void flash2on2offPattern(int duration) { for(int x=0; x<15; x++ ) { digitalWrite(redLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(yellowLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(blueLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(greenLedPin, LOW); // turn the LED off by making the voltage LOW delay(duration); // wait for 3 seconds digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(yellowLedPin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(blueLedPin, LOW); // turn the LED off by making the voltage LOW digitalWrite(greenLedPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(duration); // wait for 3 seconds } }