/*
main.ino
description: Drive relay to control blinking LED ball/disk,
relay control of confetti sprayer, RC servo control, and
control of extra RGB LEDs.
*/
// includes
#include <SoftPWMServo.h>
// defines
// global const variables
const int glowBallRelay = 30;
const int confettiRelay = 3;
const int red1 = 4;
const int green1 = 5;
const int blue1 = 6;
const int red2 = 7;
const int green2 = 8;
const int blue2 = 9;
const int red3 = 10;
const int green3 = 11;
const int blue3 = 12;
const int red4 = 19;
const int green4 = 20;
const int blue4 = 21;
const int servoPin = 29;
const int buttonPin = 28;
// global variables
int buttonState = 0;
int glowState = 0;
// function prototypes
// begin setup
void setup()
{
pinMode(glowBallRelay, OUTPUT);
digitalWrite(glowBallRelay, LOW);
pinMode(confettiRelay, OUTPUT);
pinMode(buttonPin, INPUT);
}
// begin loop
void loop()
{
// check button state
buttonState = digitalRead(buttonPin);
// check for state change
if(buttonState == HIGH)
{
// turn on confetti and glow ball
if(glowState == 0)
{
digitalWrite(glowBallRelay, HIGH);
delay(50);
digitalWrite(glowBallRelay, LOW);
glowState = 1;
}
digitalWrite(confettiRelay, HIGH);
// turn servo clockwise
SoftPWMServoServoWrite(servoPin, 2000);
delay(1000);
// turn servo counter-clockwise
SoftPWMServoServoWrite(servoPin, 1000);
delay(1000); // add this if needed
}
else
{
// make sure confetti, glow ball, and servo are off
digitalWrite(confettiRelay, LOW);
digitalWrite(glowBallRelay, LOW);
SoftPWMServoServoWrite(servoPin, 1500);
}
}
Comments