Justin Kufro
Partner: Oshada Gunasekara
These responsive cars are made to communicate through sensing the world through limit switches. One car moves only when its limit switch is open, while the other moves only when its limit switch is closed. They are intended to be placed in front of each other so that they seem to chase one another around.
One of the subgoals for this demo was having simplicity of design. Both cars use just two laser-cut pieces of 6mm plywood, a DC motor, and a limit switch. The tradeoff to this is that the cars tend to turn in the rightward direction instead of driving straight. Wires tethered to a computer and wall outlet just amplify the issue further.
Video
Files
Code
const int MOTOR_PIN_1 = 5; const int MOTOR_PIN_2 = 6; const int LIMIT_SWITCH_PIN = 13; void setup() { // put your setup code here, to run once: pinMode(MOTOR_PIN_1, OUTPUT); pinMode(MOTOR_PIN_2, OUTPUT); pinMode(LIMIT_SWITCH_PIN, INPUT); } // https://courses.ideate.cmu.edu/16-223/f2018/text/lib/WheelDrive.html void set_motor_pwm(int pwm, int MOTOR_PIN_1, int MOTOR_PIN_2) { if (pwm < 0) { // reverse speeds analogWrite(MOTOR_PIN_1, -pwm); digitalWrite(MOTOR_PIN_2, LOW); } else { // stop or forward digitalWrite(MOTOR_PIN_1, LOW); analogWrite(MOTOR_PIN_2, pwm); } } // https://courses.ideate.cmu.edu/16-223/f2018/text/lib/WheelDrive.html void set_motor_currents(int pwm_A, int pwm_B) { set_motor_pwm(pwm_A, MOTOR_PIN_1, MOTOR_PIN_2); set_motor_pwm(pwm_B, MOTOR_PIN_1, MOTOR_PIN_2); } // https://courses.ideate.cmu.edu/16-223/f2018/text/lib/WheelDrive.html void spin_and_wait(int pwm_A, int pwm_B, int duration) { set_motor_currents(pwm_A, pwm_B); delay(duration); } void loop() { int value = digitalRead(LIMIT_SWITCH_PIN); if (value == 0) { spin_and_wait(255,255,2000); } else { spin_and_wait(0,0,50); } }
Leave a Reply
You must be logged in to post a comment.