Brainstorming and Initial Ideas

I wanted to use the idea behind my “Rocking and Rolling” demo to create a system that uses two lever switches to tilt a rocking body one way or another.

Here’s a diagram describing my initial thought process:

Although I planned on using two switches to control the movement of the body, I ended up using only one switch to tilt the body in one direction and coded in a “reset” to the body’s initial tilted position. This was due to the body moving too aggressively (the ball moved too quickly between the two switches).

Final Result

All in all, I’m content with the final product. In the future, I would definitely try to find a way to incorporate more than one sensor as it would make for a more interesting and complex project.

Code

#include <Servo.h&gt; 

const int SERVO_PIN = 9;
Servo svo;
int value;
const int SWITCH_PIN1  = 8;
const int SWITCH_PIN2  = 7;


void setup(void)
{
  svo.attach(SERVO_PIN);
  Serial.begin(115200);
}


void loop()
{
  svo.write(70);
  while(digitalRead(SWITCH_PIN1) == 0) ; // busywait for the switch to be pressed
    for (int idx = 0; idx < 50; idx = idx + 7) {
       Serial.println(idx);
       svo.write(90 + idx);
       delay(100);
    }
      
  Serial.println(-1);
  svo.write(70);

}

SolidWorks DXF File for Front Face of Body