these are my codes in java using the following impoted libraries from maven please fix the errors in my code. the errors are Pin buttonPin = new FirmataPin("D4"); Pin moistureSensorPin = new Pin(2); Pin waterPumpPin = new Pin(7); this blovk of code is still red. github.kurbatov.firmata4j io.github.java.native.jssc slf4j.jcl
import org.firmata4j.IODevice;
import org.firmata4j.Pin;
import org.firmata4j.firmata.FirmataDevice;
import org.firmata4j.ssd1306.SSD1306;
import java.io.IOException;
import java.util.HashMap;
import java.util.TimerTask;
public class minorproj extends TimerTask {
static String recLog = "\"/dev/cu.usbserial-0001\"";
static IODevice myGroveBoard;
private final SSD1306 theOledObject;
private Pin MoistureSensor;
private Pin WaterPump;
private Pin Button;
private int sampleCount;
public minorproj(SSD1306 theOledObject, Pin Button, Pin MoistureSensor, Pin WaterPump) {
this.theOledObject = theOledObject;
this.Button = Button;
this.MoistureSensor = MoistureSensor;
this.WaterPump = WaterPump;
this.sampleCount = 0;
}
double startTime = System.currentTimeMillis();
@Override
public void run() {
while (true) {
{
// check if button is pressed
if (this.Button.getValue() == 1) {
break; // exit loop and stop program
}
String VolValue = String.valueOf(MoistureSensor.getValue());
System.out.println("Moisture Sensor Value:" + VolValue);
double Moisture = (double)( ((MoistureSensor).getValue() * 5)/ 1023);
HashMap<Double, Integer> Value = new HashMap<>();//used to store a mapping of keys to values.
//the keys are of the data type Double and the values are of the data type Integer.
double elapsedTime = (System.currentTimeMillis() - startTime) / 1000.0;
if (this.MoistureSensor.getValue() >= 710) {
try {
System.out.println("Soil is Dry.Water!!");
theOledObject.getCanvas().clear(); // clear contents first.
theOledObject.getCanvas().drawString(0, 0, "Soil is Dry.Water!!::" + String.format("%.2f", Moisture));
theOledObject.display();
WaterPump.setValue(1);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else if (this.MoistureSensor.getValue() <= 510) {
try {
System.out.println("Soil is WET.Do Not Water!!");
theOledObject.getCanvas().clear(); // clear contents first.
theOledObject.getCanvas().drawString(0, 0, "Soil is WET.Do Not Water!!::" + String.format("%.2f", Moisture));
theOledObject.display();
WaterPump.setValue(0);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else
try {
System.out.println("Soil is Moist.Needs More Water!!");
theOledObject.getCanvas().clear(); // clear contents first.
theOledObject.getCanvas().drawString(0, 0, "Soil is Moist.Needs More Water!!::" + String.format("%.2f", Moisture));
theOledObject.display();
WaterPump.setValue(1);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
-------
import org.firmata4j.IODevice;
import org.firmata4j.Pin;
import org.firmata4j.firmata.FirmataDevice;
import org.firmata4j.ssd1306.SSD1306;
import java.io.IOException;
import java.util.HashMap;
import java.util.TimerTask;
public class Main {
public static void main(String[] args) {
// Create an instance of SSD1306
SSD1306 theOledObject = new SSD1306();
// Create instances of Pin for Button, MoistureSensor, and WaterPump
Pin buttonPin = new Pin("D4");
Pin moistureSensorPin = new Pin("A2");
Pin waterPumpPin = new Pin("D7");
// Create an instance of the minorproj class
minorproj task = new minorproj(theOledObject, buttonPin, moistureSensorPin, waterPumpPin);
// Schedule the task to run
java.util.Timer timer = new java.util.Timer();
timer.schedule(task, 0, /* Specify interval in milliseconds */);
}
}
Pin moistureSensorPin = new Pin(2);
Pin waterPumpPin = new Pin(7);
Step by step
Solved in 3 steps