The hardware for the following control I already had kludged together but Sir Cumference's code finally showed me a practical example of how to use selectable modes, 6 in this case.
I was formerly only able to get a 2-mode 3-channel controller working using state refs(?).
I used, to a sickening degree, plain old digitalWrite commands. I did this because it is the easiest way for beginners to read and understand what the hell is going on in a glob of code.
I also did it because them funny equations with numbers AND letters make my brain hurt. I'm sure there's a more elegant coding solution, I'm still in diapers when it comes to programming.
I ran the electronic repair & calibration divisions at a few universities, never had anything to do with the programming stuff.
Instead of discrete transistors I used a ULN2004A Darlington transistor array. Each section (7 total) handles 500mA. I paralleled the inputs and outputs to handle 1A. I have about 20 hours on the motors at voltages up to 17VDC (short periods), 15VDC continuous. No magic smoke has been emitted yet. Not even any burning wires. Damn.
I have a ULN2069 quad array that handles 1.5A per section, I'll try it out as soon as I can get it unsoldered from a PCB.
The ULN arrays have clamp diodes internally to snub back-EMF. Plus my motors (salvaged from a massage chair) have clamps and capacitors installed across the motor terminals so there's no worries.
So, here's the code. Lots of snippets left in from SC's code but I may use the serial console someday so I left it in.
Code: Select all
/* 3 Motor controller by FoxBilt based upon Sir Cumference's
original code and mode / case switch scheme. My coding is very basic,
the different routines use simple digitalWrite to turn the motors on
and off intentionally to allow others to dive right in and kinda
have a clue by reading my existing garble.
Feel free to use it for your own pleasure (and the pleasure of whoever else is similarly inclined).
Developed on an arduino UNO, then transferred to an ATTiny85.
A lot of "Serial.print" is commented out in the code. If you use an arduino, it is nice to see what
happens, but an ATTiny doesn't like the serial monitor.
Modes available: 6. Populate with your own routines. */
int pot1 = A0; // select the input pin for potentiometer 1 Sequence Fill
int pot2 = A1; // select the input pin for potentiometer 2 Dwell Time
int selector = A2; // input pin for 6-pole rotary switch
// connect 3.9k resistors between each pole terminal, then + on the CCW term, - on the CW term, and com/wiper term to pin A2
int led1 = 3; // (PWM pin) select the pin for transistor 1
int led2 = 5; // (PWM pin) select the pin for transistor 2
int led3 = 6; // (PWM pin) select the pin for transistor 3
// I chose pins 3, 5, 6 for future development using PWM
int val1 = 0; // variable to store the value coming from the Sequence pot
int val2 = 0; // variable to store the value coming from the Dwell pot
int mode;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop()
{
// read values (and print for debugging)
int selectorVal = analogRead(selector);
int val1 = analogRead(pot1);
int val2 = analogRead(pot2);
/*
Serial.println(selectorVal);
Serial.print("val1:");
Serial.println(val1);
Serial.print("val2:");
Serial.println(val2);
Serial.print("Mode:");
Serial.println (mode);
Serial.println("***********************");
*/
// determine mode
mode = 0;
if ( 100 < selectorVal )
{ mode = 1; }
if ( 300 < selectorVal )
{ mode = 2; }
if ( 500 < selectorVal )
{ mode = 3; }
if ( 700 < selectorVal)
{ mode = 4; }
if ( 900 < selectorVal )
{ mode = 5; }
// and use the mode determined
switch (mode)
{
case 0:
// 2x2 - 2 motors on at a time, rotating pattern
digitalWrite(led3, LOW);
delay(val1);
digitalWrite(led1, HIGH); //1 & 2
digitalWrite(led2, HIGH);
delay(val2*2);
digitalWrite(led1, LOW); //2 & 3
delay(val1);
digitalWrite(led3, HIGH);
delay(val2*2);
digitalWrite(led2, LOW); //3 & 1
delay(val1);
digitalWrite(led1, HIGH);
delay(val2*2);
break;
case 1:
// All ON - All OFF
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(val1);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(val2*3);
break;
case 2:
// Variable speed radial pattern - adjustable pulsewidth and period
digitalWrite(led1, HIGH);
delay(val1);
digitalWrite(led3, LOW);
delay(val2);
digitalWrite(led2, HIGH);
delay(val1);
digitalWrite(led1, LOW);
delay(val2);
digitalWrite(led3, HIGH);
delay(val1);
digitalWrite(led2, LOW);
delay(val2);
break;
case 3:
// Adjustable Throb
digitalWrite(led1, HIGH);
delay(val1 * 2);
digitalWrite(led3, LOW);
delay(val1 * 2);
digitalWrite(led2, HIGH);
delay(val1 * 2);
digitalWrite(led1, LOW);
delay(val1 * 2);
digitalWrite(led3, HIGH);
delay(val1 * 2);
digitalWrite(led2, LOW);
delay(val1 * 2);
break;
case 4:
// The Zipper I
// Adjustable phase delay ramp
digitalWrite(led1, HIGH);
delay(val1);
digitalWrite(led2, HIGH);
delay(val1);
digitalWrite(led3, HIGH);
delay(val1 + val2);
digitalWrite(led3, LOW);
delay(val1 * 0.75);
digitalWrite(led2, LOW);
delay(val1 * 0.75);
digitalWrite(led1, LOW);
delay(val1 * 0.75);
break;
case 5:
// The Zipper II
// decreased recycle time using delay(val1 * 0.1);
digitalWrite(led1, HIGH);
delay(val1);
digitalWrite(led2, HIGH);
delay(val1);
digitalWrite(led3, HIGH);
delay(val2 * 2);
digitalWrite(led3, LOW);
delay(val1 * 0.75);
digitalWrite(led2, LOW);
delay(val1 * 0.75);
digitalWrite(led1, LOW);
delay(val1 * 0.1);
break;
}
delay(5); // for stability
}
There are 8 of them, heh heh heh... Now for some of the key parts.
You might wonder why I use the Pro-Mini. They're so cheap that it doesn't make sense to custom etch a PCB in 90% of cases anymore.
I buy them 10 at a time because they're so affordable. 6 analog, 6 PWM, 14 DIO, etc. Plus they're tiny! They'll fit anywhere you want
Arduino Pro-Mini (they call it "Pro Mini Microcontroller Circuit Board Module":
http://www.fasttech.com/products/1380906
$5.25 (price break to $4.75 at 5 units)
I use a variable buck power supply to power the motors. I'll just call it the +15V rail because that's what my motors seem to like.
I'm feeding it 24VDC but limit it to 15V via the trimpot on the power module.
DC-DC 3-40V to 1.5-35V 3A Buck Converter Stepdown Module (Adjustable)
http://www.fasttech.com/products/1219200
$1.48
The ULN2004A I used came out of an old microwave oven.
The molex connectors on the in and out lines are from a broken computer.
I added 5 leds; +5V rail, +15V rail, and one for each motor output. It's nice to be able to see the patterns, much more understandable than having to feel the motors and run the pots.
I could go on but I won't...
Ask me anything. If I know, I'll tell you. If I don't, I'll bullshit you real good