Hi!
I’m using Orangutan X2 Microcontroller for my sumo-robot project. For the last days I’ve been trying to set up a bump sensor. Using this sensor I would be able to know,
when my robot is hitten by other participant.
I have followed this scheme, to setup a proper sensor.
After soldering the sensor to the Digital socket on the microcontroller, I checked the sensor with a multimeter, and everything was as it should be -
when the switch is pressed the voltage goes down to 0.3V.
So I assume, that the sensor itself is doing fine. So my problem should be at the code.
Here’s a test code I wrote for the sensor, to check whether it’s working. The robot acts as the sensor would be driven low all the time. The worst thing is that it doesn’t react to the switch, whether it’s pressed or not, it doesn’t change a thing.
My question is, is there something wrong with the code? Did I miss some important lines within the code?
#include "SPI.h"
int main()
{
delay_ms(3000);
SPIInit();
while (1)
{
DDRC &= ~(1 << PORTC2); // make pin PC2 an input
PORTC |= (1 << PORTC2); // enable pull-up on pin PC2 (this means pin PC2
// will read as high unless externally driven low)
if (!(PINC & (1 << PORTC2))) // if pin PC2 input reads as high
{
setMotor1( 50 );
setMotor2( 50 );
}
else
{
setMotor1( 50 );
setMotor2( -50 );
}
}
return 0;
}