January 1

Cheerlights enhanced

Here is a little enhancement for the Cheerlights sketch. I’ve attached a servo, which shall ring a little bell. Alas, the servo is to slow to have a hearable effect on the bell – the sound of the servo is louder than the ringing of the bell.


A picture of the free wiring:

free wiring of cheerlights setup
free wiring of cheerlights setup
/*   cheerlights - interface to www.cheerlights.com
 *
 *   2013-12-15   danimath   created
 *   2014-01-01   danimath   servo added
 *
 **********************************************************/

#include <Servo.h%gt;

const byte REDLED   =   5;
const byte GREENLED =   6;
const byte BLUELED  =   3;
const int  PAUSE    = 500;

int r, g, b, old_r, old_g, old_b;

Servo bell;

void setup ()
{
    bell.attach (9);

    analogWrite (REDLED, 255);
    delay (500);
    analogWrite (REDLED, 0);
    analogWrite (GREENLED, 255);
    delay (500);
    analogWrite (GREENLED, 0);
    analogWrite (BLUELED, 255);
    delay (500);
    analogWrite (REDLED, 255);
    analogWrite (GREENLED, 255);
    analogWrite (BLUELED, 255);
    delay (500);
    Serial.begin (9600);
    old_r = 0;
    old_g = 0;
    old_b = 0;
    r = 255;
    g = 255;
    b = 255;
}void loop ()
{
    if (Serial.available ())
    {
        old_r = r;
        old_g = g;
        old_b = b;
        r = Serial.read ();
        g = Serial.read ();
        b = Serial.read ();
        for (int j = 0;   j < 5;   j++)
        {
            bell.write (45);
            analogWrite (REDLED, r);
            analogWrite (GREENLED, g);
            analogWrite (BLUELED, b);
            delay (PAUSE);
            bell.write (135);
            analogWrite (REDLED, old_r);
            analogWrite (GREENLED, old_g);
            analogWrite (BLUELED, old_b);
            delay (PAUSE);
        }
    }
    analogWrite (REDLED, r);
    analogWrite (GREENLED, g);
    analogWrite (BLUELED, b);
    delay (250);    
}

Tags: , , ,
Copyright © 2014. All rights reserved.

Posted 2014-01-01 by Daniel LeMath in category "Arduino", "Raspberry Pi

Leave a Reply

Your email address will not be published. Required fields are marked *