I'm posting this to respond to a request for the code used to create the circuit in this video
Here you go, arduinoversusevil. I never really finished the code, or took the hardware further than the video.
Kind of like solving a Rubik's cube: once I figured out how to make it work, I got bored with it and shelved it.
/*
Stirplate - controls an array of four electromagnets to spin a teflon
encapsulated stirbar in a flask, such as used by homebrewers to culture yeast.
This is based on the basic "FADE" sketch. Two pairs of magnets create an x and y axis.
The pulling force of the magnet swings back and forth from the x to the y axis,
the H-Bridge is used to reverse the polarity of each axis when it is at 0 force.
This is written to run on an Atmel ATtiny84. I would suspect it would run equally well
on an ATtiny85, but I am not familiar with the process to designate the RESET pin
to work as an I/O, or the process to refuse should I want to reprogram the chip afterwards.
The information in this thread: http://arduino.cc/forum/index.php/topic,87517.0.html
may be useful for anyone who chooses to try this on at ATtiny85. If you do, please let
me know how it comes out. chuck.falls@gmail.com
Software:
You will need to gather and install all of the support files and libraries as detailed on this page: http://hlt.media.mit.edu/?p=1695
Hardware:
(4) electromagnets (Mine are model: ZYE1-P20/15)
(1) ATmel ATtiny84
(1) SN754410
(1) LM7805 (and filter capacitors of your choosing)
(1) Switched potentiometer, or a switch and a potentiomter.
(3) 10uf decoupling capacitors - VCC on the ATtiny84 (pin 1), VCC1 and VCC2 on the SN754410 (pins 8 & 16)
*/
int xaxis = 6; //connect to the pin 1 on the SN754410
int yaxis = 5; //connect to the pin 9 on the SN754410
int logicA1 = 8; //connect to the pin 7 on the SN754410
int logicA2 = 7; //connect to the pin 2 on the SN754410
int logicB1 = 3; //connect to the pin 10 on the SN754410
int logicB2 = 4; //connect to the pin 15 on the SN754410
int potPin = 0;
int force = 0;
int fadeAmount = 51; //3, 5, 15, 17, 51, & 85 should all be acceptable
int delaytime = 1000;
int state = 0;
//
void setup() {
pinMode(xaxis, OUTPUT);
pinMode(yaxis, OUTPUT);
pinMode(logicA1, OUTPUT);
pinMode(logicA2, OUTPUT);
pinMode(logicB1, OUTPUT);
pinMode(logicB2, OUTPUT);
pinMode(potPin, INPUT);
/*this section just turns the magnets on and holds a position for 5 seconds. This is necessary as there is no magnet upon which to
center the stirbar until after the "motor" is turned on and is already spinning.*/
digitalWrite(logicA1,HIGH);
digitalWrite(logicA2,LOW);
digitalWrite(logicB1,HIGH);
digitalWrite(logicB2,LOW);
digitalWrite(xaxis, HIGH);
digitalWrite(yaxis, HIGH);
delay(500);
}
void loop() {
analogWrite(xaxis, force);
analogWrite(yaxis, 255-force);
if (millis()<(20*1000)) delay((20000/millis())+14);
else delay(14);
// change the force for next time through the loop:
force = force + fadeAmount;
if (force == 0 || force == 255) // if the magnet is aligned withe the x-axis or y-axis
{
switchState(); //four states direct the polarity of the magnets
fadeAmount = -fadeAmount ; //swings the "on" magnet from the y-axis to the x-axis, and then back.
}
}
void switchState()
{
if (state==3) state=0;
else state+=1;
if (state==0)
{
digitalWrite(logicA1,HIGH);
digitalWrite(logicA2,LOW);
}
if (state==1)
{
digitalWrite(logicB1,LOW);
digitalWrite(logicB2,HIGH);
}
if (state==2)
{
digitalWrite(logicA1,LOW);
digitalWrite(logicA2,HIGH);
}
if (state==3)
{
digitalWrite(logicB1,HIGH);
digitalWrite(logicB2,LOW);
}
}