So for my intro class I need to make an autonomous robot and when it bumps into something it backs up and turns around. Only problem is once the bump sensor is clicked it will always read high. I was wondering if there is a way to reset it with programming instead of having to hit the reset but every time just to get it to work. The link to the sensor is below, along with the code I had. I can get it to read one switch change but not another one after that
const byte switchPin = 10;
byte oldSwitchState = HIGH;
void setup ()
{
Serial.begin (9600);
pinMode (switchPin, INPUT);
} // end of setup
void loop ()
{
// see if switch is open or closed
byte switchState = digitalRead (switchPin);
// has it changed since last time?
if (switchState != oldSwitchState)
{
oldSwitchState = switchState; // remember for next time
if (switchState == LOW)
{
Serial.println ("Switch closed.");
} // end if switchState is LOW
else
{
Serial.println ("Switch opened.");
} // end if switchState is HIGH
} // end of state change
}
sketch_nov24b.ino (117 Bytes)