Baby O 2 pins used for cut off switch


I would like to use 2 pins hooked up to a cut off switch.

I would like to send a signal to pin1 (from within the baby O), this signal could be a pulse or voltage what ever method is simplest. When the switch is closed I would like to be able to detect this pulse or voltage
on pin 2 in order to determine when the switch closed.

So basically I would like to be able to programically sense when the switch is closed using 2 pins and a simple signal.

Is it possible to do this with the baby O.


Why do you want to use two IO pins? One would suffice.

Just connect the switch between an IO line and ground, then in your program enable the internal pullup using set_digital_input(IO_xx, PULL_UP_ENABLED) and read the value on the line using is_digital_input_high(IO_xx).

See the OrangutanDigital library documentation for more information:

The example program there named “digital1” shows you what your code should look like.



I am powering the babyO by a 7.4volt 1200mah battery.

I have PC0 pin wired to switch, then the switch to ground or (-).
I would like to run Motor #1 while the switch is open. As soon as the switch closes
I want to stop the motor.

This is my code

// servo movement
// 0 fast , 150 slow

set_digital_input(IO_C0, PULL_UP_ENABLED);

// open door
set_motors(-70, 0);			// run motor 1
while(is_digital_input_high(IO_C0) == 0)  while switch is open
// run motor while switch is open
// stop M1
set_motors(0, 0);

The motor never runs, which means either my code is off, or there may be a problem with my connections.

your advise?


I think that you should remove the “== 0” from your while loop condition, because the line should be high when the switch it open. Also you might consider adding a delay of a few microseconds after enabling the pull-up and before reading the value of the line the first time.

I also think that you should have been able to figure this out yourself. You should have started by asking and answering these questions:

  1. What is the value of is_digital_input_high(IO_C0) when the switch is open (zero or non-zero)?
  2. What is the value of is_digital_input_high(IO_C0) when the switch is closed (zero or non-zero)?
  3. Does set_motors(-70,0) work?

You can do little experiments to determine the answers to those questions.