#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
// Init the Pins used for PWM
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
// Init our Vars
int currentColorValueRed;
int currentColorValueGreen;
int currentColorValueBlue;
void setup()
{
myservo.attach(3); // attaches the servo on pin 3 to the servo object
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
} //add this closing bracket for the void loop
// event 1, servo moves to random position counter clockwise
void event_1 () {
pos = random(1, 90);
myservo.write(pos);
delay(random(1000,3000));
myservo.write(91); //servo stop command
}
//event 2, random color in tri-color led
void event_2 () {
currentColorValueRed = random(255);
currentColorValueBlue = random(255);
currentColorValueGreen = random(255);
// Write the color to each pin using PWM and the value gathered above
analogWrite(redPin, currentColorValueRed);
analogWrite(bluePin, currentColorValueBlue);
analogWrite(greenPin, currentColorValueGreen);
delay(3000);
}
//event 3, random position of servo clockwise movement
void event_3 () {
pos = random(92, 180); //
myservo.write(pos);
delay(random(1000,3000));
myservo.write(91); //servo stop command
}
//event 4, random color LED
void event_4 () {
currentColorValueRed = random(255);
currentColorValueBlue = random(255);
currentColorValueGreen = random(255);
// Write the color to each pin using PWM and the value gathered above
analogWrite(redPin, currentColorValueRed);
analogWrite(bluePin, currentColorValueBlue);
analogWrite(greenPin, currentColorValueGreen);
delay(3000);
}