So the idea is that, the hedgehog will be weighed and if it falls within a weight limit it will receive some food, However, at the moment, I am using weights that are below the weight limit (so no food should be dispensed) but in fact, food is being dispensed.
I also am struggling to create different weight limits which will determine how much food will be dispensed.
if (scale.get_units()>sensorMin){
Serial.print("Weight: ");
Serial.print(scale.get_units(), 3);
Serial.println(" kg");
myStepper.setSpeed(30);
//set RPM at which stepper will rotate when called to step
Serial.println("stepperclockwise");
myStepper.step(400);
hedgehogData.println(scale.get_units(), 3);
hedgehogData.close();
Sleepy::loseSomeTime(10000); //instead of delay (10000)
I have tried using code as shown below but it does not make a difference
else if ((scale.get_units()>sensorMid)&&(scale.get_units()<sensorMax)){... }
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
You have defined sensorMin and two other varialbles as int but initialised them with floating point numbers. That won't work, they will get rounded down, and in this case to zero, as they are all less than 1. You should use float variables.
Are you sure? yes | no
Hi there, thank you for your advice - just wanted to check whether you meant just to change the variables sensorMin etc to 'float sensorMin =...' or isthere more that needs to be done?
Are you sure? yes | no
Yes, just that. int variables can only hold whole numbers, e.g. -10, 42, etc. Effectively you are assigning 0 to them so later the test always succeeds. Refer to a programming book if you need a refresher on types of variables and values they can hold.
Are you sure? yes | no