I just had enough time left to create SANTA THREE : The Baubles befoe the close of the Hack The Holidays Project 14 competition. This adds some dancing baubles to the SANTA ONE and TWO displays, to create the full throttle SANTA ONE TWO THREE.
It is just two servo motors added to A2 and A1 outputs on the Arduino Nano used for SANTA TWO and uses almost the same programme from EyeballThingy ( EyeBall Thingy ) to create random movements on the two servo motors. The full programme including the train controlling is listed at the end of this Blog.
I used two giant baubles with each servo motor with a small piece of wood bar to separate them. By hanging the baubles equi-distant from the centre point the stress on these small servos is reduced. I used cotton to tie the baubles to the ends of the wood bars and BlueTac to hold everything together. I wasn't planning on creating something that would last (and it didn't). I then placed the two servo motors on a shelf above the SANTA ONE : Diorama to create SANTA THREE. Below is a video showing the full SANTA ONE TWO THREE in operation (almost).
https://www.youtube.com/watch?v=ZIxc6NYv3pY
Sadly, by the time SANTA THREE was working, SANTA TWO : The Train had stopped working under Nano control so in this video the train is being manually controlled by me. But, it has worked previously so if I was inclined (which I am not) I could probably get it all working properly again. However, time has now run out and I am pleased to stop.
Dubbie
PS The full programme listing is given below.
/*
SantaOneTwoThree
Dubbie Dubbie
4th Jan'23
Just for Fun
*/
#include <Servo.h>
#define bauble1 A2
#define bauble2 A1
#define trainlight 4
#define trainwhistle 5
#define trainbackwards 6
#define trainforwards 7
Servo baubleone;
Servo baubletwo;
int prevleft;
int prevright;
int indexmove;
void setup()
{
Serial.begin(9600);
Serial.println("Santa OneTwoThree ");
baubleone.attach(bauble1);
baubletwo.attach(bauble2);
prevleft = 90;
prevright = 90;
indexmove = 0;
pinMode(trainlight, OUTPUT);
pinMode(trainwhistle, OUTPUT);
pinMode(trainbackwards, OUTPUT);
pinMode(trainforwards, OUTPUT);
digitalWrite(trainlight, HIGH);
digitalWrite(trainwhistle, HIGH);
digitalWrite(trainbackwards, HIGH);
digitalWrite(trainforwards, HIGH);
delay(100);
} /* setup */
void loop()
{
int angle;
angle = 0;
trainmovements();
while (1)
{
randombaubles();
} /* while */
} /* loop */
void tforward(void)
{
digitalWrite(trainforwards, LOW);
delay(1500);
digitalWrite(trainforwards, HIGH);
delay(100);
} /* tforward */
void tbackward(void)
{
digitalWrite(trainbackwards, LOW);
delay(1500);
digitalWrite(trainbackwards, HIGH);
delay(100);
} /* tbackward */
void tbackstop(void)
{
digitalWrite(trainforwards, LOW);
delay(100);
digitalWrite(trainforwards, HIGH);
delay(100);
} /* tbackstop */
void tforstop(void)
{
digitalWrite(trainbackwards, LOW);
delay(100);
digitalWrite(trainbackwards, HIGH);
delay(100);
} /* tforstop */
void trainmovements(void)
{
delay(1000);
tbackward();
delay(2000);
tbackstop();
delay(2000);
tforward();
delay(2000);
tforstop();
} /* trainmovements */
void randombaubles(void)
{
int nexteye;
nexteye = 0;
nexteye = random(0, 180);
movelefteyeto(prevleft, nexteye);
moverighteyeto(prevright, nexteye);
prevleft = nexteye;
prevright = nexteye;
} /* randomeyes */
void movelefteyeto(int prev, int next)
{
int angle;
angle = 0;
// Serial.print(prev); Serial.print(" "); Serial.println(next);
if (next >= prev)
{
// Serial.println("Up ");
for (angle = prev; angle <= next; angle += 1)
{
baubleone.write(angle);
delay(20);
} /* for */
}
else
{
// Serial.println("Down ");
for (angle = prev; angle >= next; angle -= 1)
{
// Serial.println(angle);
baubleone.write(angle);
delay(20);
} /* for */
} /* else */
} /* movelefteye */
void moverighteyeto(int prev, int next)
{
int angle;
angle = 0;
// Serial.print(prev); Serial.print(" "); Serial.println(next);
if (next >= prev)
{
// Serial.println("Up ");
for (angle = prev; angle <= next; angle += 1)
{
baubletwo.write(angle);
delay(20);
} /* for */
}
else
{
// Serial.println("Down ");
for (angle = prev; angle >= next; angle -= 1)
{
Serial.println(angle);
baubletwo.write(angle);
delay(20);
} /* for */
} /* else */
} /* moverighteye */