So I have my HydraBot built and the range sensor working the code I have does what I want it to but is throwing this error
#### Exception System.Exception - CLR_E_DIVIDE_BY_ZERO (1) ####
#### Message:
#### Gadgeteer.Modules.GHIElectronics.MotorControllerL298::MoveMotorRamp [IP: 0026] ####
#### HydraBotWithRangeF.Program+<>c__DisplayClass1::<ProgramStarted>b__0 [IP: 007d] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 004a] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001d] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 001c] ####
#### HydraBotWithRangeF.Program::Main [IP: 001a] ####
A first chance exception of type ‘System.Exception’ occurred in GTM.GHIElectronics.MotorControllerL298.dll
Exception performing Timer operation
The motors do stop and start when there is something in front of the sensor at the right distance and the motors start back up when there is nothing in the way.
namespace HydraBotWithRangeF
{
public partial class Program
{
GT.Socket.SocketInterfaces.AnalogInput ain5 = GT.Socket.GetSocket(14, true, null, null).AnalogInput5;
GT.Timer RangFinderTimer = new GT.Timer(100);
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, 0);
motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, 0);
double v;
double r;
int d = 11;
var timer = new GT.Timer(100);
timer.Tick += timer1 =>
{
v = ain5.ReadVoltage();
r = (v / 0.009766);
// Debug.Print((r.ToString()));
if (d < r)
{
Debug.Print("greater than 11");
motorControllerL298.MoveMotorRamp(MotorControllerL298.Motor.Motor1, 100, 5000);
motorControllerL298.MoveMotorRamp(MotorControllerL298.Motor.Motor2, 100, 5000);
}
else
{
Debug.Print("less than 11");
motorControllerL298.MoveMotorRamp(MotorControllerL298.Motor.Motor1, 0, 1000);
motorControllerL298.MoveMotorRamp(MotorControllerL298.Motor.Motor2, 0, 1000);
}
};
timer.Start();
{
}
}
}
}
do I have the
"if "
in the wrong place