I've made a Digital Light Organ Enchantment for my Perpetuum-Ebner turntable last week.
To add a little cyberpunk touch to it, I'm creating a servo lift that will pop out the light effects when there is music.
I've titled it an autonomous lift because the logic is contained within a limited set of code.
You tell it to be up or down, and it will take care to achieve that state and stay there until told differently.
The servo is a small 180° common motor, not the 360° continuous servo.
Servo Lift Code
The lift logic is contained in a few methods. You only have to remember to call servoInit() in your setup() code, and call servoGo() at regular times (I've put it in the loop().
You tell the servo what state it should be in by setting the boolean variable servoUp to false (down) or true (up).
The servo will work by itself to fulfill your demand.
There are a few parameters you can tweak:
SERVO_BASE: the down position of the lift.
SERVO_TOP: the up position
SERVO_DELAY: milliseconds between steps to move up or down. Affects the rise and fall time of the light organ in my player.
#include <Servo.h> Servo servo; #define SERVO_PIN 9 #define SERVO_DELAY 25 #define SERVO_BASE 90 #define SERVO_TOP (SERVO_BASE - 61) int servoPos = SERVO_BASE; bool servoUp = false; void servoInit() { servoUp = false; servo.attach(SERVO_PIN); servoPos = SERVO_BASE; servo.write(SERVO_BASE); delay(1000); } void servoGoUp() { if (servoPos > SERVO_BASE) { servoInit(); } if (servoPos > SERVO_TOP) { servoPos--; servo.write(servoPos); delay(SERVO_DELAY); } } void servoGoDown() { if (servoPos > SERVO_BASE) { servoInit(); } if (servoPos < SERVO_BASE) { servoPos++; servo.write(servoPos); delay(SERVO_DELAY); } } void servoGo() { if (servoUp) { servoGoUp(); } else { servoGoDown(); } }
Test Bed Code
The sketch to exercise the lift is simple.
It waits for you to enter a command in the Arduino IDE Serial Monitor.
If you enter '1', the lift will go up slowly and stay there. If you enter '0' it will go down.
void setup() { Serial.begin(9600); servoInit(); Serial.println("Menu: Up: 1, Down: 0"); } void loop() { while (Serial.available() > 0) { servoUp = (Serial.parseInt() > 0); } servoGo(); }
The lift is supposed to go into the cable storage area of the Perpetuum-Ebner Musical 1.
Top Comments